From d6591f452c77c82150757b3362a230c4fd75ce5c Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Wed, 28 Aug 2024 12:16:14 +0700 Subject: [PATCH] Test `ArrayableTrait` separately (#382) --- tests/ActiveQueryTest.php | 14 -- tests/ActiveRecordTest.php | 98 ------------- tests/ArrayableTraitTest.php | 133 ++++++++++++++++++ tests/Driver/Mssql/ActiveRecordTest.php | 2 +- tests/Driver/Mssql/ArrayableTraitTest.php | 16 +++ tests/Driver/Mysql/ArrayableTraitTest.php | 16 +++ tests/Driver/Oracle/ActiveRecordTest.php | 43 ------ tests/Driver/Oracle/ArrayableTraitTest.php | 61 ++++++++ tests/Driver/Oracle/MagicActiveRecordTest.php | 43 ------ tests/Driver/Pgsql/ActiveRecordTest.php | 55 +------- tests/Driver/Pgsql/ArrayableTraitTest.php | 16 +++ tests/Driver/Pgsql/MagicActiveRecordTest.php | 43 ------ tests/Driver/Sqlite/ArrayableTraitTest.php | 16 +++ tests/MagicActiveRecordTest.php | 98 ------------- tests/Stubs/ActiveRecord.php | 39 ----- tests/Stubs/ActiveRecord/Alpha.php | 2 +- tests/Stubs/ActiveRecord/Animal.php | 2 +- .../Stubs/ActiveRecord/ArrayAndJsonTypes.php | 2 +- tests/Stubs/ActiveRecord/Beta.php | 2 +- tests/Stubs/ActiveRecord/BitValues.php | 2 +- tests/Stubs/ActiveRecord/BoolAR.php | 2 +- tests/Stubs/ActiveRecord/Category.php | 2 +- tests/Stubs/ActiveRecord/Customer.php | 4 +- .../ActiveRecord/CustomerClosureField.php | 4 +- .../ActiveRecord/CustomerForArrayable.php | 4 +- .../Stubs/ActiveRecord/CustomerWithAlias.php | 2 +- tests/Stubs/ActiveRecord/DefaultPk.php | 2 +- tests/Stubs/ActiveRecord/Department.php | 2 +- tests/Stubs/ActiveRecord/Document.php | 2 +- tests/Stubs/ActiveRecord/Dossier.php | 2 +- tests/Stubs/ActiveRecord/Employee.php | 2 +- tests/Stubs/ActiveRecord/Item.php | 2 +- tests/Stubs/ActiveRecord/NoExist.php | 2 +- tests/Stubs/ActiveRecord/NullValues.php | 2 +- tests/Stubs/ActiveRecord/Order.php | 2 +- tests/Stubs/ActiveRecord/OrderItem.php | 16 +-- .../ActiveRecord/OrderItemWithNullFK.php | 2 +- tests/Stubs/ActiveRecord/OrderWithNullFK.php | 2 +- tests/Stubs/ActiveRecord/Profile.php | 2 +- .../ActiveRecord/ProfileWithConstructor.php | 2 +- tests/Stubs/ActiveRecord/TestTrigger.php | 2 +- tests/Stubs/ActiveRecord/TestTriggerAlert.php | 2 +- tests/Stubs/ActiveRecord/Type.php | 2 +- tests/Stubs/ActiveRecord/UserAR.php | 2 +- tests/Stubs/ArrayableActiveRecord.php | 19 +++ tests/Stubs/MagicActiveRecord.php | 27 +--- .../CustomerClosureField.php | 33 ----- .../CustomerForArrayable.php | 57 -------- 48 files changed, 317 insertions(+), 590 deletions(-) create mode 100644 tests/ArrayableTraitTest.php create mode 100644 tests/Driver/Mssql/ArrayableTraitTest.php create mode 100644 tests/Driver/Mysql/ArrayableTraitTest.php create mode 100644 tests/Driver/Oracle/ArrayableTraitTest.php create mode 100644 tests/Driver/Pgsql/ArrayableTraitTest.php create mode 100644 tests/Driver/Sqlite/ArrayableTraitTest.php delete mode 100644 tests/Stubs/ActiveRecord.php create mode 100644 tests/Stubs/ArrayableActiveRecord.php delete mode 100644 tests/Stubs/MagicActiveRecord/CustomerClosureField.php delete mode 100644 tests/Stubs/MagicActiveRecord/CustomerForArrayable.php diff --git a/tests/ActiveQueryTest.php b/tests/ActiveQueryTest.php index 9c1b016a2..72d3d402d 100644 --- a/tests/ActiveQueryTest.php +++ b/tests/ActiveQueryTest.php @@ -2160,20 +2160,6 @@ public function testGetAttributesExcept(): void ); } - public function testFields(): void - { - $this->checkFixture($this->db(), 'order_item'); - - $orderItem = new ActiveQuery(OrderItem::class); - - $fields = $orderItem->findOne(['order_id' => 1, 'item_id' => 2])->fields(); - - $this->assertEquals( - $fields, - ['order_id' => 1, 'item_id' => 2, 'quantity' => 2, 'subtotal' => '40', 'price' => 20] - ); - } - public function testGetOldAttribute(): void { $this->checkFixture($this->db(), 'customer'); diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php index b070e78fe..539e54b5d 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -13,8 +13,6 @@ use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Animal; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Cat; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Customer; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\CustomerClosureField; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\CustomerForArrayable; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\CustomerWithAlias; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\CustomerWithFactory; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\CustomerWithCustomConnection; @@ -754,102 +752,6 @@ public function testJoinWithEager() $this->assertEquals($eagerItemsCount, $lazyItemsCount); } - public function testToArray(): void - { - $this->checkFixture($this->db(), 'customer', true); - - $customerQuery = new ActiveQuery(Customer::class); - $customer = $customerQuery->findOne(1); - - $this->assertSame( - [ - 'id' => 1, - 'email' => 'user1@example.com', - 'name' => 'user1', - 'address' => 'address1', - 'status' => 1, - 'bool_status' => true, - 'profile_id' => 1, - ], - $customer->toArray(), - ); - } - - public function testToArrayWithClosure(): void - { - $this->checkFixture($this->db(), 'customer', true); - - $customerQuery = new ActiveQuery(CustomerClosureField::class); - $customer = $customerQuery->findOne(1); - - $this->assertSame( - [ - 'id' => 1, - 'email' => 'user1@example.com', - 'name' => 'user1', - 'address' => 'address1', - 'status' => 'active', - 'bool_status' => true, - 'profile_id' => 1, - ], - $customer->toArray(), - ); - } - - public function testToArrayForArrayable(): void - { - $this->checkFixture($this->db(), 'customer', true); - - $customerQuery = new ActiveQuery(CustomerForArrayable::class); - - /** @var CustomerForArrayable $customer */ - $customer = $customerQuery->findOne(1); - /** @var CustomerForArrayable $customer2 */ - $customer2 = $customerQuery->findOne(2); - /** @var CustomerForArrayable $customer3 */ - $customer3 = $customerQuery->findOne(3); - - $customer->setItem($customer2); - $customer->setItems($customer3); - - $this->assertSame( - [ - 'id' => 1, - 'email' => 'user1@example.com', - 'name' => 'user1', - 'address' => 'address1', - 'status' => 'active', - 'item' => [ - 'id' => 2, - 'email' => 'user2@example.com', - 'name' => 'user2', - 'status' => 'active', - ], - 'items' => [ - [ - 'id' => 3, - 'email' => 'user3@example.com', - 'name' => 'user3', - 'status' => 'inactive', - ], - ], - ], - $customer->toArray([ - 'id', - 'name', - 'email', - 'address', - 'status', - 'item.id', - 'item.name', - 'item.email', - 'items.0.id', - 'items.0.name', - 'items.0.email', - ]), - ); - } - public function testSaveWithoutChanges(): void { $this->checkFixture($this->db(), 'customer'); diff --git a/tests/ArrayableTraitTest.php b/tests/ArrayableTraitTest.php new file mode 100644 index 000000000..43c407684 --- /dev/null +++ b/tests/ArrayableTraitTest.php @@ -0,0 +1,133 @@ +checkFixture($this->db(), 'customer'); + + $customerQuery = new ActiveQuery(CustomerForArrayable::class); + + $fields = $customerQuery->findOne(['id' => 1])->fields(); + + $this->assertEquals( + [ + 'id' => 'id', + 'email' => 'email', + 'name' => 'name', + 'address' => 'address', + 'status' => 'status', + 'bool_status' => 'bool_status', + 'profile_id' => 'profile_id', + 'item' => 'item', + 'items' => 'items', + ], + $fields, + ); + } + + public function testToArray(): void + { + $this->checkFixture($this->db(), 'customer', true); + + $customerQuery = new ActiveQuery(Customer::class); + $customer = $customerQuery->findOne(1); + + $this->assertSame( + [ + 'id' => 1, + 'email' => 'user1@example.com', + 'name' => 'user1', + 'address' => 'address1', + 'status' => 1, + 'bool_status' => true, + 'profile_id' => 1, + ], + $customer->toArray(), + ); + } + + public function testToArrayWithClosure(): void + { + $this->checkFixture($this->db(), 'customer', true); + + $customerQuery = new ActiveQuery(CustomerClosureField::class); + $customer = $customerQuery->findOne(1); + + $this->assertSame( + [ + 'id' => 1, + 'email' => 'user1@example.com', + 'name' => 'user1', + 'address' => 'address1', + 'status' => 'active', + 'bool_status' => true, + 'profile_id' => 1, + ], + $customer->toArray(), + ); + } + + public function testToArrayForArrayable(): void + { + $this->checkFixture($this->db(), 'customer', true); + + $customerQuery = new ActiveQuery(CustomerForArrayable::class); + + /** @var CustomerForArrayable $customer */ + $customer = $customerQuery->findOne(1); + /** @var CustomerForArrayable $customer2 */ + $customer2 = $customerQuery->findOne(2); + /** @var CustomerForArrayable $customer3 */ + $customer3 = $customerQuery->findOne(3); + + $customer->setItem($customer2); + $customer->setItems($customer3); + + $this->assertSame( + [ + 'id' => 1, + 'email' => 'user1@example.com', + 'name' => 'user1', + 'address' => 'address1', + 'status' => 'active', + 'item' => [ + 'id' => 2, + 'email' => 'user2@example.com', + 'name' => 'user2', + 'status' => 'active', + ], + 'items' => [ + [ + 'id' => 3, + 'email' => 'user3@example.com', + 'name' => 'user3', + 'status' => 'inactive', + ], + ], + ], + $customer->toArray([ + 'id', + 'name', + 'email', + 'address', + 'status', + 'item.id', + 'item.name', + 'item.email', + 'items.0.id', + 'items.0.name', + 'items.0.email', + ]), + ); + } +} diff --git a/tests/Driver/Mssql/ActiveRecordTest.php b/tests/Driver/Mssql/ActiveRecordTest.php index a3d738ca8..a15944aa9 100644 --- a/tests/Driver/Mssql/ActiveRecordTest.php +++ b/tests/Driver/Mssql/ActiveRecordTest.php @@ -49,7 +49,7 @@ public function testSaveWithTrigger(): void SQL; $this->db()->createCommand($sql)->execute(); - $record = new TestTrigger($this->db()); + $record = new TestTrigger(); $record->stringcol = 'test'; diff --git a/tests/Driver/Mssql/ArrayableTraitTest.php b/tests/Driver/Mssql/ArrayableTraitTest.php new file mode 100644 index 000000000..25e818779 --- /dev/null +++ b/tests/Driver/Mssql/ArrayableTraitTest.php @@ -0,0 +1,16 @@ +createConnection(); + } +} diff --git a/tests/Driver/Mysql/ArrayableTraitTest.php b/tests/Driver/Mysql/ArrayableTraitTest.php new file mode 100644 index 000000000..0ae1a1d99 --- /dev/null +++ b/tests/Driver/Mysql/ArrayableTraitTest.php @@ -0,0 +1,16 @@ +createConnection(); + } +} diff --git a/tests/Driver/Oracle/ActiveRecordTest.php b/tests/Driver/Oracle/ActiveRecordTest.php index 59d86be41..af89974c4 100644 --- a/tests/Driver/Oracle/ActiveRecordTest.php +++ b/tests/Driver/Oracle/ActiveRecordTest.php @@ -6,7 +6,6 @@ use Yiisoft\ActiveRecord\ActiveQuery; use Yiisoft\ActiveRecord\Tests\Driver\Oracle\Stubs\Customer; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\CustomerClosureField; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Type; use Yiisoft\ActiveRecord\Tests\Support\OracleHelper; use Yiisoft\Db\Connection\ConnectionInterface; @@ -119,46 +118,4 @@ public function testBooleanAttribute(): void $customers = $customerQuery->where(['status' => '0'])->all(); $this->assertCount(1, $customers); } - - public function testToArray(): void - { - $this->checkFixture($this->db(), 'customer', true); - - $customerQuery = new ActiveQuery(Customer::class); - $customer = $customerQuery->findOne(1); - - $this->assertSame( - [ - 'id' => 1, - 'email' => 'user1@example.com', - 'name' => 'user1', - 'address' => 'address1', - 'status' => 1, - 'bool_status' => '1', - 'profile_id' => 1, - ], - $customer->toArray(), - ); - } - - public function testToArrayWithClosure(): void - { - $this->checkFixture($this->db(), 'customer', true); - - $customerQuery = new ActiveQuery(CustomerClosureField::class); - $customer = $customerQuery->findOne(1); - - $this->assertSame( - [ - 'id' => 1, - 'email' => 'user1@example.com', - 'name' => 'user1', - 'address' => 'address1', - 'status' => 'active', - 'bool_status' => '1', - 'profile_id' => 1, - ], - $customer->toArray(), - ); - } } diff --git a/tests/Driver/Oracle/ArrayableTraitTest.php b/tests/Driver/Oracle/ArrayableTraitTest.php new file mode 100644 index 000000000..3c84f4fae --- /dev/null +++ b/tests/Driver/Oracle/ArrayableTraitTest.php @@ -0,0 +1,61 @@ +createConnection(); + } + + public function testToArray(): void + { + $this->checkFixture($this->db(), 'customer', true); + + $customerQuery = new ActiveQuery(Customer::class); + $customer = $customerQuery->findOne(1); + + $this->assertSame( + [ + 'id' => 1, + 'email' => 'user1@example.com', + 'name' => 'user1', + 'address' => 'address1', + 'status' => 1, + 'bool_status' => '1', + 'profile_id' => 1, + ], + $customer->toArray(), + ); + } + + public function testToArrayWithClosure(): void + { + $this->checkFixture($this->db(), 'customer', true); + + $customerQuery = new ActiveQuery(CustomerClosureField::class); + $customer = $customerQuery->findOne(1); + + $this->assertSame( + [ + 'id' => 1, + 'email' => 'user1@example.com', + 'name' => 'user1', + 'address' => 'address1', + 'status' => 'active', + 'bool_status' => '1', + 'profile_id' => 1, + ], + $customer->toArray(), + ); + } +} diff --git a/tests/Driver/Oracle/MagicActiveRecordTest.php b/tests/Driver/Oracle/MagicActiveRecordTest.php index 677091f5f..5a59a69d5 100644 --- a/tests/Driver/Oracle/MagicActiveRecordTest.php +++ b/tests/Driver/Oracle/MagicActiveRecordTest.php @@ -6,7 +6,6 @@ use Yiisoft\ActiveRecord\ActiveQuery; use Yiisoft\ActiveRecord\Tests\Driver\Oracle\Stubs\MagicCustomer as Customer; -use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\CustomerClosureField; use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\Type; use Yiisoft\ActiveRecord\Tests\Support\OracleHelper; use Yiisoft\Db\Connection\ConnectionInterface; @@ -113,46 +112,4 @@ public function testBooleanAttribute(): void $customers = $customerQuery->where(['status' => '0'])->all(); $this->assertCount(1, $customers); } - - public function testToArray(): void - { - $this->checkFixture($this->db(), 'customer', true); - - $customerQuery = new ActiveQuery(Customer::class); - $customer = $customerQuery->findOne(1); - - $this->assertSame( - [ - 'id' => 1, - 'email' => 'user1@example.com', - 'name' => 'user1', - 'address' => 'address1', - 'status' => 1, - 'bool_status' => '1', - 'profile_id' => 1, - ], - $customer->toArray(), - ); - } - - public function testToArrayWithClosure(): void - { - $this->checkFixture($this->db(), 'customer', true); - - $customerQuery = new ActiveQuery(CustomerClosureField::class); - $customer = $customerQuery->findOne(1); - - $this->assertSame( - [ - 'id' => 1, - 'email' => 'user1@example.com', - 'name' => 'user1', - 'address' => 'address1', - 'status' => 'active', - 'bool_status' => '1', - 'profile_id' => 1, - ], - $customer->toArray(), - ); - } } diff --git a/tests/Driver/Pgsql/ActiveRecordTest.php b/tests/Driver/Pgsql/ActiveRecordTest.php index 3a186f2dd..c67bc730d 100644 --- a/tests/Driver/Pgsql/ActiveRecordTest.php +++ b/tests/Driver/Pgsql/ActiveRecordTest.php @@ -15,7 +15,6 @@ use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Beta; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\BoolAR; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Customer; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\CustomerClosureField; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\DefaultPk; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\UserAR; use Yiisoft\ActiveRecord\Tests\Support\PgsqlHelper; @@ -42,7 +41,7 @@ public function testDefaultValues(): void { $this->checkFixture($this->db(), 'type'); - $arClass = new Type($this->db()); + $arClass = new Type(); $arClass->loadDefaultValues(); @@ -53,13 +52,13 @@ public function testDefaultValues(): void $this->assertEquals(true, $arClass->bool_col2); $this->assertEquals('2002-01-01 00:00:00', $arClass->time); - $arClass = new Type($this->db()); + $arClass = new Type(); $arClass->char_col2 = 'not something'; $arClass->loadDefaultValues(); $this->assertEquals('not something', $arClass->char_col2); - $arClass = new Type($this->db()); + $arClass = new Type(); $arClass->char_col2 = 'not something'; $arClass->loadDefaultValues(false); @@ -70,7 +69,7 @@ public function testCastValues(): void { $this->checkFixture($this->db(), 'type'); - $arClass = new Type($this->db()); + $arClass = new Type(); $arClass->int_col = 123; $arClass->int_col2 = 456; @@ -101,7 +100,7 @@ public function testExplicitPkOnAutoIncrement(): void { $this->checkFixture($this->db(), 'customer'); - $customer = new Customer($this->db()); + $customer = new Customer(); $customer->setId(1337); $customer->setEmail('user1337@example.com'); $customer->setName('user1337'); @@ -140,7 +139,7 @@ public function testBooleanAttribute(): void { $this->checkFixture($this->db(), 'customer', true); - $customer = new Customer($this->db()); + $customer = new Customer(); $customer->setName('boolean customer'); $customer->setEmail('mail@example.com'); $customer->setBoolStatus(false); @@ -398,48 +397,6 @@ public function testArrayValues($attributes): void $this->assertSame(1, $type->update(), 'The record got updated'); } - public function testToArray(): void - { - $this->checkFixture($this->db(), 'customer', true); - - $customerQuery = new ActiveQuery(Customer::class); - $customer = $customerQuery->findOne(1); - - $this->assertSame( - [ - 'id' => 1, - 'email' => 'user1@example.com', - 'name' => 'user1', - 'address' => 'address1', - 'status' => 1, - 'bool_status' => true, - 'profile_id' => 1, - ], - $customer->toArray(), - ); - } - - public function testToArrayWithClosure(): void - { - $this->checkFixture($this->db(), 'customer', true); - - $customerQuery = new ActiveQuery(CustomerClosureField::class); - $customer = $customerQuery->findOne(1); - - $this->assertSame( - [ - 'id' => 1, - 'email' => 'user1@example.com', - 'name' => 'user1', - 'address' => 'address1', - 'status' => 'active', - 'bool_status' => true, - 'profile_id' => 1, - ], - $customer->toArray(), - ); - } - public function testRelationViaArray() { $this->checkFixture($this->db(), 'promotion'); diff --git a/tests/Driver/Pgsql/ArrayableTraitTest.php b/tests/Driver/Pgsql/ArrayableTraitTest.php new file mode 100644 index 000000000..b2ebfbde2 --- /dev/null +++ b/tests/Driver/Pgsql/ArrayableTraitTest.php @@ -0,0 +1,16 @@ +createConnection(); + } +} diff --git a/tests/Driver/Pgsql/MagicActiveRecordTest.php b/tests/Driver/Pgsql/MagicActiveRecordTest.php index f7958ab0b..951f59d27 100644 --- a/tests/Driver/Pgsql/MagicActiveRecordTest.php +++ b/tests/Driver/Pgsql/MagicActiveRecordTest.php @@ -11,7 +11,6 @@ use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\Beta; use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\BoolAR; use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\Customer; -use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\CustomerClosureField; use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\DefaultPk; use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\UserAR; use Yiisoft\ActiveRecord\Tests\Support\PgsqlHelper; @@ -328,46 +327,4 @@ public function testArrayValues($attributes): void $this->assertSame(1, $type->update(), 'The record got updated'); } - - public function testToArray(): void - { - $this->checkFixture($this->db(), 'customer', true); - - $customerQuery = new ActiveQuery(Customer::class); - $customer = $customerQuery->findOne(1); - - $this->assertSame( - [ - 'id' => 1, - 'email' => 'user1@example.com', - 'name' => 'user1', - 'address' => 'address1', - 'status' => 1, - 'bool_status' => true, - 'profile_id' => 1, - ], - $customer->toArray(), - ); - } - - public function testToArrayWithClosure(): void - { - $this->checkFixture($this->db(), 'customer', true); - - $customerQuery = new ActiveQuery(CustomerClosureField::class); - $customer = $customerQuery->findOne(1); - - $this->assertSame( - [ - 'id' => 1, - 'email' => 'user1@example.com', - 'name' => 'user1', - 'address' => 'address1', - 'status' => 'active', - 'bool_status' => true, - 'profile_id' => 1, - ], - $customer->toArray(), - ); - } } diff --git a/tests/Driver/Sqlite/ArrayableTraitTest.php b/tests/Driver/Sqlite/ArrayableTraitTest.php new file mode 100644 index 000000000..8f02e00a9 --- /dev/null +++ b/tests/Driver/Sqlite/ArrayableTraitTest.php @@ -0,0 +1,16 @@ +createConnection(); + } +} diff --git a/tests/MagicActiveRecordTest.php b/tests/MagicActiveRecordTest.php index 0239ad393..924a04ada 100644 --- a/tests/MagicActiveRecordTest.php +++ b/tests/MagicActiveRecordTest.php @@ -11,8 +11,6 @@ use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\Animal; use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\Cat; use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\Customer; -use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\CustomerClosureField; -use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\CustomerForArrayable; use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\CustomerWithAlias; use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\CustomerWithProperties; use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\Dog; @@ -736,102 +734,6 @@ public function testJoinWithEager() $this->assertEquals($eagerItemsCount, $lazyItemsCount); } - public function testToArray(): void - { - $this->checkFixture($this->db(), 'customer', true); - - $customerQuery = new ActiveQuery(Customer::class); - $customer = $customerQuery->findOne(1); - - $this->assertSame( - [ - 'id' => 1, - 'email' => 'user1@example.com', - 'name' => 'user1', - 'address' => 'address1', - 'status' => 1, - 'bool_status' => true, - 'profile_id' => 1, - ], - $customer->toArray(), - ); - } - - public function testToArrayWithClosure(): void - { - $this->checkFixture($this->db(), 'customer', true); - - $customerQuery = new ActiveQuery(CustomerClosureField::class); - $customer = $customerQuery->findOne(1); - - $this->assertSame( - [ - 'id' => 1, - 'email' => 'user1@example.com', - 'name' => 'user1', - 'address' => 'address1', - 'status' => 'active', - 'bool_status' => true, - 'profile_id' => 1, - ], - $customer->toArray(), - ); - } - - public function testToArrayForArrayable(): void - { - $this->checkFixture($this->db(), 'customer', true); - - $customerQuery = new ActiveQuery(CustomerForArrayable::class); - - /** @var CustomerForArrayable $customer */ - $customer = $customerQuery->findOne(1); - /** @var CustomerForArrayable $customer2 */ - $customer2 = $customerQuery->findOne(2); - /** @var CustomerForArrayable $customer3 */ - $customer3 = $customerQuery->findOne(3); - - $customer->setItem($customer2); - $customer->setItems($customer3); - - $this->assertSame( - [ - 'id' => 1, - 'email' => 'user1@example.com', - 'name' => 'user1', - 'address' => 'address1', - 'status' => 'active', - 'item' => [ - 'id' => 2, - 'email' => 'user2@example.com', - 'name' => 'user2', - 'status' => 'active', - ], - 'items' => [ - [ - 'id' => 3, - 'email' => 'user3@example.com', - 'name' => 'user3', - 'status' => 'inactive', - ], - ], - ], - $customer->toArray([ - 'id', - 'name', - 'email', - 'address', - 'status', - 'item.id', - 'item.name', - 'item.email', - 'items.0.id', - 'items.0.name', - 'items.0.email', - ]), - ); - } - public function testSaveWithoutChanges(): void { $this->checkFixture($this->db(), 'customer'); diff --git a/tests/Stubs/ActiveRecord.php b/tests/Stubs/ActiveRecord.php deleted file mode 100644 index 8c3b80568..000000000 --- a/tests/Stubs/ActiveRecord.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @template-implements IteratorAggregate - * - * @see ActiveRecord for more information. - */ -class ActiveRecord extends \Yiisoft\ActiveRecord\ActiveRecord implements - ArrayableInterface, - ArrayAccess, - IteratorAggregate, - TransactionalInterface -{ - use ArrayableTrait; - use ArrayAccessTrait; - use ArrayIteratorTrait; - use TransactionalTrait; -} diff --git a/tests/Stubs/ActiveRecord/Alpha.php b/tests/Stubs/ActiveRecord/Alpha.php index f60abab51..ba7ac208b 100644 --- a/tests/Stubs/ActiveRecord/Alpha.php +++ b/tests/Stubs/ActiveRecord/Alpha.php @@ -6,7 +6,7 @@ use Yiisoft\ActiveRecord\ActiveQuery; use Yiisoft\ActiveRecord\ActiveQueryInterface; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; final class Alpha extends ActiveRecord { diff --git a/tests/Stubs/ActiveRecord/Animal.php b/tests/Stubs/ActiveRecord/Animal.php index 7346abc99..5530334b6 100644 --- a/tests/Stubs/ActiveRecord/Animal.php +++ b/tests/Stubs/ActiveRecord/Animal.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; use Yiisoft\ActiveRecord\ActiveRecordInterface; /** diff --git a/tests/Stubs/ActiveRecord/ArrayAndJsonTypes.php b/tests/Stubs/ActiveRecord/ArrayAndJsonTypes.php index 7cdcfc7ea..be17258c4 100644 --- a/tests/Stubs/ActiveRecord/ArrayAndJsonTypes.php +++ b/tests/Stubs/ActiveRecord/ArrayAndJsonTypes.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; use Yiisoft\Db\Expression\ArrayExpression; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Expression\JsonExpression; diff --git a/tests/Stubs/ActiveRecord/Beta.php b/tests/Stubs/ActiveRecord/Beta.php index 9449aaaf0..9e7a9cde2 100644 --- a/tests/Stubs/ActiveRecord/Beta.php +++ b/tests/Stubs/ActiveRecord/Beta.php @@ -6,7 +6,7 @@ use Yiisoft\ActiveRecord\ActiveQuery; use Yiisoft\ActiveRecord\ActiveQueryInterface; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; final class Beta extends ActiveRecord { diff --git a/tests/Stubs/ActiveRecord/BitValues.php b/tests/Stubs/ActiveRecord/BitValues.php index 53758395f..7d61c2c66 100644 --- a/tests/Stubs/ActiveRecord/BitValues.php +++ b/tests/Stubs/ActiveRecord/BitValues.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; /** * {@see https://github.com/yiisoft/yii2/issues/9006} diff --git a/tests/Stubs/ActiveRecord/BoolAR.php b/tests/Stubs/ActiveRecord/BoolAR.php index 3f11de60d..058f6bd1c 100644 --- a/tests/Stubs/ActiveRecord/BoolAR.php +++ b/tests/Stubs/ActiveRecord/BoolAR.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; final class BoolAR extends ActiveRecord { diff --git a/tests/Stubs/ActiveRecord/Category.php b/tests/Stubs/ActiveRecord/Category.php index ceba7ac3e..e151077cc 100644 --- a/tests/Stubs/ActiveRecord/Category.php +++ b/tests/Stubs/ActiveRecord/Category.php @@ -6,7 +6,7 @@ use Yiisoft\ActiveRecord\ActiveQuery; use Yiisoft\ActiveRecord\ActiveQueryInterface; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; /** * Class Category. diff --git a/tests/Stubs/ActiveRecord/Customer.php b/tests/Stubs/ActiveRecord/Customer.php index 786487756..22d118c35 100644 --- a/tests/Stubs/ActiveRecord/Customer.php +++ b/tests/Stubs/ActiveRecord/Customer.php @@ -6,12 +6,12 @@ use Yiisoft\ActiveRecord\ActiveQuery; use Yiisoft\ActiveRecord\ActiveQueryInterface; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\Tests\Stubs\ArrayableActiveRecord; /** * Class Customer. */ -class Customer extends ActiveRecord +class Customer extends ArrayableActiveRecord { public const STATUS_ACTIVE = 1; public const STATUS_INACTIVE = 2; diff --git a/tests/Stubs/ActiveRecord/CustomerClosureField.php b/tests/Stubs/ActiveRecord/CustomerClosureField.php index cb1567edf..69346fb93 100644 --- a/tests/Stubs/ActiveRecord/CustomerClosureField.php +++ b/tests/Stubs/ActiveRecord/CustomerClosureField.php @@ -4,12 +4,12 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\Tests\Stubs\ArrayableActiveRecord; /** * Class CustomerClosureField. */ -final class CustomerClosureField extends ActiveRecord +final class CustomerClosureField extends ArrayableActiveRecord { protected int $id; protected string $email; diff --git a/tests/Stubs/ActiveRecord/CustomerForArrayable.php b/tests/Stubs/ActiveRecord/CustomerForArrayable.php index 2abd3640f..fb2bfb2df 100644 --- a/tests/Stubs/ActiveRecord/CustomerForArrayable.php +++ b/tests/Stubs/ActiveRecord/CustomerForArrayable.php @@ -4,12 +4,12 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\Tests\Stubs\ArrayableActiveRecord; /** * Class CustomerClosureField. */ -class CustomerForArrayable extends ActiveRecord +class CustomerForArrayable extends ArrayableActiveRecord { public array $items = []; diff --git a/tests/Stubs/ActiveRecord/CustomerWithAlias.php b/tests/Stubs/ActiveRecord/CustomerWithAlias.php index 13c11163a..b5b7aab7a 100644 --- a/tests/Stubs/ActiveRecord/CustomerWithAlias.php +++ b/tests/Stubs/ActiveRecord/CustomerWithAlias.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; /** * Class Customer. diff --git a/tests/Stubs/ActiveRecord/DefaultPk.php b/tests/Stubs/ActiveRecord/DefaultPk.php index 73d4f71af..7565a1f29 100644 --- a/tests/Stubs/ActiveRecord/DefaultPk.php +++ b/tests/Stubs/ActiveRecord/DefaultPk.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; final class DefaultPk extends ActiveRecord { diff --git a/tests/Stubs/ActiveRecord/Department.php b/tests/Stubs/ActiveRecord/Department.php index cbe9e0f8c..4de951604 100644 --- a/tests/Stubs/ActiveRecord/Department.php +++ b/tests/Stubs/ActiveRecord/Department.php @@ -6,7 +6,7 @@ use Yiisoft\ActiveRecord\ActiveQuery; use Yiisoft\ActiveRecord\ActiveQueryInterface; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; use Yiisoft\ActiveRecord\ActiveRecordInterface; /** diff --git a/tests/Stubs/ActiveRecord/Document.php b/tests/Stubs/ActiveRecord/Document.php index ab74651fc..ef1eb860a 100644 --- a/tests/Stubs/ActiveRecord/Document.php +++ b/tests/Stubs/ActiveRecord/Document.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; final class Document extends ActiveRecord { diff --git a/tests/Stubs/ActiveRecord/Dossier.php b/tests/Stubs/ActiveRecord/Dossier.php index 1caa605e4..56642adc2 100644 --- a/tests/Stubs/ActiveRecord/Dossier.php +++ b/tests/Stubs/ActiveRecord/Dossier.php @@ -6,7 +6,7 @@ use Yiisoft\ActiveRecord\ActiveQuery; use Yiisoft\ActiveRecord\ActiveQueryInterface; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; /** * Class Dossier diff --git a/tests/Stubs/ActiveRecord/Employee.php b/tests/Stubs/ActiveRecord/Employee.php index b3e02ffe2..5bd94b631 100644 --- a/tests/Stubs/ActiveRecord/Employee.php +++ b/tests/Stubs/ActiveRecord/Employee.php @@ -6,7 +6,7 @@ use Yiisoft\ActiveRecord\ActiveQuery; use Yiisoft\ActiveRecord\ActiveQueryInterface; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; /** * Class Employee diff --git a/tests/Stubs/ActiveRecord/Item.php b/tests/Stubs/ActiveRecord/Item.php index ee4ed4658..fb2001bae 100644 --- a/tests/Stubs/ActiveRecord/Item.php +++ b/tests/Stubs/ActiveRecord/Item.php @@ -6,7 +6,7 @@ use Yiisoft\ActiveRecord\ActiveQuery; use Yiisoft\ActiveRecord\ActiveQueryInterface; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; /** * Class Item. diff --git a/tests/Stubs/ActiveRecord/NoExist.php b/tests/Stubs/ActiveRecord/NoExist.php index d2c02c6ca..4f9d1c248 100644 --- a/tests/Stubs/ActiveRecord/NoExist.php +++ b/tests/Stubs/ActiveRecord/NoExist.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; final class NoExist extends ActiveRecord { diff --git a/tests/Stubs/ActiveRecord/NullValues.php b/tests/Stubs/ActiveRecord/NullValues.php index 13247c796..b33c9ca7b 100644 --- a/tests/Stubs/ActiveRecord/NullValues.php +++ b/tests/Stubs/ActiveRecord/NullValues.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; /** * Class NullValues. diff --git a/tests/Stubs/ActiveRecord/Order.php b/tests/Stubs/ActiveRecord/Order.php index ae3518977..beea8e89c 100644 --- a/tests/Stubs/ActiveRecord/Order.php +++ b/tests/Stubs/ActiveRecord/Order.php @@ -6,7 +6,7 @@ use Yiisoft\ActiveRecord\ActiveQuery; use Yiisoft\ActiveRecord\ActiveQueryInterface; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; use Yiisoft\ActiveRecord\Trait\CustomTableNameTrait; /** diff --git a/tests/Stubs/ActiveRecord/OrderItem.php b/tests/Stubs/ActiveRecord/OrderItem.php index 50c29633d..800c17e7f 100644 --- a/tests/Stubs/ActiveRecord/OrderItem.php +++ b/tests/Stubs/ActiveRecord/OrderItem.php @@ -6,7 +6,7 @@ use Yiisoft\ActiveRecord\ActiveQuery; use Yiisoft\ActiveRecord\ActiveQueryInterface; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; use Yiisoft\ActiveRecord\Trait\CustomTableNameTrait; /** @@ -26,20 +26,6 @@ public function getTableName(): string return $this->tableName ??= 'order_item'; } - public function fields(): array - { - $fields = parent::fields(); - - // Wrong fields. Should be without values. - $fields['order_id'] = $this->getAttribute('order_id'); - $fields['item_id'] = $this->getAttribute('item_id'); - $fields['price'] = $this->getAttribute('subtotal') / $this->getAttribute('quantity'); - $fields['quantity'] = $this->getAttribute('quantity'); - $fields['subtotal'] = $this->getAttribute('subtotal'); - - return $fields; - } - public function getOrderId(): int { return $this->order_id; diff --git a/tests/Stubs/ActiveRecord/OrderItemWithNullFK.php b/tests/Stubs/ActiveRecord/OrderItemWithNullFK.php index 6d13984ef..8dd104b33 100644 --- a/tests/Stubs/ActiveRecord/OrderItemWithNullFK.php +++ b/tests/Stubs/ActiveRecord/OrderItemWithNullFK.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; /** * Class OrderItem. diff --git a/tests/Stubs/ActiveRecord/OrderWithNullFK.php b/tests/Stubs/ActiveRecord/OrderWithNullFK.php index 4d36dd3a4..eea6b5495 100644 --- a/tests/Stubs/ActiveRecord/OrderWithNullFK.php +++ b/tests/Stubs/ActiveRecord/OrderWithNullFK.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; /** * Class Order. diff --git a/tests/Stubs/ActiveRecord/Profile.php b/tests/Stubs/ActiveRecord/Profile.php index 1a5f0bcb4..251fab816 100644 --- a/tests/Stubs/ActiveRecord/Profile.php +++ b/tests/Stubs/ActiveRecord/Profile.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; /** * Class Profile. diff --git a/tests/Stubs/ActiveRecord/ProfileWithConstructor.php b/tests/Stubs/ActiveRecord/ProfileWithConstructor.php index 64a6be799..2b52f57d3 100644 --- a/tests/Stubs/ActiveRecord/ProfileWithConstructor.php +++ b/tests/Stubs/ActiveRecord/ProfileWithConstructor.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; use Yiisoft\Aliases\Aliases; use Yiisoft\Db\Connection\ConnectionInterface; diff --git a/tests/Stubs/ActiveRecord/TestTrigger.php b/tests/Stubs/ActiveRecord/TestTrigger.php index cc9cc0dea..caee9c577 100644 --- a/tests/Stubs/ActiveRecord/TestTrigger.php +++ b/tests/Stubs/ActiveRecord/TestTrigger.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; /** * Class TestTrigger. diff --git a/tests/Stubs/ActiveRecord/TestTriggerAlert.php b/tests/Stubs/ActiveRecord/TestTriggerAlert.php index 1e62ebf03..96ffb6b34 100644 --- a/tests/Stubs/ActiveRecord/TestTriggerAlert.php +++ b/tests/Stubs/ActiveRecord/TestTriggerAlert.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; /** * Class TestTriggerAlert. diff --git a/tests/Stubs/ActiveRecord/Type.php b/tests/Stubs/ActiveRecord/Type.php index f146835aa..bcf8b44c8 100644 --- a/tests/Stubs/ActiveRecord/Type.php +++ b/tests/Stubs/ActiveRecord/Type.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; use Yiisoft\Db\Expression\Expression; /** diff --git a/tests/Stubs/ActiveRecord/UserAR.php b/tests/Stubs/ActiveRecord/UserAR.php index 08b72d5a6..9944cab58 100644 --- a/tests/Stubs/ActiveRecord/UserAR.php +++ b/tests/Stubs/ActiveRecord/UserAR.php @@ -4,7 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; -use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; +use Yiisoft\ActiveRecord\ActiveRecord; final class UserAR extends ActiveRecord { diff --git a/tests/Stubs/ArrayableActiveRecord.php b/tests/Stubs/ArrayableActiveRecord.php new file mode 100644 index 000000000..6f013d605 --- /dev/null +++ b/tests/Stubs/ArrayableActiveRecord.php @@ -0,0 +1,19 @@ + - * @template-implements IteratorAggregate - * - * @see ActiveRecord for more information. */ -class MagicActiveRecord extends ActiveRecord implements - ArrayableInterface, - ArrayAccess, - IteratorAggregate, - TransactionalInterface +class MagicActiveRecord extends ActiveRecord { - use ArrayableTrait; - use ArrayAccessTrait; - use ArrayIteratorTrait; use MagicPropertiesTrait; use MagicRelationsTrait; - use TransactionalTrait; } diff --git a/tests/Stubs/MagicActiveRecord/CustomerClosureField.php b/tests/Stubs/MagicActiveRecord/CustomerClosureField.php deleted file mode 100644 index b5d8f7ebc..000000000 --- a/tests/Stubs/MagicActiveRecord/CustomerClosureField.php +++ /dev/null @@ -1,33 +0,0 @@ - $customer->status === 1 ? 'active' : 'inactive'; - - return $fields; - } -} diff --git a/tests/Stubs/MagicActiveRecord/CustomerForArrayable.php b/tests/Stubs/MagicActiveRecord/CustomerForArrayable.php deleted file mode 100644 index 49d8d66e7..000000000 --- a/tests/Stubs/MagicActiveRecord/CustomerForArrayable.php +++ /dev/null @@ -1,57 +0,0 @@ -item = $item; - } - - public function setItems(self ...$items) - { - $this->items = $items; - } - - public function toArray(array $fields = [], array $expand = [], bool $recursive = true): array - { - $data = parent::toArray($fields, $expand, $recursive); - - $data['status'] = $this->status == 1 ? 'active' : 'inactive'; - - return $data; - } -}