Skip to content

Commit

Permalink
deduplicate loading enum when not-enum class test cases using data pr…
Browse files Browse the repository at this point in the history
…ovider
  • Loading branch information
petrduda committed Feb 27, 2023
1 parent 1dc8b81 commit 9a66d79
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 loadEnumNotEnumClassDataProvider(): 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(),
'expectedNotEnumClass' => 'Consistence\Doctrine\Enum\NonExistingClass',
];

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

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

Expand Down

0 comments on commit 9a66d79

Please sign in to comment.