-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test
ArrayableTrait
separately (#382)
- Loading branch information
Showing
48 changed files
with
317 additions
and
590 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' => '[email protected]', | ||
'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' => '[email protected]', | ||
'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' => '[email protected]', | ||
'name' => 'user1', | ||
'address' => 'address1', | ||
'status' => 'active', | ||
'item' => [ | ||
'id' => 2, | ||
'email' => '[email protected]', | ||
'name' => 'user2', | ||
'status' => 'active', | ||
], | ||
'items' => [ | ||
[ | ||
'id' => 3, | ||
'email' => '[email protected]', | ||
'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'); | ||
|
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,133 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\ActiveRecord\Tests; | ||
|
||
use Yiisoft\ActiveRecord\ActiveQuery; | ||
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Customer; | ||
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\CustomerClosureField; | ||
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\CustomerForArrayable; | ||
|
||
abstract class ArrayableTraitTest extends TestCase | ||
{ | ||
public function testFields(): void | ||
{ | ||
$this->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' => '[email protected]', | ||
'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' => '[email protected]', | ||
'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' => '[email protected]', | ||
'name' => 'user1', | ||
'address' => 'address1', | ||
'status' => 'active', | ||
'item' => [ | ||
'id' => 2, | ||
'email' => '[email protected]', | ||
'name' => 'user2', | ||
'status' => 'active', | ||
], | ||
'items' => [ | ||
[ | ||
'id' => 3, | ||
'email' => '[email protected]', | ||
'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', | ||
]), | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\ActiveRecord\Tests\Driver\Mssql; | ||
|
||
use Yiisoft\ActiveRecord\Tests\Support\MssqlHelper; | ||
use Yiisoft\Db\Connection\ConnectionInterface; | ||
|
||
final class ArrayableTraitTest extends \Yiisoft\ActiveRecord\Tests\ArrayableTraitTest | ||
{ | ||
protected function createConnection(): ConnectionInterface | ||
{ | ||
return (new MssqlHelper())->createConnection(); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\ActiveRecord\Tests\Driver\Mysql; | ||
|
||
use Yiisoft\ActiveRecord\Tests\Support\MysqlHelper; | ||
use Yiisoft\Db\Connection\ConnectionInterface; | ||
|
||
final class ArrayableTraitTest extends \Yiisoft\ActiveRecord\Tests\ArrayableTraitTest | ||
{ | ||
protected function createConnection(): ConnectionInterface | ||
{ | ||
return (new MysqlHelper())->createConnection(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -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' => '[email protected]', | ||
'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' => '[email protected]', | ||
'name' => 'user1', | ||
'address' => 'address1', | ||
'status' => 'active', | ||
'bool_status' => '1', | ||
'profile_id' => 1, | ||
], | ||
$customer->toArray(), | ||
); | ||
} | ||
} |
Oops, something went wrong.