File tree Expand file tree Collapse file tree
src/Annotation/Inheritance
Annotated/Unit/Attribute/SingleTable Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616 - name : Setup DB services
1717 run : |
1818 cd tests
19- docker- compose up -d
19+ docker compose up -d
2020 cd ..
2121 - name : Setup PHP ${{ matrix.php-version }}
2222 uses : shivammathur/setup-php@v2
Original file line number Diff line number Diff line change 1515#[\Attribute(\Attribute::TARGET_CLASS ), NamedArgumentConstructor]
1616class SingleTable extends Inheritance
1717{
18+ protected ?string $ value ;
19+
1820 public function __construct (
19- protected ? string $ value = null
21+ string | int | float | \ Stringable | \ BackedEnum | null $ value = null
2022 ) {
23+ $ this ->value = $ value === null
24+ ? null
25+ : (string ) ($ value instanceof \BackedEnum ? $ value ->value : $ value );
2126 parent ::__construct ('single ' );
2227 }
2328
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Cycle \Annotated \Tests \Unit \Attribute \SingleTable ;
6+
7+ enum IntegerEnum: int
8+ {
9+ case ONE = 1 ;
10+ case TWO = 2 ;
11+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Cycle \Annotated \Tests \Unit \Attribute \SingleTable ;
6+
7+ use Cycle \Annotated \Annotation \Inheritance \SingleTable ;
8+ use PHPUnit \Framework \Attributes \DataProvider ;
9+ use PHPUnit \Framework \TestCase ;
10+
11+ final class SingleTableTest extends TestCase
12+ {
13+ public static function dataBase (): iterable
14+ {
15+ yield [null , null ];
16+ yield ['test ' , 'test ' ];
17+ yield ['42 ' , 42 ];
18+ yield ['36.6 ' , 36.6 ];
19+ yield ['test ' , new StringableObject ('test ' )];
20+ yield ['1 ' , IntegerEnum::ONE ];
21+ yield ['a ' , StringEnum::A];
22+ }
23+
24+ #[DataProvider('dataBase ' )]
25+ public function testBase1 (?string $ expected , mixed $ value ): void
26+ {
27+ $ attribute = new SingleTable ($ value );
28+
29+ $ this ->assertSame ($ expected , $ attribute ->getValue ());
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Cycle \Annotated \Tests \Unit \Attribute \SingleTable ;
6+
7+ enum StringEnum: string
8+ {
9+ case A = 'a ' ;
10+ case B = 'b ' ;
11+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Cycle \Annotated \Tests \Unit \Attribute \SingleTable ;
6+
7+ use Stringable ;
8+
9+ final class StringableObject implements Stringable
10+ {
11+ public function __construct (
12+ private string $ value ,
13+ ) {
14+ }
15+
16+ public function __toString (): string
17+ {
18+ return $ this ->value ;
19+ }
20+ }
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ services:
1111 ACCEPT_EULA : " Y"
1212
1313 mysql_latest :
14- image : mysql:latest
14+ image : mysql:8.0
1515 restart : always
1616 command : --default-authentication-plugin=mysql_native_password
1717 ports :
You can’t perform that action at this time.
0 commit comments