@@ -1455,17 +1455,25 @@ class TestAutoLazyClassAttributeData extends Data
1455
1455
});
1456
1456
1457
1457
describe ('property-morphable creation tests ' , function () {
1458
+ enum TestPropertyMorphableEnum: string
1459
+ {
1460
+ case A = 'a ' ;
1461
+ case B = 'b ' ;
1462
+ };
1463
+
1458
1464
abstract class TestAbstractPropertyMorphableData extends Data implements PropertyMorphableData
1459
1465
{
1460
- public function __construct (public string $ variant )
1461
- {
1466
+ public function __construct (
1467
+ #[\Spatie \LaravelData \Attributes \PropertyForMorph]
1468
+ public TestPropertyMorphableEnum $ variant
1469
+ ) {
1462
1470
}
1463
1471
1464
1472
public static function morph (array $ properties ): ?string
1465
1473
{
1466
1474
return match ($ properties ['variant ' ] ?? null ) {
1467
- ' a ' => TestPropertyMorphableDataA::class,
1468
- ' b ' => TestPropertyMorphableDataB::class,
1475
+ TestPropertyMorphableEnum::A => TestPropertyMorphableDataA::class,
1476
+ TestPropertyMorphableEnum::B => TestPropertyMorphableDataB::class,
1469
1477
default => null ,
1470
1478
};
1471
1479
}
@@ -1475,15 +1483,15 @@ class TestPropertyMorphableDataA extends TestAbstractPropertyMorphableData
1475
1483
{
1476
1484
public function __construct (public string $ a , public DummyBackedEnum $ enum )
1477
1485
{
1478
- parent ::__construct (' a ' );
1486
+ parent ::__construct (TestPropertyMorphableEnum::A );
1479
1487
}
1480
1488
}
1481
1489
1482
1490
class TestPropertyMorphableDataB extends TestAbstractPropertyMorphableData
1483
1491
{
1484
1492
public function __construct (public string $ b )
1485
1493
{
1486
- parent ::__construct (' b ' );
1494
+ parent ::__construct (TestPropertyMorphableEnum::B );
1487
1495
}
1488
1496
}
1489
1497
@@ -1496,7 +1504,7 @@ public function __construct(public string $b)
1496
1504
1497
1505
expect ($ dataA )
1498
1506
->toBeInstanceOf (TestPropertyMorphableDataA::class)
1499
- ->variant ->toEqual (' a ' )
1507
+ ->variant ->toEqual (TestPropertyMorphableEnum::A )
1500
1508
->a ->toEqual ('foo ' )
1501
1509
->enum ->toEqual (DummyBackedEnum::FOO );
1502
1510
@@ -1507,7 +1515,7 @@ public function __construct(public string $b)
1507
1515
1508
1516
expect ($ dataB )
1509
1517
->toBeInstanceOf (TestPropertyMorphableDataB::class)
1510
- ->variant ->toEqual (' b ' )
1518
+ ->variant ->toEqual (TestPropertyMorphableEnum::B )
1511
1519
->b ->toEqual ('bar ' );
1512
1520
});
1513
1521
@@ -1519,7 +1527,7 @@ public function __construct(public string $b)
1519
1527
1520
1528
expect ($ dataA )
1521
1529
->toBeInstanceOf (TestPropertyMorphableDataA::class)
1522
- ->variant ->toEqual (' a ' )
1530
+ ->variant ->toEqual (TestPropertyMorphableEnum::A )
1523
1531
->a ->toEqual ('foo ' )
1524
1532
->enum ->toEqual (DummyBackedEnum::FOO );
1525
1533
});
@@ -1543,13 +1551,13 @@ public function __construct(
1543
1551
1544
1552
expect ($ data ->nestedCollection [0 ])
1545
1553
->toBeInstanceOf (TestPropertyMorphableDataA::class)
1546
- ->variant ->toEqual (' a ' )
1554
+ ->variant ->toEqual (TestPropertyMorphableEnum::A )
1547
1555
->a ->toEqual ('foo ' )
1548
1556
->enum ->toEqual (DummyBackedEnum::FOO );
1549
1557
1550
1558
expect ($ data ->nestedCollection [1 ])
1551
1559
->toBeInstanceOf (TestPropertyMorphableDataB::class)
1552
- ->variant ->toEqual (' b ' )
1560
+ ->variant ->toEqual (TestPropertyMorphableEnum::B )
1553
1561
->b ->toEqual ('bar ' );
1554
1562
});
1555
1563
@@ -1562,13 +1570,13 @@ public function __construct(
1562
1570
1563
1571
expect ($ collection [0 ])
1564
1572
->toBeInstanceOf (TestPropertyMorphableDataA::class)
1565
- ->variant ->toEqual (' a ' )
1573
+ ->variant ->toEqual (TestPropertyMorphableEnum::A )
1566
1574
->a ->toEqual ('foo ' )
1567
1575
->enum ->toEqual (DummyBackedEnum::FOO );
1568
1576
1569
1577
expect ($ collection [1 ])
1570
1578
->toBeInstanceOf (TestPropertyMorphableDataB::class)
1571
- ->variant ->toEqual (' b ' )
1579
+ ->variant ->toEqual (TestPropertyMorphableEnum::B )
1572
1580
->b ->toEqual ('bar ' );
1573
1581
});
1574
1582
});
0 commit comments