Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jul 10, 2024
1 parent 3a7b2a8 commit 2e02c47
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/Definition/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
16 changes: 15 additions & 1 deletion tests/Schema/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
1 change: 0 additions & 1 deletion tests/Schema/Generator/GenerateModifiersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public function testErrorInsideModifierShouldThrowAnException(string $method)
public function brokenMethodsDataProvider()
{
return [
'withRole' => ['withRole'],
'compute' => ['compute'],
];
}
Expand Down
12 changes: 5 additions & 7 deletions tests/Schema/Generator/RenderModifiersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -73,7 +71,7 @@ public function testErrorInsideModifierShouldThrowAnException(string $method)
public function brokenMethodsDataProvider()
{
return [
'withRole' => ['withRole'],
// 'withRole' => ['withRole'],
'render' => ['render'],
];
}
Expand Down

0 comments on commit 2e02c47

Please sign in to comment.