PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php

https://bitbucket.org/Evgenii/zf2t
PHP | 590 lines | 530 code | 46 blank | 14 comment | 9 complexity | 4c2ec019c613704e8551b9979b81b236 MD5 | raw file
  1. <?php
  2. namespace Doctrine\Tests\ORM\Tools;
  3. use Doctrine\ORM\Tools\SchemaTool,
  4. Doctrine\ORM\Tools\EntityGenerator,
  5. Doctrine\ORM\Tools\Export\ClassMetadataExporter,
  6. Doctrine\ORM\Mapping\ClassMetadataInfo;
  7. require_once __DIR__ . '/../../TestInit.php';
  8. class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
  9. {
  10. /**
  11. * @var EntityGenerator
  12. */
  13. private $_generator;
  14. private $_tmpDir;
  15. private $_namespace;
  16. public function setUp()
  17. {
  18. $this->_namespace = uniqid("doctrine_");
  19. $this->_tmpDir = \sys_get_temp_dir();
  20. \mkdir($this->_tmpDir . \DIRECTORY_SEPARATOR . $this->_namespace);
  21. $this->_generator = new EntityGenerator();
  22. $this->_generator->setAnnotationPrefix("");
  23. $this->_generator->setGenerateAnnotations(true);
  24. $this->_generator->setGenerateStubMethods(true);
  25. $this->_generator->setRegenerateEntityIfExists(false);
  26. $this->_generator->setUpdateEntityIfExists(true);
  27. $this->_generator->setFieldVisibility(EntityGenerator::FIELD_VISIBLE_PROTECTED);
  28. }
  29. public function tearDown()
  30. {
  31. $ri = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->_tmpDir . '/' . $this->_namespace));
  32. foreach ($ri AS $file) {
  33. /* @var $file \SplFileInfo */
  34. if ($file->isFile()) {
  35. \unlink($file->getPathname());
  36. }
  37. }
  38. rmdir($this->_tmpDir . '/' . $this->_namespace);
  39. }
  40. public function generateBookEntityFixture()
  41. {
  42. $metadata = new ClassMetadataInfo($this->_namespace . '\EntityGeneratorBook');
  43. $metadata->namespace = $this->_namespace;
  44. $metadata->customRepositoryClassName = $this->_namespace . '\EntityGeneratorBookRepository';
  45. $metadata->table['name'] = 'book';
  46. $metadata->table['uniqueConstraints']['name_uniq'] = array('columns' => array('name'));
  47. $metadata->table['indexes']['status_idx'] = array('columns' => array('status'));
  48. $metadata->mapField(array('fieldName' => 'name', 'type' => 'string'));
  49. $metadata->mapField(array('fieldName' => 'status', 'type' => 'string', 'default' => 'published'));
  50. $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
  51. $metadata->mapOneToOne(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor', 'mappedBy' => 'book'));
  52. $joinColumns = array(
  53. array('name' => 'author_id', 'referencedColumnName' => 'id')
  54. );
  55. $metadata->mapManyToMany(array(
  56. 'fieldName' => 'comments',
  57. 'targetEntity' => 'Doctrine\Tests\ORM\Tools\EntityGeneratorComment',
  58. 'fetch' => ClassMetadataInfo::FETCH_EXTRA_LAZY,
  59. 'joinTable' => array(
  60. 'name' => 'book_comment',
  61. 'joinColumns' => array(array('name' => 'book_id', 'referencedColumnName' => 'id')),
  62. 'inverseJoinColumns' => array(array('name' => 'comment_id', 'referencedColumnName' => 'id')),
  63. ),
  64. ));
  65. $metadata->addLifecycleCallback('loading', 'postLoad');
  66. $metadata->addLifecycleCallback('willBeRemoved', 'preRemove');
  67. $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
  68. $this->_generator->writeEntityClass($metadata, $this->_tmpDir);
  69. return $metadata;
  70. }
  71. private function generateEntityTypeFixture(array $field)
  72. {
  73. $metadata = new ClassMetadataInfo($this->_namespace . '\EntityType');
  74. $metadata->namespace = $this->_namespace;
  75. $metadata->table['name'] = 'entity_type';
  76. $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
  77. $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
  78. $name = $field['fieldName'];
  79. $type = $field['dbType'];
  80. $metadata->mapField(array('fieldName' => $name, 'type' => $type));
  81. $this->_generator->writeEntityClass($metadata, $this->_tmpDir);
  82. return $metadata;
  83. }
  84. /**
  85. * @param ClassMetadataInfo $metadata
  86. * @return EntityGeneratorBook
  87. */
  88. public function newInstance($metadata)
  89. {
  90. $path = $this->_tmpDir . '/'. $this->_namespace . '/EntityGeneratorBook.php';
  91. $this->assertFileExists($path);
  92. require_once $path;
  93. return new $metadata->name;
  94. }
  95. public function testGeneratedEntityClass()
  96. {
  97. $metadata = $this->generateBookEntityFixture();
  98. $book = $this->newInstance($metadata);
  99. $this->assertTrue(class_exists($metadata->name), "Class does not exist.");
  100. $this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', '__construct'), "EntityGeneratorBook::__construct() missing.");
  101. $this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'getId'), "EntityGeneratorBook::getId() missing.");
  102. $this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'setName'), "EntityGeneratorBook::setName() missing.");
  103. $this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'getName'), "EntityGeneratorBook::getName() missing.");
  104. $this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'setAuthor'), "EntityGeneratorBook::setAuthor() missing.");
  105. $this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'getAuthor'), "EntityGeneratorBook::getAuthor() missing.");
  106. $this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'getComments'), "EntityGeneratorBook::getComments() missing.");
  107. $this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'addComment'), "EntityGeneratorBook::addComment() missing.");
  108. $this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'removeComment'), "EntityGeneratorBook::removeComment() missing.");
  109. $this->assertEquals('published', $book->getStatus());
  110. $book->setName('Jonathan H. Wage');
  111. $this->assertEquals('Jonathan H. Wage', $book->getName());
  112. $author = new EntityGeneratorAuthor();
  113. $book->setAuthor($author);
  114. $this->assertEquals($author, $book->getAuthor());
  115. $comment = new EntityGeneratorComment();
  116. $book->addComment($comment);
  117. $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $book->getComments());
  118. $this->assertEquals(new \Doctrine\Common\Collections\ArrayCollection(array($comment)), $book->getComments());
  119. $book->removeComment($comment);
  120. $this->assertEquals(new \Doctrine\Common\Collections\ArrayCollection(array()), $book->getComments());
  121. }
  122. public function testEntityUpdatingWorks()
  123. {
  124. $metadata = $this->generateBookEntityFixture();
  125. $metadata->mapField(array('fieldName' => 'test', 'type' => 'string'));
  126. $this->_generator->writeEntityClass($metadata, $this->_tmpDir);
  127. $this->assertFileExists($this->_tmpDir . "/" . $this->_namespace . "/EntityGeneratorBook.php~");
  128. $book = $this->newInstance($metadata);
  129. $reflClass = new \ReflectionClass($metadata->name);
  130. $this->assertTrue($reflClass->hasProperty('name'), "Regenerating keeps property 'name'.");
  131. $this->assertTrue($reflClass->hasProperty('status'), "Regenerating keeps property 'status'.");
  132. $this->assertTrue($reflClass->hasProperty('id'), "Regenerating keeps property 'id'.");
  133. $this->assertTrue($reflClass->hasProperty('test'), "Check for property test failed.");
  134. $this->assertTrue($reflClass->getProperty('test')->isProtected(), "Check for protected property test failed.");
  135. $this->assertTrue($reflClass->hasMethod('getTest'), "Check for method 'getTest' failed.");
  136. $this->assertTrue($reflClass->getMethod('getTest')->isPublic(), "Check for public visibility of method 'getTest' failed.");
  137. $this->assertTrue($reflClass->hasMethod('setTest'), "Check for method 'getTest' failed.");
  138. $this->assertTrue($reflClass->getMethod('getTest')->isPublic(), "Check for public visibility of method 'getTest' failed.");
  139. }
  140. /**
  141. * @group DDC-2121
  142. */
  143. public function testMethodDocBlockShouldStartWithBackSlash()
  144. {
  145. $metadata = $this->generateBookEntityFixture();
  146. $book = $this->newInstance($metadata);
  147. $this->assertPhpDocVarType('\Doctrine\Common\Collections\Collection', new \ReflectionProperty($book, 'comments'));
  148. $this->assertPhpDocReturnType('\Doctrine\Common\Collections\Collection', new \ReflectionMethod($book, 'getComments'));
  149. $this->assertPhpDocParamType('\Doctrine\Tests\ORM\Tools\EntityGeneratorComment', new \ReflectionMethod($book, 'addComment'));
  150. $this->assertPhpDocParamType('\Doctrine\Tests\ORM\Tools\EntityGeneratorComment', new \ReflectionMethod($book, 'removeComment'));
  151. $this->assertPhpDocVarType('\Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor', new \ReflectionProperty($book, 'author'));
  152. $this->assertPhpDocReturnType('\Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor', new \ReflectionMethod($book, 'getAuthor'));
  153. $this->assertPhpDocParamType('\Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor', new \ReflectionMethod($book, 'setAuthor'));
  154. }
  155. public function testEntityExtendsStdClass()
  156. {
  157. $this->_generator->setClassToExtend('stdClass');
  158. $metadata = $this->generateBookEntityFixture();
  159. $book = $this->newInstance($metadata);
  160. $this->assertInstanceOf('stdClass', $book);
  161. }
  162. public function testLifecycleCallbacks()
  163. {
  164. $metadata = $this->generateBookEntityFixture();
  165. $book = $this->newInstance($metadata);
  166. $reflClass = new \ReflectionClass($metadata->name);
  167. $this->assertTrue($reflClass->hasMethod('loading'), "Check for postLoad lifecycle callback.");
  168. $this->assertTrue($reflClass->hasMethod('willBeRemoved'), "Check for preRemove lifecycle callback.");
  169. }
  170. public function testLoadMetadata()
  171. {
  172. $metadata = $this->generateBookEntityFixture();
  173. $book = $this->newInstance($metadata);
  174. $cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name);
  175. $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
  176. $driver = $this->createAnnotationDriver();
  177. $driver->loadMetadataForClass($cm->name, $cm);
  178. $this->assertEquals($cm->columnNames, $metadata->columnNames);
  179. $this->assertEquals($cm->getTableName(), $metadata->getTableName());
  180. $this->assertEquals($cm->lifecycleCallbacks, $metadata->lifecycleCallbacks);
  181. $this->assertEquals($cm->identifier, $metadata->identifier);
  182. $this->assertEquals($cm->idGenerator, $metadata->idGenerator);
  183. $this->assertEquals($cm->customRepositoryClassName, $metadata->customRepositoryClassName);
  184. $this->assertEquals(ClassMetadataInfo::FETCH_EXTRA_LAZY, $cm->associationMappings['comments']['fetch']);
  185. }
  186. public function testLoadPrefixedMetadata()
  187. {
  188. $this->_generator->setAnnotationPrefix('ORM\\');
  189. $metadata = $this->generateBookEntityFixture();
  190. $reader = new \Doctrine\Common\Annotations\AnnotationReader();
  191. $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, array());
  192. $book = $this->newInstance($metadata);
  193. $cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name);
  194. $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
  195. $driver->loadMetadataForClass($cm->name, $cm);
  196. $this->assertEquals($cm->columnNames, $metadata->columnNames);
  197. $this->assertEquals($cm->getTableName(), $metadata->getTableName());
  198. $this->assertEquals($cm->lifecycleCallbacks, $metadata->lifecycleCallbacks);
  199. $this->assertEquals($cm->identifier, $metadata->identifier);
  200. $this->assertEquals($cm->idGenerator, $metadata->idGenerator);
  201. $this->assertEquals($cm->customRepositoryClassName, $metadata->customRepositoryClassName);
  202. }
  203. /**
  204. * @dataProvider getParseTokensInEntityFileData
  205. */
  206. public function testParseTokensInEntityFile($php, $classes)
  207. {
  208. $r = new \ReflectionObject($this->_generator);
  209. $m = $r->getMethod('parseTokensInEntityFile');
  210. $m->setAccessible(true);
  211. $p = $r->getProperty('staticReflection');
  212. $p->setAccessible(true);
  213. $ret = $m->invoke($this->_generator, $php);
  214. $this->assertEquals($classes, array_keys($p->getValue($this->_generator)));
  215. }
  216. /**
  217. * @group DDC-1784
  218. */
  219. public function testGenerateEntityWithSequenceGenerator()
  220. {
  221. $metadata = new ClassMetadataInfo($this->_namespace . '\DDC1784Entity');
  222. $metadata->namespace = $this->_namespace;
  223. $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
  224. $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE);
  225. $metadata->setSequenceGeneratorDefinition(array(
  226. 'sequenceName' => 'DDC1784_ID_SEQ',
  227. 'allocationSize' => 1,
  228. 'initialValue' => 2
  229. ));
  230. $this->_generator->writeEntityClass($metadata, $this->_tmpDir);
  231. $filename = $this->_tmpDir . DIRECTORY_SEPARATOR
  232. . $this->_namespace . DIRECTORY_SEPARATOR . 'DDC1784Entity.php';
  233. $this->assertFileExists($filename);
  234. require_once $filename;
  235. $reflection = new \ReflectionProperty($metadata->name, 'id');
  236. $docComment = $reflection->getDocComment();
  237. $this->assertContains('@Id', $docComment);
  238. $this->assertContains('@Column(name="id", type="integer")', $docComment);
  239. $this->assertContains('@GeneratedValue(strategy="SEQUENCE")', $docComment);
  240. $this->assertContains('@SequenceGenerator(sequenceName="DDC1784_ID_SEQ", allocationSize=1, initialValue=2)', $docComment);
  241. }
  242. /**
  243. * @group DDC-2079
  244. */
  245. public function testGenerateEntityWithMultipleInverseJoinColumns()
  246. {
  247. $metadata = new ClassMetadataInfo($this->_namespace . '\DDC2079Entity');
  248. $metadata->namespace = $this->_namespace;
  249. $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
  250. $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE);
  251. $metadata->mapManyToMany(array(
  252. 'fieldName' => 'centroCustos',
  253. 'targetEntity' => 'DDC2079CentroCusto',
  254. 'joinTable' => array(
  255. 'name' => 'unidade_centro_custo',
  256. 'joinColumns' => array(
  257. array('name' => 'idorcamento', 'referencedColumnName' => 'idorcamento'),
  258. array('name' => 'idunidade', 'referencedColumnName' => 'idunidade')
  259. ),
  260. 'inverseJoinColumns' => array(
  261. array('name' => 'idcentrocusto', 'referencedColumnName' => 'idcentrocusto'),
  262. array('name' => 'idpais', 'referencedColumnName' => 'idpais'),
  263. ),
  264. ),
  265. ));
  266. $this->_generator->writeEntityClass($metadata, $this->_tmpDir);
  267. $filename = $this->_tmpDir . DIRECTORY_SEPARATOR
  268. . $this->_namespace . DIRECTORY_SEPARATOR . 'DDC2079Entity.php';
  269. $this->assertFileExists($filename);
  270. require_once $filename;
  271. $property = new \ReflectionProperty($metadata->name, 'centroCustos');
  272. $docComment = $property->getDocComment();
  273. //joinColumns
  274. $this->assertContains('@JoinColumn(name="idorcamento", referencedColumnName="idorcamento"),', $docComment);
  275. $this->assertContains('@JoinColumn(name="idunidade", referencedColumnName="idunidade")', $docComment);
  276. //inverseJoinColumns
  277. $this->assertContains('@JoinColumn(name="idcentrocusto", referencedColumnName="idcentrocusto"),', $docComment);
  278. $this->assertContains('@JoinColumn(name="idpais", referencedColumnName="idpais")', $docComment);
  279. }
  280. /**
  281. * @group DDC-2172
  282. */
  283. public function testGetInheritanceTypeString()
  284. {
  285. $reflection = new \ReflectionClass('\Doctrine\ORM\Mapping\ClassMetadata');
  286. $method = new \ReflectionMethod($this->_generator, 'getInheritanceTypeString');
  287. $constants = $reflection->getConstants();
  288. $pattern = '/^INHERITANCE_TYPE_/';
  289. $method->setAccessible(true);
  290. foreach ($constants as $name => $value) {
  291. if( ! preg_match($pattern, $name)) {
  292. continue;
  293. }
  294. $expected = preg_replace($pattern, '', $name);
  295. $actual = $method->invoke($this->_generator, $value);
  296. $this->assertEquals($expected, $actual);
  297. }
  298. $this->setExpectedException('\InvalidArgumentException', 'Invalid provided InheritanceType: INVALID');
  299. $method->invoke($this->_generator, 'INVALID');
  300. }
  301. /**
  302. * @group DDC-2172
  303. */
  304. public function testGetChangeTrackingPolicyString()
  305. {
  306. $reflection = new \ReflectionClass('\Doctrine\ORM\Mapping\ClassMetadata');
  307. $method = new \ReflectionMethod($this->_generator, 'getChangeTrackingPolicyString');
  308. $constants = $reflection->getConstants();
  309. $pattern = '/^CHANGETRACKING_/';
  310. $method->setAccessible(true);
  311. foreach ($constants as $name => $value) {
  312. if( ! preg_match($pattern, $name)) {
  313. continue;
  314. }
  315. $expected = preg_replace($pattern, '', $name);
  316. $actual = $method->invoke($this->_generator, $value);
  317. $this->assertEquals($expected, $actual);
  318. }
  319. $this->setExpectedException('\InvalidArgumentException', 'Invalid provided ChangeTrackingPolicy: INVALID');
  320. $method->invoke($this->_generator, 'INVALID');
  321. }
  322. /**
  323. * @group DDC-2172
  324. */
  325. public function testGetIdGeneratorTypeString()
  326. {
  327. $reflection = new \ReflectionClass('\Doctrine\ORM\Mapping\ClassMetadata');
  328. $method = new \ReflectionMethod($this->_generator, 'getIdGeneratorTypeString');
  329. $constants = $reflection->getConstants();
  330. $pattern = '/^GENERATOR_TYPE_/';
  331. $method->setAccessible(true);
  332. foreach ($constants as $name => $value) {
  333. if( ! preg_match($pattern, $name)) {
  334. continue;
  335. }
  336. $expected = preg_replace($pattern, '', $name);
  337. $actual = $method->invoke($this->_generator, $value);
  338. $this->assertEquals($expected, $actual);
  339. }
  340. $this->setExpectedException('\InvalidArgumentException', 'Invalid provided IdGeneratorType: INVALID');
  341. $method->invoke($this->_generator, 'INVALID');
  342. }
  343. /**
  344. * @dataProvider getEntityTypeAliasDataProvider
  345. *
  346. * @group DDC-1694
  347. */
  348. public function testEntityTypeAlias(array $field)
  349. {
  350. $metadata = $this->generateEntityTypeFixture($field);
  351. $path = $this->_tmpDir . '/'. $this->_namespace . '/EntityType.php';
  352. $this->assertFileExists($path);
  353. require_once $path;
  354. $entity = new $metadata->name;
  355. $reflClass = new \ReflectionClass($metadata->name);
  356. $type = $field['phpType'];
  357. $name = $field['fieldName'];
  358. $value = $field['value'];
  359. $getter = "get" . ucfirst($name);
  360. $setter = "set" . ucfirst($name);
  361. $this->assertPhpDocVarType($type, $reflClass->getProperty($name));
  362. $this->assertPhpDocParamType($type, $reflClass->getMethod($setter));
  363. $this->assertPhpDocReturnType($type, $reflClass->getMethod($getter));
  364. $this->assertSame($entity, $entity->{$setter}($value));
  365. $this->assertEquals($value, $entity->{$getter}());
  366. }
  367. /**
  368. * @return array
  369. */
  370. public function getEntityTypeAliasDataProvider()
  371. {
  372. return array(
  373. array(array(
  374. 'fieldName' => 'datetimetz',
  375. 'phpType' => '\\DateTime',
  376. 'dbType' => 'datetimetz',
  377. 'value' => new \DateTime
  378. )),
  379. array(array(
  380. 'fieldName' => 'datetime',
  381. 'phpType' => '\\DateTime',
  382. 'dbType' => 'datetime',
  383. 'value' => new \DateTime
  384. )),
  385. array(array(
  386. 'fieldName' => 'date',
  387. 'phpType' => '\\DateTime',
  388. 'dbType' => 'date',
  389. 'value' => new \DateTime
  390. )),
  391. array(array(
  392. 'fieldName' => 'time',
  393. 'phpType' => '\DateTime',
  394. 'dbType' => 'time',
  395. 'value' => new \DateTime
  396. )),
  397. array(array(
  398. 'fieldName' => 'object',
  399. 'phpType' => '\stdClass',
  400. 'dbType' => 'object',
  401. 'value' => new \stdClass()
  402. )),
  403. array(array(
  404. 'fieldName' => 'bigint',
  405. 'phpType' => 'integer',
  406. 'dbType' => 'bigint',
  407. 'value' => 11
  408. )),
  409. array(array(
  410. 'fieldName' => 'smallint',
  411. 'phpType' => 'integer',
  412. 'dbType' => 'smallint',
  413. 'value' => 22
  414. )),
  415. array(array(
  416. 'fieldName' => 'text',
  417. 'phpType' => 'string',
  418. 'dbType' => 'text',
  419. 'value' => 'text'
  420. )),
  421. array(array(
  422. 'fieldName' => 'blob',
  423. 'phpType' => 'string',
  424. 'dbType' => 'blob',
  425. 'value' => 'blob'
  426. )),
  427. array(array(
  428. 'fieldName' => 'decimal',
  429. 'phpType' => 'float',
  430. 'dbType' => 'decimal',
  431. 'value' => 33.33
  432. ),
  433. ));
  434. }
  435. public function getParseTokensInEntityFileData()
  436. {
  437. return array(
  438. array(
  439. '<?php namespace Foo\Bar; class Baz {}',
  440. array('Foo\Bar\Baz'),
  441. ),
  442. array(
  443. '<?php namespace Foo\Bar; use Foo; class Baz {}',
  444. array('Foo\Bar\Baz'),
  445. ),
  446. array(
  447. '<?php namespace /*Comment*/ Foo\Bar; /** Foo */class /* Comment */ Baz {}',
  448. array('Foo\Bar\Baz'),
  449. ),
  450. array(
  451. '
  452. <?php namespace
  453. /*Comment*/
  454. Foo\Bar
  455. ;
  456. /** Foo */
  457. class
  458. /* Comment */
  459. Baz {}
  460. ',
  461. array('Foo\Bar\Baz'),
  462. ),
  463. );
  464. }
  465. /**
  466. * @param string $type
  467. * @param \ReflectionProperty $property
  468. */
  469. private function assertPhpDocVarType($type, \ReflectionProperty $property)
  470. {
  471. $this->assertEquals(1, preg_match('/@var\s+([^\s]+)/',$property->getDocComment(), $matches));
  472. $this->assertEquals($type, $matches[1]);
  473. }
  474. /**
  475. * @param string $type
  476. * @param \ReflectionProperty $method
  477. */
  478. private function assertPhpDocReturnType($type, \ReflectionMethod $method)
  479. {
  480. $this->assertEquals(1, preg_match('/@return\s+([^\s]+)/', $method->getDocComment(), $matches));
  481. $this->assertEquals($type, $matches[1]);
  482. }
  483. /**
  484. * @param string $type
  485. * @param \ReflectionProperty $method
  486. */
  487. private function assertPhpDocParamType($type, \ReflectionMethod $method)
  488. {
  489. $this->assertEquals(1, preg_match('/@param\s+([^\s]+)/', $method->getDocComment(), $matches));
  490. $this->assertEquals($type, $matches[1]);
  491. }
  492. }
  493. class EntityGeneratorAuthor {}
  494. class EntityGeneratorComment {}