ConstructorTest.php 561 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace Doctrine\Tests\ORM\Entity;
  3. require_once __DIR__ . '/../../TestInit.php';
  4. class ConstructorTest extends \Doctrine\Tests\OrmTestCase
  5. {
  6. public function testFieldInitializationInConstructor()
  7. {
  8. $entity = new ConstructorTestEntity1("romanb");
  9. $this->assertEquals("romanb", $entity->username);
  10. }
  11. }
  12. class ConstructorTestEntity1
  13. {
  14. private $id;
  15. public $username;
  16. public function __construct($username = null)
  17. {
  18. if ($username !== null) {
  19. $this->username = $username;
  20. }
  21. }
  22. }