PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/doctrine_m/vendor/doctrine2/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php

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