diff --git a/tests/ActiveQueryFindTest.php b/tests/ActiveQueryFindTest.php index d501e996c..519cb4993 100644 --- a/tests/ActiveQueryFindTest.php +++ b/tests/ActiveQueryFindTest.php @@ -277,6 +277,7 @@ public function testFindAsArray(): void 'name' => 'user2', 'address' => 'address2', 'status' => 1, + 'bool_status' => true, 'profile_id' => null, ], $customer); diff --git a/tests/ActiveQueryTest.php b/tests/ActiveQueryTest.php index 46f0d828d..f58e1d495 100644 --- a/tests/ActiveQueryTest.php +++ b/tests/ActiveQueryTest.php @@ -2116,15 +2116,7 @@ public function testGetAttributes(): void $attributesExpected['name'] = 'user1'; $attributesExpected['address'] = 'address1'; $attributesExpected['status'] = 1; - - if ($this->db->getDriverName() === 'pgsql') { - $attributesExpected['bool_status'] = true; - } - - if ($this->db->getDriverName() === 'oci') { - $attributesExpected['bool_status'] = '1'; - } - + $attributesExpected['bool_status'] = true; $attributesExpected['profile_id'] = 1; $customer = new ActiveQuery(Customer::class, $this->db); @@ -2200,15 +2192,7 @@ public function testGetOldAttributes(): void $attributes['name'] = 'user1'; $attributes['address'] = 'address1'; $attributes['status'] = 1; - - if ($this->db->getDriverName() === 'pgsql') { - $attributes['bool_status'] = true; - } - - if ($this->db->getDriverName() === 'oci') { - $attributes['bool_status'] = '1'; - } - + $attributes['bool_status'] = true; $attributes['profile_id'] = 1; $customer = new ActiveQuery(Customer::class, $this->db); @@ -2223,15 +2207,7 @@ public function testGetOldAttributes(): void $attributesNew['name'] = 'samdark'; $attributesNew['address'] = 'address1'; $attributesNew['status'] = 1; - - if ($this->db->getDriverName() === 'pgsql') { - $attributesNew['bool_status'] = true; - } - - if ($this->db->getDriverName() === 'oci') { - $attributesNew['bool_status'] = '1'; - } - + $attributesNew['bool_status'] = true; $attributesNew['profile_id'] = 1; $this->assertEquals($attributesNew, $query->getAttributes()); diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php index 6b448abb1..53fd467e7 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -756,6 +756,7 @@ public function testToArray(): void 'name' => 'user1', 'address' => 'address1', 'status' => 1, + 'bool_status' => true, 'profile_id' => 1, ], $customer->toArray(), @@ -776,6 +777,7 @@ public function testToArrayWithClosure(): void 'name' => 'user1', 'address' => 'address1', 'status' => 'active', + 'bool_status' => true, 'profile_id' => 1, ], $customer->toArray(), @@ -883,6 +885,7 @@ public function testGetDirtyAttributesOnNewRecord(): void 'name' => null, 'address' => null, 'status' => 0, + 'bool_status' => false, 'profile_id' => null, ], $customer->getDirtyAttributes() @@ -900,6 +903,7 @@ public function testGetDirtyAttributesOnNewRecord(): void 'email' => 'adam@example.com', 'address' => null, 'status' => 0, + 'bool_status' => false, 'profile_id' => null, ], $customer->getDirtyAttributes() diff --git a/tests/Driver/Mysql/ActiveRecordTest.php b/tests/Driver/Mysql/ActiveRecordTest.php index 0b502d231..92972d7aa 100644 --- a/tests/Driver/Mysql/ActiveRecordTest.php +++ b/tests/Driver/Mysql/ActiveRecordTest.php @@ -5,6 +5,7 @@ namespace Yiisoft\ActiveRecord\Tests\Driver\Mysql; use Yiisoft\ActiveRecord\ActiveQuery; +use Yiisoft\ActiveRecord\Tests\Driver\Mysql\Stubs\Type; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Beta; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Customer; use Yiisoft\ActiveRecord\Tests\Support\MysqlHelper; @@ -28,6 +29,39 @@ protected function tearDown(): void unset($this->db); } + public function testCastValues(): void + { + $this->checkFixture($this->db, 'type'); + + $arClass = new Type($this->db); + + $arClass->int_col = 123; + $arClass->int_col2 = 456; + $arClass->smallint_col = 42; + $arClass->char_col = '1337'; + $arClass->char_col2 = 'test'; + $arClass->char_col3 = 'test123'; + $arClass->enum_col = 'B'; + $arClass->float_col = 3.742; + $arClass->float_col2 = 42.1337; + $arClass->bool_col = true; + $arClass->bool_col2 = false; + + $arClass->save(); + + /** @var $model Type */ + $aqClass = new ActiveQuery(Type::class, $this->db); + $query = $aqClass->onePopulate(); + + $this->assertSame(123, $query->int_col); + $this->assertSame(456, $query->int_col2); + $this->assertSame(42, $query->smallint_col); + $this->assertSame('1337', trim($query->char_col)); + $this->assertSame('test', $query->char_col2); + $this->assertSame('test123', $query->char_col3); + $this->assertSame('B', $query->enum_col); + } + public function testExplicitPkOnAutoIncrement(): void { $this->checkFixture($this->db, 'customer'); diff --git a/tests/Driver/Mysql/Stubs/Type.php b/tests/Driver/Mysql/Stubs/Type.php new file mode 100644 index 000000000..860da85e3 --- /dev/null +++ b/tests/Driver/Mysql/Stubs/Type.php @@ -0,0 +1,13 @@ +db); } + public function testFindLimit(): void + { + $this->checkFixture($this->db, 'customer', true); + + /** one */ + $customerQuery = new ActiveQuery(CustomerWithRownumid::class, $this->db); + $customer = $customerQuery->orderBy('id')->onePopulate(); + $this->assertEquals('user1', $customer->getName()); + + /** all */ + $customerQuery = new ActiveQuery(CustomerWithRownumid::class, $this->db); + $customers = $customerQuery->allPopulate(); + $this->assertCount(3, $customers); + + /** limit */ + $customerQuery = new ActiveQuery(CustomerWithRownumid::class, $this->db); + $customers = $customerQuery->orderBy('id')->limit(1)->allPopulate(); + $this->assertCount(1, $customers); + $this->assertEquals('user1', $customers[0]->getName()); + + $customers = $customerQuery->orderBy('id')->limit(1)->offset(1)->allPopulate(); + $this->assertCount(1, $customers); + $this->assertEquals('user2', $customers[0]->getName()); + + $customers = $customerQuery->orderBy('id')->limit(1)->offset(2)->allPopulate(); + $this->assertCount(1, $customers); + $this->assertEquals('user3', $customers[0]->getName()); + + $customers = $customerQuery->orderBy('id')->limit(2)->offset(1)->allPopulate(); + $this->assertCount(2, $customers); + $this->assertEquals('user2', $customers[0]->getName()); + $this->assertEquals('user3', $customers[1]->getName()); + + $customers = $customerQuery->limit(2)->offset(3)->allPopulate(); + $this->assertCount(0, $customers); + + /** offset */ + $customerQuery = new ActiveQuery(CustomerWithRownumid::class, $this->db); + $customer = $customerQuery->orderBy('id')->offset(0)->onePopulate(); + $this->assertEquals('user1', $customer->getName()); + + $customer = $customerQuery->orderBy('id')->offset(1)->onePopulate(); + $this->assertEquals('user2', $customer->getName()); + + $customer = $customerQuery->orderBy('id')->offset(2)->onePopulate(); + $this->assertEquals('user3', $customer->getName()); + + $customer = $customerQuery->offset(3)->onePopulate(); + $this->assertNull($customer); + } + public function testFindEager(): void { $this->checkFixture($this->db, 'customer', true); diff --git a/tests/Driver/Oracle/BatchQueryResultTest.php b/tests/Driver/Oracle/BatchQueryResultTest.php index 228e03698..6324c7dd6 100644 --- a/tests/Driver/Oracle/BatchQueryResultTest.php +++ b/tests/Driver/Oracle/BatchQueryResultTest.php @@ -4,6 +4,8 @@ namespace Yiisoft\ActiveRecord\Tests\Driver\Oracle; +use Yiisoft\ActiveRecord\ActiveQuery; +use Yiisoft\ActiveRecord\Tests\Driver\Oracle\Stubs\Customer; use Yiisoft\ActiveRecord\Tests\Support\OracleHelper; final class BatchQueryResultTest extends \Yiisoft\ActiveRecord\Tests\BatchQueryResultTest @@ -24,4 +26,20 @@ protected function tearDown(): void unset($this->db); } + + public function testBatchWithIndexBy(): void + { + $this->checkFixture($this->db, 'customer'); + + $customerQuery = new ActiveQuery(Customer::class, $this->db); + + $query = $customerQuery->orderBy('id')->limit(3)->indexBy('id'); + + $customers = $this->getAllRowsFromBatch($query->batch(2)); + + $this->assertCount(3, $customers); + $this->assertEquals('user1', $customers[0]->getName()); + $this->assertEquals('user2', $customers[1]->getName()); + $this->assertEquals('user3', $customers[2]->getName()); + } } diff --git a/tests/Driver/Oracle/MagicActiveRecordTest.php b/tests/Driver/Oracle/MagicActiveRecordTest.php index 0222f5fb7..c2c95fd59 100644 --- a/tests/Driver/Oracle/MagicActiveRecordTest.php +++ b/tests/Driver/Oracle/MagicActiveRecordTest.php @@ -5,7 +5,7 @@ namespace Yiisoft\ActiveRecord\Tests\Driver\Oracle; use Yiisoft\ActiveRecord\ActiveQuery; -use Yiisoft\ActiveRecord\Tests\Driver\Oracle\Stubs\Customer; +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; diff --git a/tests/Driver/Oracle/Stubs/Customer.php b/tests/Driver/Oracle/Stubs/Customer.php index e0d5916f5..e341e5f64 100644 --- a/tests/Driver/Oracle/Stubs/Customer.php +++ b/tests/Driver/Oracle/Stubs/Customer.php @@ -8,15 +8,11 @@ /** * Class Customer. - * - * @property int $id - * @property string $name - * @property string $email - * @property string $address - * @property int $status */ final class Customer extends \Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Customer { + protected string $ROWNUMID; + public function getOrdersQuery(): ActiveQuery { return $this->hasMany(Order::class, ['customer_id' => 'id'])->orderBy('{{customer}}.[[id]]'); diff --git a/tests/Driver/Oracle/Stubs/MagicCustomer.php b/tests/Driver/Oracle/Stubs/MagicCustomer.php new file mode 100644 index 000000000..5787ffad8 --- /dev/null +++ b/tests/Driver/Oracle/Stubs/MagicCustomer.php @@ -0,0 +1,24 @@ +hasMany(Order::class, ['customer_id' => 'id'])->orderBy('{{customer}}.[[id]]'); + } +} diff --git a/tests/Driver/Oracle/Stubs/MagicOrder.php b/tests/Driver/Oracle/Stubs/MagicOrder.php new file mode 100644 index 000000000..89d526c15 --- /dev/null +++ b/tests/Driver/Oracle/Stubs/MagicOrder.php @@ -0,0 +1,23 @@ +hasOne(MagicCustomer::class, ['id' => 'customer_id']); + } +} diff --git a/tests/Driver/Pgsql/ActiveRecordTest.php b/tests/Driver/Pgsql/ActiveRecordTest.php index 7402e3579..74707f18a 100644 --- a/tests/Driver/Pgsql/ActiveRecordTest.php +++ b/tests/Driver/Pgsql/ActiveRecordTest.php @@ -7,6 +7,7 @@ use ArrayAccess; use Traversable; use Yiisoft\ActiveRecord\ActiveQuery; +use Yiisoft\ActiveRecord\Tests\Driver\Pgsql\Stubs\Type; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\ArrayAndJsonTypes; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Beta; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\BoolAR; @@ -39,6 +40,65 @@ protected function tearDown(): void unset($this->db); } + public function testDefaultValues(): void + { + $this->checkFixture($this->db, 'type'); + + $arClass = new Type($this->db); + + $arClass->loadDefaultValues(); + + $this->assertEquals(1, $arClass->int_col2); + $this->assertEquals('something', $arClass->char_col2); + $this->assertEquals(1.23, $arClass->float_col2); + $this->assertEquals(33.22, $arClass->numeric_col); + $this->assertEquals(true, $arClass->bool_col2); + $this->assertEquals('2002-01-01 00:00:00', $arClass->time); + + $arClass = new Type($this->db); + $arClass->char_col2 = 'not something'; + + $arClass->loadDefaultValues(); + $this->assertEquals('not something', $arClass->char_col2); + + $arClass = new Type($this->db); + $arClass->char_col2 = 'not something'; + + $arClass->loadDefaultValues(false); + $this->assertEquals('something', $arClass->char_col2); + } + + public function testCastValues(): void + { + $this->checkFixture($this->db, 'type'); + + $arClass = new Type($this->db); + + $arClass->int_col = 123; + $arClass->int_col2 = 456; + $arClass->smallint_col = 42; + $arClass->char_col = '1337'; + $arClass->char_col2 = 'test'; + $arClass->char_col3 = 'test123'; + $arClass->float_col = 3.742; + $arClass->float_col2 = 42.1337; + $arClass->bool_col = true; + $arClass->bool_col2 = false; + + $arClass->save(); + + /** @var $model Type */ + $aqClass = new ActiveQuery(Type::class, $this->db); + $query = $aqClass->onePopulate(); + + $this->assertSame(123, $query->int_col); + $this->assertSame(456, $query->int_col2); + $this->assertSame(42, $query->smallint_col); + $this->assertSame('1337', trim($query->char_col)); + $this->assertSame('test', $query->char_col2); + $this->assertSame('test123', $query->char_col3); + } + public function testExplicitPkOnAutoIncrement(): void { $this->checkFixture($this->db, 'customer'); diff --git a/tests/Driver/Pgsql/Stubs/Type.php b/tests/Driver/Pgsql/Stubs/Type.php new file mode 100644 index 000000000..d0a8047b4 --- /dev/null +++ b/tests/Driver/Pgsql/Stubs/Type.php @@ -0,0 +1,17 @@ + 'user1', 'address' => 'address1', 'status' => 1, + 'bool_status' => true, 'profile_id' => 1, ], $customer->toArray(), @@ -769,6 +770,7 @@ public function testToArrayWithClosure(): void 'name' => 'user1', 'address' => 'address1', 'status' => 'active', + 'bool_status' => true, 'profile_id' => 1, ], $customer->toArray(), diff --git a/tests/Stubs/ActiveRecord/ArrayAndJsonTypes.php b/tests/Stubs/ActiveRecord/ArrayAndJsonTypes.php index 686fa3794..7cabbec11 100644 --- a/tests/Stubs/ActiveRecord/ArrayAndJsonTypes.php +++ b/tests/Stubs/ActiveRecord/ArrayAndJsonTypes.php @@ -5,7 +5,16 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; use Yiisoft\ActiveRecord\ActiveRecord; +use Yiisoft\Db\Expression\ArrayExpression; +use Yiisoft\Db\Expression\Expression; +use Yiisoft\Db\Expression\JsonExpression; final class ArrayAndJsonTypes extends ActiveRecord { + public int $id; + public array|ArrayExpression|null $intarray_col; + public array|ArrayExpression|null $textarray2_col; + public array|float|int|string|JsonExpression|null $json_col; + public array|float|int|string|JsonExpression|null $jsonb_col; + public array|ArrayExpression|Expression|null $jsonarray_col; } diff --git a/tests/Stubs/ActiveRecord/BitValues.php b/tests/Stubs/ActiveRecord/BitValues.php index d9fd60311..d13ae01b7 100644 --- a/tests/Stubs/ActiveRecord/BitValues.php +++ b/tests/Stubs/ActiveRecord/BitValues.php @@ -15,5 +15,5 @@ final class BitValues extends ActiveRecord { public int $id; - public bool $val; + public bool|int $val; } diff --git a/tests/Stubs/ActiveRecord/Customer.php b/tests/Stubs/ActiveRecord/Customer.php index 713ad9eb8..ef527fc36 100644 --- a/tests/Stubs/ActiveRecord/Customer.php +++ b/tests/Stubs/ActiveRecord/Customer.php @@ -10,14 +10,6 @@ /** * Class Customer. - * - * @property int $id - * @property string $name - * @property string $email - * @property string $address - * @property int $status - * - * @method CustomerQuery findBySql($sql, $params = []) static. */ class Customer extends ActiveRecord { @@ -29,6 +21,7 @@ class Customer extends ActiveRecord protected string|null $name = null; protected string|null $address = null; protected int|null $status = 0; + protected bool|string|null $bool_status = false; protected int|null $profile_id = null; /** @@ -89,6 +82,11 @@ public function getStatus(): int|null return $this->status; } + public function getBoolStatus(): bool|null + { + return $this->bool_status; + } + public function getProfileId(): int|null { return $this->profile_id; @@ -119,6 +117,11 @@ public function setStatus(int|null $status): void $this->status = $status; } + public function setBoolStatus(bool|null $bool_status): void + { + $this->bool_status = $bool_status; + } + public function setProfileId(int|null $profile_id): void { $this->setAttribute('profile_id', $profile_id); diff --git a/tests/Stubs/ActiveRecord/CustomerClosureField.php b/tests/Stubs/ActiveRecord/CustomerClosureField.php index 984766321..f53951de7 100644 --- a/tests/Stubs/ActiveRecord/CustomerClosureField.php +++ b/tests/Stubs/ActiveRecord/CustomerClosureField.php @@ -12,11 +12,12 @@ final class CustomerClosureField extends ActiveRecord { protected int $id; - protected string $name; protected string $email; - protected string $address; - protected int $status; - protected int|null $profile_id; + protected string|null $name = null; + protected string|null $address = null; + protected int|null $status = 0; + protected bool|string|null $bool_status = false; + protected int|null $profile_id = null; public function getTableName(): string { diff --git a/tests/Stubs/ActiveRecord/CustomerForArrayable.php b/tests/Stubs/ActiveRecord/CustomerForArrayable.php index 3a8c32fe0..3011e3ff1 100644 --- a/tests/Stubs/ActiveRecord/CustomerForArrayable.php +++ b/tests/Stubs/ActiveRecord/CustomerForArrayable.php @@ -16,11 +16,12 @@ class CustomerForArrayable extends ActiveRecord public ?CustomerForArrayable $item = null; protected int $id; - protected string $name; protected string $email; - protected string $address; - protected int $status; - protected int|null $profile_id; + protected string|null $name = null; + protected string|null $address = null; + protected int|null $status = 0; + protected bool|string|null $bool_status = false; + protected int|null $profile_id = null; public function getTableName(): string { diff --git a/tests/Stubs/ActiveRecord/CustomerWithAlias.php b/tests/Stubs/ActiveRecord/CustomerWithAlias.php index 4ba1fa18e..91e36afbc 100644 --- a/tests/Stubs/ActiveRecord/CustomerWithAlias.php +++ b/tests/Stubs/ActiveRecord/CustomerWithAlias.php @@ -20,11 +20,12 @@ final class CustomerWithAlias extends ActiveRecord public float $sumTotal; public int $id; - public string $name; public string $email; - public string $address; - public int $status; - public int|null $profile_id; + public string|null $name = null; + public string|null $address = null; + public int|null $status = null; + public bool|string|null $bool_status = null; + public int|null $profile_id = null; public function getTableName(): string { diff --git a/tests/Stubs/ActiveRecord/CustomerWithConstructor.php b/tests/Stubs/ActiveRecord/CustomerWithConstructor.php index 678f93c70..32baa4035 100644 --- a/tests/Stubs/ActiveRecord/CustomerWithConstructor.php +++ b/tests/Stubs/ActiveRecord/CustomerWithConstructor.php @@ -12,21 +12,16 @@ /** * CustomerWithConstructor. - * - * @property int $id - * @property string $name - * @property string $email - * @property string $address - * @property int $status */ final class CustomerWithConstructor extends ActiveRecord { protected int $id; - protected string $name; protected string $email; - protected string $address; - protected int $status; - protected int $profile_id; + protected string|null $name = null; + protected string|null $address = null; + protected int|null $status = 0; + protected bool|string|null $bool_status = false; + protected int|null $profile_id = null; public function __construct(ConnectionInterface $db, private Aliases $aliases) { diff --git a/tests/Stubs/ActiveRecord/Type.php b/tests/Stubs/ActiveRecord/Type.php index d2cb1ccf4..e16f02dcb 100644 --- a/tests/Stubs/ActiveRecord/Type.php +++ b/tests/Stubs/ActiveRecord/Type.php @@ -25,7 +25,7 @@ * @property bool $bool_col * @property bool|null $bool_col2 DEFAULT 1 */ -final class Type extends ActiveRecord +class Type extends ActiveRecord { public int $int_col; public int|null $int_col2 = 1; @@ -40,10 +40,10 @@ final class Type extends ActiveRecord public float|null $numeric_col = 33.22; public string $time = '2002-01-01 00:00:00'; public bool|int $bool_col; - public bool|int|null $bool_col2 = true; + public bool|int|string|null $bool_col2 = true; public string|Expression $ts_default; - public $bit_col = b'10000010'; - public array $json_col; + public int|string $bit_col = 0b1000_0010; + public array|null $json_col = null; public function getTableName(): string { diff --git a/tests/Stubs/ActiveRecord/UserAR.php b/tests/Stubs/ActiveRecord/UserAR.php index 1ab979966..9944cab58 100644 --- a/tests/Stubs/ActiveRecord/UserAR.php +++ b/tests/Stubs/ActiveRecord/UserAR.php @@ -12,6 +12,18 @@ final class UserAR extends ActiveRecord public const STATUS_ACTIVE = 10; public const ROLE_USER = 10; + public int $id; + public string $username; + public string $auth_key; + public string $password_hash; + public string|null $password_reset_token = null; + public string $email; + public int $role = 10; + public int $status = 10; + public int $created_at; + public int $updated_at; + public bool $is_deleted = false; + public function getTableName(): string { return '{{%bool_user}}'; diff --git a/tests/data/mssql.sql b/tests/data/mssql.sql index 84027d951..04e6ef417 100644 --- a/tests/data/mssql.sql +++ b/tests/data/mssql.sql @@ -42,6 +42,7 @@ CREATE TABLE [dbo].[customer] ( [name] [varchar](128), [address] [text], [status] [int] DEFAULT 0, + [bool_status] [bit] DEFAULT 0, [profile_id] [int], CONSTRAINT [PK_customer] PRIMARY KEY CLUSTERED ( [id] ASC @@ -214,9 +215,9 @@ INSERT INTO [dbo].[animal] (type) VALUES ('Yiisoft\ActiveRecord\Tests\Stubs\Acti INSERT INTO [dbo].[profile] ([description]) VALUES ('profile customer 1'); INSERT INTO [dbo].[profile] ([description]) VALUES ('profile customer 3'); -INSERT INTO [dbo].[customer] ([email], [name], [address], [status], [profile_id]) VALUES ('user1@example.com', 'user1', 'address1', 1, 1); -INSERT INTO [dbo].[customer] ([email], [name], [address], [status]) VALUES ('user2@example.com', 'user2', 'address2', 1); -INSERT INTO [dbo].[customer] ([email], [name], [address], [status], [profile_id]) VALUES ('user3@example.com', 'user3', 'address3', 2, 2); +INSERT INTO [dbo].[customer] ([email], [name], [address], [status], [bool_status], [profile_id]) VALUES ('user1@example.com', 'user1', 'address1', 1, 1, 1); +INSERT INTO [dbo].[customer] ([email], [name], [address], [status], [bool_status]) VALUES ('user2@example.com', 'user2', 'address2', 1, 1); +INSERT INTO [dbo].[customer] ([email], [name], [address], [status], [bool_status], [profile_id]) VALUES ('user3@example.com', 'user3', 'address3', 2, 0, 2); INSERT INTO [dbo].[category] ([name]) VALUES ('Books'); INSERT INTO [dbo].[category] ([name]) VALUES ('Movies'); diff --git a/tests/data/mysql.sql b/tests/data/mysql.sql index 08a1bf10e..f4a4b3848 100644 --- a/tests/data/mysql.sql +++ b/tests/data/mysql.sql @@ -20,19 +20,19 @@ DROP TABLE IF EXISTS `animal` CASCADE; DROP TABLE IF EXISTS `default_pk` CASCADE; DROP TABLE IF EXISTS `document` CASCADE; DROP TABLE IF EXISTS `comment` CASCADE; -DROP TABLE IF EXISTS `dossier`; -DROP TABLE IF EXISTS `employee`; -DROP TABLE IF EXISTS `department`; -DROP TABLE IF EXISTS `storage`; -DROP TABLE IF EXISTS `alpha`; -DROP TABLE IF EXISTS `beta`; -DROP VIEW IF EXISTS `animal_view`; +DROP TABLE IF EXISTS `dossier` CASCADE; +DROP TABLE IF EXISTS `employee` CASCADE; +DROP TABLE IF EXISTS `department` CASCADE; +DROP TABLE IF EXISTS `storage` CASCADE; +DROP TABLE IF EXISTS `alpha` CASCADE; +DROP TABLE IF EXISTS `beta` CASCADE; +DROP VIEW IF EXISTS `animal_view` CASCADE; DROP TABLE IF EXISTS `T_constraints_4` CASCADE; DROP TABLE IF EXISTS `T_constraints_3` CASCADE; DROP TABLE IF EXISTS `T_constraints_2` CASCADE; DROP TABLE IF EXISTS `T_constraints_1` CASCADE; DROP TABLE IF EXISTS `T_upsert` CASCADE; -DROP TABLE IF EXISTS `T_upsert_1`; +DROP TABLE IF EXISTS `T_upsert_1` CASCADE; CREATE TABLE `constraints` ( @@ -53,6 +53,7 @@ CREATE TABLE `customer` ( `name` varchar(128), `address` text, `status` int (11) DEFAULT 0, + `bool_status` bit(1) DEFAULT 0, `profile_id` int(11), PRIMARY KEY (`id`), CONSTRAINT `FK_customer_profile_id` FOREIGN KEY (`profile_id`) REFERENCES `profile` (`id`) @@ -232,9 +233,9 @@ INSERT INTO `animal` (`type`) VALUES ('Yiisoft\ActiveRecord\Tests\Stubs\ActiveRe INSERT INTO `profile` (description) VALUES ('profile customer 1'); INSERT INTO `profile` (description) VALUES ('profile customer 3'); -INSERT INTO `customer` (email, name, address, status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1); -INSERT INTO `customer` (email, name, address, status) VALUES ('user2@example.com', 'user2', 'address2', 1); -INSERT INTO `customer` (email, name, address, status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 2); +INSERT INTO `customer` (email, name, address, status, bool_status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1, 1); +INSERT INTO `customer` (email, name, address, status, bool_status) VALUES ('user2@example.com', 'user2', 'address2', 1, 1); +INSERT INTO `customer` (email, name, address, status, bool_status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 0, 2); INSERT INTO `category` (name) VALUES ('Books'); INSERT INTO `category` (name) VALUES ('Movies'); diff --git a/tests/data/pgsql.sql b/tests/data/pgsql.sql index e762e5a87..2ce4fe6b0 100644 --- a/tests/data/pgsql.sql +++ b/tests/data/pgsql.sql @@ -23,18 +23,18 @@ DROP TABLE IF EXISTS "animal" CASCADE; DROP TABLE IF EXISTS "default_pk" CASCADE; DROP TABLE IF EXISTS "document" CASCADE; DROP TABLE IF EXISTS "comment" CASCADE; -DROP TABLE IF EXISTS "dossier"; -DROP TABLE IF EXISTS "employee"; -DROP TABLE IF EXISTS "department"; -DROP TABLE IF EXISTS "alpha"; -DROP TABLE IF EXISTS "beta"; -DROP VIEW IF EXISTS "animal_view"; -DROP TABLE IF EXISTS "T_constraints_4"; -DROP TABLE IF EXISTS "T_constraints_3"; -DROP TABLE IF EXISTS "T_constraints_2"; -DROP TABLE IF EXISTS "T_constraints_1"; -DROP TABLE IF EXISTS "T_upsert"; -DROP TABLE IF EXISTS "T_upsert_1"; +DROP TABLE IF EXISTS "dossier" CASCADE; +DROP TABLE IF EXISTS "employee" CASCADE; +DROP TABLE IF EXISTS "department" CASCADE; +DROP TABLE IF EXISTS "alpha" CASCADE; +DROP TABLE IF EXISTS "beta" CASCADE; +DROP VIEW IF EXISTS "animal_view" CASCADE; +DROP TABLE IF EXISTS "T_constraints_4" CASCADE; +DROP TABLE IF EXISTS "T_constraints_3" CASCADE; +DROP TABLE IF EXISTS "T_constraints_2" CASCADE; +DROP TABLE IF EXISTS "T_constraints_1" CASCADE; +DROP TABLE IF EXISTS "T_upsert" CASCADE; +DROP TABLE IF EXISTS "T_upsert_1" CASCADE; DROP SCHEMA IF EXISTS "schema1" CASCADE; DROP SCHEMA IF EXISTS "schema2" CASCADE; diff --git a/tests/data/sqlite.sql b/tests/data/sqlite.sql index 017998b48..e10b97fa9 100644 --- a/tests/data/sqlite.sql +++ b/tests/data/sqlite.sql @@ -43,6 +43,7 @@ CREATE TABLE "customer" ( name varchar(128), address text, status INTEGER DEFAULT 0, + bool_status bool DEFAULT FALSE, profile_id INTEGER, PRIMARY KEY (id) ); @@ -196,9 +197,9 @@ INSERT INTO "animal" ("type") VALUES ('Yiisoft\ActiveRecord\Tests\Stubs\ActiveRe INSERT INTO "profile" (description) VALUES ('profile customer 1'); INSERT INTO "profile" (description) VALUES ('profile customer 3'); -INSERT INTO "customer" (email, name, address, status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1); -INSERT INTO "customer" (email, name, address, status) VALUES ('user2@example.com', 'user2', 'address2', 1); -INSERT INTO "customer" (email, name, address, status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 2); +INSERT INTO "customer" (email, name, address, status, bool_status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1, 1); +INSERT INTO "customer" (email, name, address, status, bool_status) VALUES ('user2@example.com', 'user2', 'address2', 1, 1); +INSERT INTO "customer" (email, name, address, status, bool_status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 0, 2); INSERT INTO "category" (name) VALUES ('Books'); INSERT INTO "category" (name) VALUES ('Movies');