Skip to content

Commit

Permalink
deduplicate creating enum values in data providers
Browse files Browse the repository at this point in the history
  • Loading branch information
petrduda committed Feb 22, 2023
1 parent 933dfd6 commit 8d4f5b1
Showing 1 changed file with 30 additions and 33 deletions.
63 changes: 30 additions & 33 deletions tests/Enum/Type/EnumTypeIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,44 @@ class EnumTypeIntegrationTest extends \PHPUnit\Framework\TestCase
/**
* @return mixed[][]|\Generator
*/
public function convertEnumToDatabaseDataProvider(): Generator
public function enumDataProvider(): Generator
{
yield 'float enum' => [
'type' => DoctrineType::getType(FloatEnumType::NAME),
'enum' => FooFloatEnum::get(FooFloatEnum::ONE),
'expectedValue' => FooFloatEnum::ONE,
'scalarValue' => FooFloatEnum::ONE,
];
yield 'integer enum' => [
'type' => DoctrineType::getType(IntegerEnumType::NAME),
'enum' => FooIntegerEnum::get(FooIntegerEnum::ONE),
'expectedValue' => FooIntegerEnum::ONE,
'scalarValue' => FooIntegerEnum::ONE,
];
yield 'string enum' => [
'type' => DoctrineType::getType(StringEnumType::NAME),
'enum' => FooStringEnum::get(FooStringEnum::ONE),
'expectedValue' => FooStringEnum::ONE,
'scalarValue' => FooStringEnum::ONE,
];
yield 'boolean enum' => [
'type' => DoctrineType::getType(BooleanEnumType::NAME),
'enum' => FooBooleanEnum::get(FooBooleanEnum::ENABLED),
'expectedValue' => FooBooleanEnum::ENABLED,
'scalarValue' => FooBooleanEnum::ENABLED,
];
}

/**
* @return mixed[][]|\Generator
*/
public function convertEnumToDatabaseDataProvider(): Generator
{
foreach ($this->enumDataProvider() as $name => $values) {
yield $name => [
'type' => $values['type'],
'enum' => $values['enum'],
'expectedValue' => $values['scalarValue'],
];
}
}

/**
* @dataProvider convertEnumToDatabaseDataProvider
*
Expand All @@ -58,18 +72,11 @@ public function testConvertEnumToDatabase(DoctrineType $type, Enum $enum, $expec
*/
public function enumTypesDataProvider(): Generator
{
yield 'float enum' => [
'type' => DoctrineType::getType(FloatEnumType::NAME),
];
yield 'integer enum' => [
'type' => DoctrineType::getType(IntegerEnumType::NAME),
];
yield 'string enum' => [
'type' => DoctrineType::getType(StringEnumType::NAME),
];
yield 'boolean enum' => [
'type' => DoctrineType::getType(BooleanEnumType::NAME),
];
foreach ($this->enumDataProvider() as $name => $values) {
yield $name => [
'type' => $values['type'],
];
}
}

/**
Expand All @@ -88,22 +95,12 @@ public function testConvertNullToDatabase(DoctrineType $type): void
*/
public function convertScalarValueToDatabaseDataProvider(): Generator
{
yield 'float enum' => [
'type' => DoctrineType::getType(FloatEnumType::NAME),
'scalarValue' => FooFloatEnum::ONE,
];
yield 'integer enum' => [
'type' => DoctrineType::getType(IntegerEnumType::NAME),
'scalarValue' => FooIntegerEnum::ONE,
];
yield 'string enum' => [
'type' => DoctrineType::getType(StringEnumType::NAME),
'scalarValue' => FooStringEnum::ONE,
];
yield 'boolean enum' => [
'type' => DoctrineType::getType(BooleanEnumType::NAME),
'scalarValue' => FooBooleanEnum::ENABLED,
];
foreach ($this->enumDataProvider() as $name => $values) {
yield $name => [
'type' => $values['type'],
'scalarValue' => $values['scalarValue'],
];
}
}

/**
Expand Down

0 comments on commit 8d4f5b1

Please sign in to comment.