From 2e02c47779023ea027f8b5b89c4d33b57844d5ce Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 10 Jul 2024 19:51:13 +0400 Subject: [PATCH] Fix tests --- src/Definition/Entity.php | 5 ++++- tests/Schema/EntityTest.php | 16 +++++++++++++++- tests/Schema/Generator/GenerateModifiersTest.php | 1 - tests/Schema/Generator/RenderModifiersTest.php | 12 +++++------- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Definition/Entity.php b/src/Definition/Entity.php index 7298108..ed46a9b 100644 --- a/src/Definition/Entity.php +++ b/src/Definition/Entity.php @@ -252,7 +252,10 @@ public function getForeignKeys(): ForeignKeyMap public function addSchemaModifier(SchemaModifierInterface $modifier): self { - $this->schemaModifiers[] = $modifier->withRole($this->role); + $this->schemaModifiers[] = $this->role === null + ? $modifier + : $modifier->withRole($this->role); + return $this; } diff --git a/tests/Schema/EntityTest.php b/tests/Schema/EntityTest.php index 29a1765..f714008 100644 --- a/tests/Schema/EntityTest.php +++ b/tests/Schema/EntityTest.php @@ -303,10 +303,24 @@ public function testJoinedTableInheritance(): void $this->assertSame($inheritance, $e->getInheritance()); } + public function testSchemaModifierWithRole(): void + { + $mock = $this->createMock(SchemaModifierInterface::class); + $mock->expects($this->once())->method('withRole')->with('my-entity')->willReturnSelf(); + + $e = new Entity(); + $e->setRole('my-entity'); + $e->addSchemaModifier($modifier = $mock); + + $this->assertSame([$modifier], iterator_to_array($e->getSchemaModifiers())); + } + public function testSchemaModifier(): void { + $mock = $this->createMock(SchemaModifierInterface::class); + $e = new Entity(); - $e->addSchemaModifier($modifier = $this->createMock(SchemaModifierInterface::class)); + $e->addSchemaModifier($modifier = $mock); $this->assertSame([$modifier], iterator_to_array($e->getSchemaModifiers())); } diff --git a/tests/Schema/Generator/GenerateModifiersTest.php b/tests/Schema/Generator/GenerateModifiersTest.php index 21d2c56..f499d68 100644 --- a/tests/Schema/Generator/GenerateModifiersTest.php +++ b/tests/Schema/Generator/GenerateModifiersTest.php @@ -98,7 +98,6 @@ public function testErrorInsideModifierShouldThrowAnException(string $method) public function brokenMethodsDataProvider() { return [ - 'withRole' => ['withRole'], 'compute' => ['compute'], ]; } diff --git a/tests/Schema/Generator/RenderModifiersTest.php b/tests/Schema/Generator/RenderModifiersTest.php index 5903e93..c10c73c 100644 --- a/tests/Schema/Generator/RenderModifiersTest.php +++ b/tests/Schema/Generator/RenderModifiersTest.php @@ -28,12 +28,10 @@ public function testEntityShouldBeRendered() $user->setRole('user')->setClass(User::class); $user->getFields()->set('foo_bar', (new Field())->setType('primary')->setColumn('id')); - $user->addSchemaModifier($mock = $this->createMock(SchemaModifierInterface::class)); - $mock - ->expects($this->atLeastOnce()) - ->method('withRole') - ->with($this->equalTo('user')) - ->willReturn($mock); + $mock = $this->createMock(SchemaModifierInterface::class); + $mock->expects(self::once())->method('withRole')->with('user')->willReturnSelf(); + + $user->addSchemaModifier($mock); $mock ->expects($this->atLeastOnce()) @@ -73,7 +71,7 @@ public function testErrorInsideModifierShouldThrowAnException(string $method) public function brokenMethodsDataProvider() { return [ - 'withRole' => ['withRole'], + // 'withRole' => ['withRole'], 'render' => ['render'], ]; }