These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Doctrine\Tests\ORM\Functional\Ticket; |
||
4 | |||
5 | use Doctrine\DBAL\Schema\SchemaException; |
||
6 | use Doctrine\ORM\Mapping\Column; |
||
7 | use Doctrine\ORM\Mapping\Embeddable; |
||
8 | use Doctrine\ORM\Mapping\Entity; |
||
0 ignored issues
–
show
|
|||
9 | use Doctrine\ORM\Mapping\Id; |
||
10 | use Doctrine\ORM\Mapping\GeneratedValue; |
||
11 | use Doctrine\ORM\Mapping\ManyToOne; |
||
12 | use Doctrine\ORM\Proxy\Proxy; |
||
13 | |||
14 | class DDC6460Test extends \Doctrine\Tests\OrmFunctionalTestCase |
||
15 | { |
||
16 | public function setUp() |
||
17 | { |
||
18 | parent::setUp(); |
||
19 | |||
20 | try { |
||
21 | $this->setUpEntitySchema( |
||
22 | [ |
||
23 | DDC6460Entity::class, |
||
24 | DDC6460ParentEntity::class, |
||
25 | ] |
||
26 | ); |
||
27 | } catch (SchemaException $e) { |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||
28 | } |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @group DDC-6460 |
||
33 | */ |
||
34 | public function testInlineEmbeddable() |
||
35 | { |
||
36 | $isFieldMapped = $this->_em |
||
37 | ->getClassMetadata(DDC6460Entity::class) |
||
38 | ->hasField('embedded'); |
||
39 | |||
40 | $this->assertTrue($isFieldMapped); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @group DDC-6460 |
||
45 | */ |
||
46 | public function testInlineEmbeddableProxyInitialization() |
||
47 | { |
||
48 | $entity = new DDC6460Entity(); |
||
49 | $entity->id = 1; |
||
50 | $entity->embedded = new DDC6460Embeddable(); |
||
51 | $entity->embedded->field = 'test'; |
||
52 | $this->_em->persist($entity); |
||
53 | |||
54 | $second = new DDC6460ParentEntity(); |
||
55 | $second->id = 1; |
||
56 | $second->lazyLoaded = $entity; |
||
57 | $this->_em->persist($second); |
||
58 | $this->_em->flush(); |
||
59 | |||
60 | $this->_em->clear(); |
||
61 | |||
62 | $secondEntityWithLazyParameter = $this->_em->getRepository(DDC6460ParentEntity::class)->findOneById(1); |
||
0 ignored issues
–
show
The method
findOneById does not exist on object<Doctrine\ORM\EntityRepository> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
63 | |||
64 | $this->assertInstanceOf(Proxy::class, $secondEntityWithLazyParameter->lazyLoaded); |
||
65 | $this->assertInstanceOf(DDC6460Entity::class, $secondEntityWithLazyParameter->lazyLoaded); |
||
66 | $this->assertFalse($secondEntityWithLazyParameter->lazyLoaded->__isInitialized()); |
||
67 | $this->assertEquals($secondEntityWithLazyParameter->lazyLoaded->embedded, $entity->embedded); |
||
68 | $this->assertTrue($secondEntityWithLazyParameter->lazyLoaded->__isInitialized()); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @Embeddable() |
||
74 | */ |
||
75 | class DDC6460Embeddable |
||
76 | { |
||
77 | /** @Column(type="string") */ |
||
78 | public $field; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @Entity() |
||
83 | */ |
||
84 | class DDC6460Entity |
||
85 | { |
||
86 | /** |
||
87 | * @Id |
||
88 | * @GeneratedValue(strategy = "NONE") |
||
89 | * @Column(type = "integer") |
||
90 | */ |
||
91 | public $id; |
||
92 | |||
93 | /** @Embedded(class = "DDC6460Embeddable") */ |
||
94 | public $embedded; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @Entity() |
||
99 | */ |
||
100 | class DDC6460ParentEntity |
||
101 | { |
||
102 | /** |
||
103 | * @Id |
||
104 | * @GeneratedValue(strategy = "NONE") |
||
105 | * @Column(type = "integer") |
||
106 | */ |
||
107 | public $id; |
||
108 | |||
109 | /** @ManyToOne(targetEntity = "DDC6460Entity", fetch="EXTRA_LAZY", cascade={"persist"}) */ |
||
110 | public $lazyLoaded; |
||
111 | } |
||
112 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: