GearmanParserTest.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?php
  2. /**
  3. * Gearman Bundle for Symfony2
  4. *
  5. * @author Marc Morera <yuhu@mmoreram.com>
  6. * @since 2013
  7. */
  8. namespace Mmoreram\GearmanBundle\Tests\Service;
  9. /**
  10. * Tests JobClassTest class
  11. */
  12. class GearmanParserTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @var GearmanParser
  16. *
  17. * GearmanParser mock
  18. */
  19. private $gearmanParser;
  20. /**
  21. * @var Bundle
  22. *
  23. * Bundle mock
  24. */
  25. private $bundleMock;
  26. /**
  27. * @var array
  28. *
  29. * KernelBundles
  30. */
  31. private $kernelBundles;
  32. /**
  33. * @var string
  34. *
  35. * Bundle path
  36. */
  37. private $bundlePath = '/my/bundle/path';
  38. /**
  39. * Setup
  40. */
  41. public function setUp()
  42. {
  43. $this->gearmanParser = $this
  44. ->getMockBuilder('\Mmoreram\GearmanBundle\Service\GearmanParser')
  45. ->disableOriginalConstructor()
  46. ->setMethods(null)
  47. ->getMock();
  48. $this->bundleMock = $this
  49. ->getMockBuilder('\Symfony\Component\HttpKernel\Bundle\Bundle')
  50. ->disableOriginalConstructor()
  51. ->setMethods(array(
  52. 'getPath'
  53. ))
  54. ->getMock();
  55. }
  56. /**
  57. * testing getFileClassNamespace
  58. */
  59. public function testGetFileClassNamespaceSingle()
  60. {
  61. $mockNamespace = dirname(__FILE__) . '/Mocks/SingleCleanFile.php';
  62. $gearmanParser = $this
  63. ->getMockBuilder('\Mmoreram\GearmanBundle\Service\GearmanParser')
  64. ->disableOriginalConstructor()
  65. ->setMethods(null)
  66. ->getMock();
  67. $this->assertEquals('My\File\Namespace\SingleCleanFile', $gearmanParser->getFileClassNamespace($mockNamespace));
  68. }
  69. /**
  70. * testing getFileClassNamespace
  71. */
  72. public function testGetFileClassNamespaceCommented()
  73. {
  74. $mockNamespace = dirname(__FILE__) . '/Mocks/SingleCommentedFile.php';
  75. $gearmanParser = $this
  76. ->getMockBuilder('\Mmoreram\GearmanBundle\Service\GearmanParser')
  77. ->disableOriginalConstructor()
  78. ->setMethods(null)
  79. ->getMock();
  80. $this->assertEquals('My\File\Namespace\SingleCommentedFile', $gearmanParser->getFileClassNamespace($mockNamespace));
  81. }
  82. /**
  83. * Testing loadNamespaceMap without Include and Exclude values
  84. */
  85. public function testLoadNamespaceMapSimple()
  86. {
  87. $this->bundleMock
  88. ->expects($this->any())
  89. ->method('getPath')
  90. ->will($this->returnValue($this->bundlePath));
  91. $this->kernelBundles = array(
  92. "FirstBundleName" => $this->bundleMock,
  93. );
  94. list($paths, $excludedPaths) = $this->gearmanParser->loadNamespaceMap($this->kernelBundles, array(
  95. "FirstBundle" => array(
  96. "name" => "FirstBundleName",
  97. "active" => true,
  98. "include" => array(),
  99. "ignore" => array(),
  100. ),
  101. ));
  102. $this->assertEquals($paths, array($this->bundlePath . '/'));
  103. $this->assertEquals($excludedPaths, array());
  104. }
  105. /**
  106. * Testing loadNamespaceMap with just Include values
  107. */
  108. public function testLoadNamespaceMapIncludes()
  109. {
  110. $this->bundleMock
  111. ->expects($this->any())
  112. ->method('getPath')
  113. ->will($this->returnValue($this->bundlePath));
  114. $this->kernelBundles = array(
  115. "FirstBundleName" => $this->bundleMock,
  116. );
  117. list($paths, $excludedPaths) = $this->gearmanParser->loadNamespaceMap($this->kernelBundles, array(
  118. "FirstBundle" => array(
  119. "name" => "FirstBundleName",
  120. "active" => true,
  121. "include" => array(
  122. 'Services',
  123. 'Workers',
  124. ),
  125. "ignore" => array(),
  126. ),
  127. ));
  128. $this->assertEquals($paths, array(
  129. $this->bundlePath . '/Services/',
  130. $this->bundlePath . '/Workers/',
  131. ));
  132. $this->assertEquals($excludedPaths, array());
  133. }
  134. /**
  135. * Testing loadNamespaceMap with just exclude values
  136. */
  137. public function testLoadNamespaceMapExcludes()
  138. {
  139. $this->bundleMock
  140. ->expects($this->any())
  141. ->method('getPath')
  142. ->will($this->returnValue($this->bundlePath));
  143. $this->kernelBundles = array(
  144. "FirstBundleName" => $this->bundleMock,
  145. );
  146. list($paths, $excludedPaths) = $this->gearmanParser->loadNamespaceMap($this->kernelBundles, array(
  147. "FirstBundle" => array(
  148. "name" => "FirstBundleName",
  149. "active" => true,
  150. "include" => array(),
  151. "ignore" => array(
  152. 'Services',
  153. 'Workers',
  154. ),
  155. ),
  156. ));
  157. $this->assertEquals($paths, array($this->bundlePath . '/'));
  158. $this->assertEquals($excludedPaths, array(
  159. 'Services',
  160. 'Workers',
  161. ));
  162. }
  163. /**
  164. * Testing loadNamespaceMap with includes and exclude values
  165. */
  166. public function testLoadNamespaceMapBoth()
  167. {
  168. $this->bundleMock
  169. ->expects($this->any())
  170. ->method('getPath')
  171. ->will($this->returnValue($this->bundlePath));
  172. $this->kernelBundles = array(
  173. "FirstBundleName" => $this->bundleMock,
  174. );
  175. list($paths, $excludedPaths) = $this->gearmanParser->loadNamespaceMap($this->kernelBundles, array(
  176. "FirstBundle" => array(
  177. "name" => "FirstBundleName",
  178. "active" => true,
  179. "include" => array(
  180. 'Controllers',
  181. 'libs'
  182. ),
  183. "ignore" => array(
  184. 'Services',
  185. 'Workers',
  186. 'libs',
  187. ),
  188. ),
  189. ));
  190. $this->assertEquals($paths, array(
  191. $this->bundlePath . '/Controllers/',
  192. $this->bundlePath . '/libs/',
  193. ));
  194. $this->assertEquals($excludedPaths, array(
  195. 'Services',
  196. 'Workers',
  197. 'libs',
  198. ));
  199. }
  200. }