addiks /
symfony_rdm
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Copyright (C) 2017 Gerrit Addiks. |
||
| 4 | * This package (including this file) was released under the terms of the GPL-3.0. |
||
| 5 | * You should have received a copy of the GNU General Public License along with this program. |
||
| 6 | * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
||
| 7 | * @license GPL-3.0 |
||
| 8 | * @author Gerrit Addiks <[email protected]> |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace Addiks\RDMBundle\Tests\Hydration; |
||
| 12 | |||
| 13 | use PHPUnit\Framework\TestCase; |
||
| 14 | use Addiks\RDMBundle\Hydration\HydrationContext; |
||
| 15 | use Addiks\RDMBundle\Tests\Hydration\EntityExample; |
||
| 16 | use Doctrine\ORM\EntityManagerInterface; |
||
| 17 | use Addiks\RDMBundle\Exception\InvalidMappingException; |
||
| 18 | use Addiks\RDMBundle\Tests\ValueObjectExample; |
||
| 19 | use InvalidArgumentException; |
||
| 20 | |||
| 21 | final class HydrationContextTest extends TestCase |
||
| 22 | { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var HydrationContext |
||
| 26 | */ |
||
| 27 | private $context; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var EntityExample |
||
| 31 | */ |
||
| 32 | private $entity; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var EntityManagerInterface |
||
| 36 | */ |
||
| 37 | private $entityManager; |
||
| 38 | |||
| 39 | public function setUp(): void |
||
| 40 | { |
||
| 41 | $this->entity = $this->createMock(EntityExample::class); |
||
|
0 ignored issues
–
show
|
|||
| 42 | $this->entityManager = $this->createMock(EntityManagerInterface::class); |
||
|
0 ignored issues
–
show
It seems like
$this->createMock(Doctri...anagerInterface::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Doctrine\ORM\EntityManagerInterface of property $entityManager.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 43 | |||
| 44 | $this->context = new HydrationContext( |
||
| 45 | $this->entity, |
||
| 46 | $this->entityManager |
||
| 47 | ); |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @test |
||
| 52 | */ |
||
| 53 | public function shouldStoreEntity() |
||
| 54 | { |
||
| 55 | $this->assertSame($this->entity, $this->context->getEntity()); |
||
| 56 | $this->assertTrue(is_subclass_of($this->context->getEntityClass(), EntityExample::class)); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @test |
||
| 61 | */ |
||
| 62 | public function shouldStoreEntityManager() |
||
| 63 | { |
||
| 64 | $this->assertSame($this->entityManager, $this->context->getEntityManager()); |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @test |
||
| 69 | */ |
||
| 70 | public function shouldHaveWorkingRegistry() |
||
| 71 | { |
||
| 72 | $this->assertFalse($this->context->hasRegisteredValue("some_registry_id")); |
||
| 73 | |||
| 74 | $this->context->registerValue("some_registry_id", "Lorem ipsum"); |
||
| 75 | |||
| 76 | $this->assertTrue($this->context->hasRegisteredValue("some_registry_id")); |
||
| 77 | $this->assertEquals("Lorem ipsum", $this->context->getRegisteredValue("some_registry_id")); |
||
| 78 | |||
| 79 | $this->context->registerValue("some_registry_id", "dolor sit amet"); |
||
| 80 | |||
| 81 | $this->assertTrue($this->context->hasRegisteredValue("some_registry_id")); |
||
| 82 | $this->assertEquals("dolor sit amet", $this->context->getRegisteredValue("some_registry_id")); |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @test |
||
| 87 | */ |
||
| 88 | public function shouldMaintainObjectHydrationStack() |
||
| 89 | { |
||
| 90 | /** @var ValueObjectExample $object */ |
||
| 91 | $object = $this->createMock(ValueObjectExample::class); |
||
| 92 | |||
| 93 | $this->assertEquals([$this->entity], $this->context->getObjectHydrationStack()); |
||
| 94 | |||
| 95 | $this->context->pushOnObjectHydrationStack($object); |
||
| 96 | |||
| 97 | $this->assertEquals([$this->entity, $object], $this->context->getObjectHydrationStack()); |
||
| 98 | |||
| 99 | $this->assertSame($object, $this->context->popFromObjectHydrationStack()); |
||
| 100 | |||
| 101 | $this->assertEquals([$this->entity], $this->context->getObjectHydrationStack()); |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @test |
||
| 106 | */ |
||
| 107 | public function shouldThrowExceptionWhenPopFromEmptyObjectHydrationStack() |
||
| 108 | { |
||
| 109 | $this->expectException(InvalidArgumentException::class); |
||
| 110 | $this->context->popFromObjectHydrationStack(); |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @test |
||
| 115 | */ |
||
| 116 | public function shouldThrowExceptionWhenAccessUnknownRegistry() |
||
| 117 | { |
||
| 118 | $this->expectException(InvalidMappingException::class); |
||
| 119 | $this->context->getRegisteredValue("some_registry_id"); |
||
| 120 | } |
||
| 121 | |||
| 122 | } |
||
| 123 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..