Skip to content

Commit

Permalink
deduplicate loading enum to not-enum entity test cases using data pro…
Browse files Browse the repository at this point in the history
…vider
  • Loading branch information
petrduda committed Feb 27, 2023
1 parent 1dc8b81 commit b336584
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions tests/Enum/LoadEnumToEntityIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,35 @@ public function testLoadEnumMissingEnumClass(): void
$this->callPostLoadEventOnEntity(new BarEntity());
}

public function testLoadEnumNonExistingEnumClass(): void
public function loadEnumToNotEnumEntityDataProvider(): Generator
{
try {
$this->callPostLoadEventOnEntity(new BazEntity());
Assert::fail('Exception expected');
} catch (\Consistence\Doctrine\Enum\NotEnumException $e) {
Assert::assertSame('Consistence\Doctrine\Enum\NonExistingClass', $e->getEnumClass());
}
yield 'non-existing class' => [
'entity' => new BazEntity(),
'expectedClass' => 'Consistence\Doctrine\Enum\NonExistingClass',
];

yield 'not enum class' => [
'entity' => new BaxEntity(),
'expectedClass' => FooEntity::class,
];
}

public function testLoadEnumNotEnumClass(): void
/**
* @dataProvider loadEnumToNotEnumEntityDataProvider
*
* @param \Consistence\Doctrine\Enum\FooParentEntity $notEnumClassEntity
* @param string $expectedClass
*/
public function testLoadEnumToNotEnumEntity(
FooParentEntity $notEnumClassEntity,
string $expectedClass
): void
{
try {
$this->callPostLoadEventOnEntity(new BaxEntity());
$this->callPostLoadEventOnEntity($notEnumClassEntity);
Assert::fail('Exception expected');
} catch (\Consistence\Doctrine\Enum\NotEnumException $e) {
Assert::assertSame(FooEntity::class, $e->getEnumClass());
Assert::assertSame($expectedClass, $e->getEnumClass());
}
}

Expand Down

0 comments on commit b336584

Please sign in to comment.