| Conditions | 1 |
| Paths | 1 |
| Total Lines | 27 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | public function testExtraLazyRemoveElement() |
||
| 18 | { |
||
| 19 | $user = new User(); |
||
| 20 | $user->name = "test"; |
||
| 21 | |||
| 22 | $tweet1 = new Tweet(); |
||
| 23 | $tweet1->content = "Hello World!"; |
||
| 24 | $user->addTweet($tweet1); |
||
| 25 | |||
| 26 | $tweet2 = new Tweet(); |
||
| 27 | $tweet2->content = "Goodbye, and thanks for all the fish"; |
||
| 28 | $user->addTweet($tweet2); |
||
| 29 | |||
| 30 | $this->_em->persist($user); |
||
| 31 | $this->_em->persist($tweet1); |
||
| 32 | $this->_em->persist($tweet2); |
||
| 33 | $this->_em->flush(); |
||
| 34 | $this->_em->clear(); |
||
| 35 | |||
| 36 | $user = $this->_em->find(User::class, $user->id); |
||
| 37 | $tweet = $this->_em->find(Tweet::class, $tweet1->id); |
||
| 38 | |||
| 39 | $user->tweets->removeElement($tweet); |
||
| 40 | |||
| 41 | $tweets = $user->tweets->map(function (Tweet $tweet) { return $tweet->content; }); |
||
| 42 | |||
| 43 | $this->assertEquals(['Goodbye, and thanks for all the fish'], array_values($tweets->toArray())); |
||
| 44 | } |
||
| 46 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: