-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support more types as value of
SingleTable
attribute (#103)
Co-authored-by: Aleksei Gagarin <[email protected]>
- Loading branch information
Showing
7 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
tests/Annotated/Unit/Attribute/SingleTable/IntegerEnum.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\Annotated\Tests\Unit\Attribute\SingleTable; | ||
|
||
enum IntegerEnum: int | ||
{ | ||
case ONE = 1; | ||
case TWO = 2; | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/Annotated/Unit/Attribute/SingleTable/SingleTableTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\Annotated\Tests\Unit\Attribute\SingleTable; | ||
|
||
use Cycle\Annotated\Annotation\Inheritance\SingleTable; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class SingleTableTest extends TestCase | ||
{ | ||
public static function dataBase(): iterable | ||
{ | ||
yield [null, null]; | ||
yield ['test', 'test']; | ||
yield ['42', 42]; | ||
yield ['36.6', 36.6]; | ||
yield ['test', new StringableObject('test')]; | ||
yield ['1', IntegerEnum::ONE]; | ||
yield ['a', StringEnum::A]; | ||
} | ||
|
||
#[DataProvider('dataBase')] | ||
public function testBase1(?string $expected, mixed $value): void | ||
{ | ||
$attribute = new SingleTable($value); | ||
|
||
$this->assertSame($expected, $attribute->getValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\Annotated\Tests\Unit\Attribute\SingleTable; | ||
|
||
enum StringEnum: string | ||
{ | ||
case A = 'a'; | ||
case B = 'b'; | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/Annotated/Unit/Attribute/SingleTable/StringableObject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\Annotated\Tests\Unit\Attribute\SingleTable; | ||
|
||
use Stringable; | ||
|
||
final class StringableObject implements Stringable | ||
{ | ||
public function __construct( | ||
private string $value, | ||
) { | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters