From 6df20a0e7e3f1123c1a6d2e7bc346df85ee7fbd6 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Tue, 5 Jul 2016 19:59:14 +0200 Subject: [PATCH] adjusted test data to make existing relation tests fail some tests accidentally passed because they matched the primary key which is named `id` in all tables against similar primary key values. as soon as primary key values differ among tables, these tests are failing. reproduce #5341 on existing tests... --- tests/data/ar/Category.php | 2 +- tests/data/cubrid.sql | 54 +++---- tests/data/mssql.sql | 54 +++---- tests/data/mysql.sql | 60 ++++---- tests/data/oci.sql | 54 +++---- tests/data/postgres.sql | 54 +++---- tests/data/sqlite.sql | 54 +++---- tests/framework/ar/ActiveRecordTestTrait.php | 126 ++++++++++------- tests/framework/db/ActiveRecordTest.php | 204 +++++++++++++-------------- 9 files changed, 340 insertions(+), 322 deletions(-) diff --git a/tests/data/ar/Category.php b/tests/data/ar/Category.php index aa19326..26808de 100644 --- a/tests/data/ar/Category.php +++ b/tests/data/ar/Category.php @@ -28,7 +28,7 @@ class Category extends ActiveRecord public function getLimitedItems() { return $this->hasMany(Item::className(), ['category_id' => 'id']) - ->onCondition(['item.id' => [1, 2, 3]]); + ->onCondition(['item.id' => [21, 22, 23]]); } public function getOrderItems() diff --git a/tests/data/cubrid.sql b/tests/data/cubrid.sql index b0134c9..336228e 100644 --- a/tests/data/cubrid.sql +++ b/tests/data/cubrid.sql @@ -163,33 +163,33 @@ INSERT INTO "customer" (email, name, address, status, profile_id) VALUES ('user3 INSERT INTO "category" (name) VALUES ('Books'); INSERT INTO "category" (name) VALUES ('Movies'); -INSERT INTO "item" (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1); -INSERT INTO "item" (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1); -INSERT INTO "item" (name, category_id) VALUES ('Ice Age', 2); -INSERT INTO "item" (name, category_id) VALUES ('Toy Story', 2); -INSERT INTO "item" (name, category_id) VALUES ('Cars', 2); - -INSERT INTO "order" (customer_id, created_at, total) VALUES (1, 1325282384, 110.0); -INSERT INTO "order" (customer_id, created_at, total) VALUES (2, 1325334482, 33.0); -INSERT INTO "order" (customer_id, created_at, total) VALUES (2, 1325502201, 40.0); - -INSERT INTO "order_with_null_fk" (customer_id, created_at, total) VALUES (1, 1325282384, 110.0); -INSERT INTO "order_with_null_fk" (customer_id, created_at, total) VALUES (2, 1325334482, 33.0); -INSERT INTO "order_with_null_fk" (customer_id, created_at, total) VALUES (2, 1325502201, 40.0); - -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0); - -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0); +INSERT INTO "item" (id, name, category_id) VALUES (21, 'Agile Web Application Development with Yii1.1 and PHP5', 1); +INSERT INTO "item" (id, name, category_id) VALUES (22, 'Yii 1.1 Application Development Cookbook', 1); +INSERT INTO "item" (id, name, category_id) VALUES (23, 'Ice Age', 2); +INSERT INTO "item" (id, name, category_id) VALUES (24, 'Toy Story', 2); +INSERT INTO "item" (id, name, category_id) VALUES (25, 'Cars', 2); + +INSERT INTO "order" (id, customer_id, created_at, total) VALUES (11, 1, 1325282384, 110.0); +INSERT INTO "order" (id, customer_id, created_at, total) VALUES (12, 2, 1325334482, 33.0); +INSERT INTO "order" (id, customer_id, created_at, total) VALUES (13, 2, 1325502201, 40.0); + +INSERT INTO "order_with_null_fk" (id, customer_id, created_at, total) VALUES (11, 1, 1325282384, 110.0); +INSERT INTO "order_with_null_fk" (id, customer_id, created_at, total) VALUES (12, 2, 1325334482, 33.0); +INSERT INTO "order_with_null_fk" (id, customer_id, created_at, total) VALUES (13, 2, 1325502201, 40.0); + +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (11, 21, 1, 30.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (11, 22, 2, 40.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (12, 24, 1, 10.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (12, 25, 1, 15.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (12, 23, 1, 8.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (13, 22, 1, 40.0); + +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (11, 21, 1, 30.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (11, 22, 2, 40.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (12, 24, 1, 10.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (12, 25, 1, 15.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (12, 23, 1, 8.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (13, 22, 1, 40.0); INSERT INTO "document" (title, content, version) VALUES ('Yii 2.0 guide', 'This is Yii 2.0 guide', 0); diff --git a/tests/data/mssql.sql b/tests/data/mssql.sql index c4f3d27..37a2b4a 100644 --- a/tests/data/mssql.sql +++ b/tests/data/mssql.sql @@ -153,33 +153,33 @@ INSERT INTO [dbo].[customer] ([email], [name], [address], [status], [profile_id] INSERT INTO [dbo].[category] ([name]) VALUES ('Books'); INSERT INTO [dbo].[category] ([name]) VALUES ('Movies'); -INSERT INTO [dbo].[item] ([name], [category_id]) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1); -INSERT INTO [dbo].[item] ([name], [category_id]) VALUES ('Yii 1.1 Application Development Cookbook', 1); -INSERT INTO [dbo].[item] ([name], [category_id]) VALUES ('Ice Age', 2); -INSERT INTO [dbo].[item] ([name], [category_id]) VALUES ('Toy Story', 2); -INSERT INTO [dbo].[item] ([name], [category_id]) VALUES ('Cars', 2); - -INSERT INTO [dbo].[order] ([customer_id], [created_at], [total]) VALUES (1, 1325282384, 110.0); -INSERT INTO [dbo].[order] ([customer_id], [created_at], [total]) VALUES (2, 1325334482, 33.0); -INSERT INTO [dbo].[order] ([customer_id], [created_at], [total]) VALUES (2, 1325502201, 40.0); - -INSERT INTO [dbo].[order_with_null_fk] ([customer_id], [created_at], [total]) VALUES (1, 1325282384, 110.0); -INSERT INTO [dbo].[order_with_null_fk] ([customer_id], [created_at], [total]) VALUES (2, 1325334482, 33.0); -INSERT INTO [dbo].[order_with_null_fk] ([customer_id], [created_at], [total]) VALUES (2, 1325502201, 40.0); - -INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (1, 1, 1, 30.0); -INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (1, 2, 2, 40.0); -INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (2, 4, 1, 10.0); -INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (2, 5, 1, 15.0); -INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (2, 3, 1, 8.0); -INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (3, 2, 1, 40.0); - -INSERT INTO [dbo].[order_item_with_null_fk] ([order_id], [item_id], [quantity], [subtotal]) VALUES (1, 1, 1, 30.0); -INSERT INTO [dbo].[order_item_with_null_fk] ([order_id], [item_id], [quantity], [subtotal]) VALUES (1, 2, 2, 40.0); -INSERT INTO [dbo].[order_item_with_null_fk] ([order_id], [item_id], [quantity], [subtotal]) VALUES (2, 4, 1, 10.0); -INSERT INTO [dbo].[order_item_with_null_fk] ([order_id], [item_id], [quantity], [subtotal]) VALUES (2, 5, 1, 15.0); -INSERT INTO [dbo].[order_item_with_null_fk] ([order_id], [item_id], [quantity], [subtotal]) VALUES (2, 3, 1, 8.0); -INSERT INTO [dbo].[order_item_with_null_fk] ([order_id], [item_id], [quantity], [subtotal]) VALUES (3, 2, 1, 40.0); +INSERT INTO [dbo].[item] ([id], [name], [category_id]) VALUES (21, 'Agile Web Application Development with Yii1.1 and PHP5', 1); +INSERT INTO [dbo].[item] ([id], [name], [category_id]) VALUES (22, 'Yii 1.1 Application Development Cookbook', 1); +INSERT INTO [dbo].[item] ([id], [name], [category_id]) VALUES (23, 'Ice Age', 2); +INSERT INTO [dbo].[item] ([id], [name], [category_id]) VALUES (24, 'Toy Story', 2); +INSERT INTO [dbo].[item] ([id], [name], [category_id]) VALUES (25, 'Cars', 2); + +INSERT INTO [dbo].[order] ([id], [customer_id], [created_at], [total]) VALUES (11, 1, 1325282384, 110.0); +INSERT INTO [dbo].[order] ([id], [customer_id], [created_at], [total]) VALUES (12, 2, 1325334482, 33.0); +INSERT INTO [dbo].[order] ([id], [customer_id], [created_at], [total]) VALUES (13, 2, 1325502201, 40.0); + +INSERT INTO [dbo].[order_with_null_fk] ([id], [customer_id], [created_at], [total]) VALUES (11, 1, 1325282384, 110.0); +INSERT INTO [dbo].[order_with_null_fk] ([id], [customer_id], [created_at], [total]) VALUES (12, 2, 1325334482, 33.0); +INSERT INTO [dbo].[order_with_null_fk] ([id], [customer_id], [created_at], [total]) VALUES (13, 2, 1325502201, 40.0); + +INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (11, 21, 1, 30.0); +INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (11, 22, 2, 40.0); +INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (12, 24, 1, 10.0); +INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (12, 25, 1, 15.0); +INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (12, 23, 1, 8.0); +INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (13, 22, 1, 40.0); + +INSERT INTO [dbo].[order_item_with_null_fk] ([order_id], [item_id], [quantity], [subtotal]) VALUES (11, 21, 1, 30.0); +INSERT INTO [dbo].[order_item_with_null_fk] ([order_id], [item_id], [quantity], [subtotal]) VALUES (11, 22, 2, 40.0); +INSERT INTO [dbo].[order_item_with_null_fk] ([order_id], [item_id], [quantity], [subtotal]) VALUES (12, 24, 1, 10.0); +INSERT INTO [dbo].[order_item_with_null_fk] ([order_id], [item_id], [quantity], [subtotal]) VALUES (12, 25, 1, 15.0); +INSERT INTO [dbo].[order_item_with_null_fk] ([order_id], [item_id], [quantity], [subtotal]) VALUES (12, 23, 1, 8.0); +INSERT INTO [dbo].[order_item_with_null_fk] ([order_id], [item_id], [quantity], [subtotal]) VALUES (13, 22, 1, 40.0); INSERT INTO [dbo].[document] ([title], [content], [version]) VALUES ('Yii 2.0 guide', 'This is Yii 2.0 guide', 0); diff --git a/tests/data/mysql.sql b/tests/data/mysql.sql index 8bdc46d..3b0c493 100644 --- a/tests/data/mysql.sql +++ b/tests/data/mysql.sql @@ -167,40 +167,40 @@ INSERT INTO `animal` (`type`) VALUES ('yiiunit\data\ar\Dog'); 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` (id, email, name, address, status, profile_id) VALUES (1, 'user1@example.com', 'user1', 'address1', 1, 1); +INSERT INTO `customer` (id, email, name, address, status) VALUES (2, 'user2@example.com', 'user2', 'address2', 1); +INSERT INTO `customer` (id, email, name, address, status, profile_id) VALUES (3, 'user3@example.com', 'user3', 'address3', 2, 2); INSERT INTO `category` (name) VALUES ('Books'); INSERT INTO `category` (name) VALUES ('Movies'); -INSERT INTO `item` (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1); -INSERT INTO `item` (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1); -INSERT INTO `item` (name, category_id) VALUES ('Ice Age', 2); -INSERT INTO `item` (name, category_id) VALUES ('Toy Story', 2); -INSERT INTO `item` (name, category_id) VALUES ('Cars', 2); - -INSERT INTO `order` (customer_id, created_at, total) VALUES (1, 1325282384, 110.0); -INSERT INTO `order` (customer_id, created_at, total) VALUES (2, 1325334482, 33.0); -INSERT INTO `order` (customer_id, created_at, total) VALUES (2, 1325502201, 40.0); - -INSERT INTO `order_with_null_fk` (customer_id, created_at, total) VALUES (1, 1325282384, 110.0); -INSERT INTO `order_with_null_fk` (customer_id, created_at, total) VALUES (2, 1325334482, 33.0); -INSERT INTO `order_with_null_fk` (customer_id, created_at, total) VALUES (2, 1325502201, 40.0); - -INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0); -INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0); -INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0); -INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0); -INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0); -INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0); - -INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0); -INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0); -INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0); -INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0); -INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0); -INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0); +INSERT INTO `item` (id, name, category_id) VALUES (21, 'Agile Web Application Development with Yii1.1 and PHP5', 1); +INSERT INTO `item` (id, name, category_id) VALUES (22, 'Yii 1.1 Application Development Cookbook', 1); +INSERT INTO `item` (id, name, category_id) VALUES (23, 'Ice Age', 2); +INSERT INTO `item` (id, name, category_id) VALUES (24, 'Toy Story', 2); +INSERT INTO `item` (id, name, category_id) VALUES (25, 'Cars', 2); + +INSERT INTO `order` (id, customer_id, created_at, total) VALUES (11, 1, 1325282384, 110.0); +INSERT INTO `order` (id, customer_id, created_at, total) VALUES (12, 2, 1325334482, 33.0); +INSERT INTO `order` (id, customer_id, created_at, total) VALUES (13, 2, 1325502201, 40.0); + +INSERT INTO `order_with_null_fk` (id, customer_id, created_at, total) VALUES (11, 1, 1325282384, 110.0); +INSERT INTO `order_with_null_fk` (id, customer_id, created_at, total) VALUES (12, 2, 1325334482, 33.0); +INSERT INTO `order_with_null_fk` (id, customer_id, created_at, total) VALUES (13, 2, 1325502201, 40.0); + +INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (11, 21, 1, 30.0); +INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (11, 22, 2, 40.0); +INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (12, 24, 1, 10.0); +INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (12, 25, 1, 15.0); +INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (12, 23, 1, 8.0); +INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (13, 22, 1, 40.0); + +INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (11, 21, 1, 30.0); +INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (11, 22, 2, 40.0); +INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (12, 24, 1, 10.0); +INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (12, 25, 1, 15.0); +INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (12, 23, 1, 8.0); +INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (13, 22, 1, 40.0); INSERT INTO `document` (title, content, version) VALUES ('Yii 2.0 guide', 'This is Yii 2.0 guide', 0); diff --git a/tests/data/oci.sql b/tests/data/oci.sql index 43c4941..c439f00 100644 --- a/tests/data/oci.sql +++ b/tests/data/oci.sql @@ -263,33 +263,33 @@ INSERT INTO "customer" ("email", "name", "address", "status", "bool_status", "pr INSERT INTO "category" ("name") VALUES ('Books'); INSERT INTO "category" ("name") VALUES ('Movies'); -INSERT INTO "item" ("name", "category_id") VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1); -INSERT INTO "item" ("name", "category_id") VALUES ('Yii 1.1 Application Development Cookbook', 1); -INSERT INTO "item" ("name", "category_id") VALUES ('Ice Age', 2); -INSERT INTO "item" ("name", "category_id") VALUES ('Toy Story', 2); -INSERT INTO "item" ("name", "category_id") VALUES ('Cars', 2); - -INSERT INTO "order" ("customer_id", "created_at", "total") VALUES (1, 1325282384, 110.0); -INSERT INTO "order" ("customer_id", "created_at", "total") VALUES (2, 1325334482, 33.0); -INSERT INTO "order" ("customer_id", "created_at", "total") VALUES (2, 1325502201, 40.0); - -INSERT INTO "order_with_null_fk" ("customer_id", "created_at", "total") VALUES (1, 1325282384, 110.0); -INSERT INTO "order_with_null_fk" ("customer_id", "created_at", "total") VALUES (2, 1325334482, 33.0); -INSERT INTO "order_with_null_fk" ("customer_id", "created_at", "total") VALUES (2, 1325502201, 40.0); - -INSERT INTO "order_item" ("order_id", "item_id", "quantity", "subtotal") VALUES (1, 1, 1, 30.0); -INSERT INTO "order_item" ("order_id", "item_id", "quantity", "subtotal") VALUES (1, 2, 2, 40.0); -INSERT INTO "order_item" ("order_id", "item_id", "quantity", "subtotal") VALUES (2, 4, 1, 10.0); -INSERT INTO "order_item" ("order_id", "item_id", "quantity", "subtotal") VALUES (2, 5, 1, 15.0); -INSERT INTO "order_item" ("order_id", "item_id", "quantity", "subtotal") VALUES (2, 3, 1, 8.0); -INSERT INTO "order_item" ("order_id", "item_id", "quantity", "subtotal") VALUES (3, 2, 1, 40.0); - -INSERT INTO "order_item_with_null_fk" ("order_id", "item_id", "quantity", "subtotal") VALUES (1, 1, 1, 30.0); -INSERT INTO "order_item_with_null_fk" ("order_id", "item_id", "quantity", "subtotal") VALUES (1, 2, 2, 40.0); -INSERT INTO "order_item_with_null_fk" ("order_id", "item_id", "quantity", "subtotal") VALUES (2, 4, 1, 10.0); -INSERT INTO "order_item_with_null_fk" ("order_id", "item_id", "quantity", "subtotal") VALUES (2, 5, 1, 15.0); -INSERT INTO "order_item_with_null_fk" ("order_id", "item_id", "quantity", "subtotal") VALUES (2, 3, 1, 8.0); -INSERT INTO "order_item_with_null_fk" ("order_id", "item_id", "quantity", "subtotal") VALUES (3, 2, 1, 40.0); +INSERT INTO "item" ("id", "name", "category_id") VALUES (21, 'Agile Web Application Development with Yii1.1 and PHP5', 1); +INSERT INTO "item" ("id", "name", "category_id") VALUES (22, 'Yii 1.1 Application Development Cookbook', 1); +INSERT INTO "item" ("id", "name", "category_id") VALUES (23, 'Ice Age', 2); +INSERT INTO "item" ("id", "name", "category_id") VALUES (24, 'Toy Story', 2); +INSERT INTO "item" ("id", "name", "category_id") VALUES (25, 'Cars', 2); + +INSERT INTO "order" ("id", "customer_id", "created_at", "total") VALUES (11, 1, 1325282384, 110.0); +INSERT INTO "order" ("id", "customer_id", "created_at", "total") VALUES (12, 2, 1325334482, 33.0); +INSERT INTO "order" ("id", "customer_id", "created_at", "total") VALUES (13, 2, 1325502201, 40.0); + +INSERT INTO "order_with_null_fk" ("id", "customer_id", "created_at", "total") VALUES (11, 1, 1325282384, 110.0); +INSERT INTO "order_with_null_fk" ("id", "customer_id", "created_at", "total") VALUES (12, 2, 1325334482, 33.0); +INSERT INTO "order_with_null_fk" ("id", "customer_id", "created_at", "total") VALUES (13, 2, 1325502201, 40.0); + +INSERT INTO "order_item" ("order_id", "item_id", "quantity", "subtotal") VALUES (11, 21, 1, 30.0); +INSERT INTO "order_item" ("order_id", "item_id", "quantity", "subtotal") VALUES (11, 22, 2, 40.0); +INSERT INTO "order_item" ("order_id", "item_id", "quantity", "subtotal") VALUES (12, 24, 1, 10.0); +INSERT INTO "order_item" ("order_id", "item_id", "quantity", "subtotal") VALUES (12, 25, 1, 15.0); +INSERT INTO "order_item" ("order_id", "item_id", "quantity", "subtotal") VALUES (12, 23, 1, 8.0); +INSERT INTO "order_item" ("order_id", "item_id", "quantity", "subtotal") VALUES (13, 22, 1, 40.0); + +INSERT INTO "order_item_with_null_fk" ("order_id", "item_id", "quantity", "subtotal") VALUES (11, 21, 1, 30.0); +INSERT INTO "order_item_with_null_fk" ("order_id", "item_id", "quantity", "subtotal") VALUES (11, 22, 2, 40.0); +INSERT INTO "order_item_with_null_fk" ("order_id", "item_id", "quantity", "subtotal") VALUES (12, 24, 1, 10.0); +INSERT INTO "order_item_with_null_fk" ("order_id", "item_id", "quantity", "subtotal") VALUES (12, 25, 1, 15.0); +INSERT INTO "order_item_with_null_fk" ("order_id", "item_id", "quantity", "subtotal") VALUES (12, 23, 1, 8.0); +INSERT INTO "order_item_with_null_fk" ("order_id", "item_id", "quantity", "subtotal") VALUES (13, 22, 1, 40.0); INSERT INTO "document" ("title", "content", "version") VALUES ('Yii 2.0 guide', 'This is Yii 2.0 guide', 0); diff --git a/tests/data/postgres.sql b/tests/data/postgres.sql index a15adac..f59e38e 100644 --- a/tests/data/postgres.sql +++ b/tests/data/postgres.sql @@ -181,33 +181,33 @@ INSERT INTO "customer" (email, name, address, status, bool_status, profile_id) V INSERT INTO "category" (name) VALUES ('Books'); INSERT INTO "category" (name) VALUES ('Movies'); -INSERT INTO "item" (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1); -INSERT INTO "item" (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1); -INSERT INTO "item" (name, category_id) VALUES ('Ice Age', 2); -INSERT INTO "item" (name, category_id) VALUES ('Toy Story', 2); -INSERT INTO "item" (name, category_id) VALUES ('Cars', 2); - -INSERT INTO "order" (customer_id, created_at, total) VALUES (1, 1325282384, 110.0); -INSERT INTO "order" (customer_id, created_at, total) VALUES (2, 1325334482, 33.0); -INSERT INTO "order" (customer_id, created_at, total) VALUES (2, 1325502201, 40.0); - -INSERT INTO "order_with_null_fk" (customer_id, created_at, total) VALUES (1, 1325282384, 110.0); -INSERT INTO "order_with_null_fk" (customer_id, created_at, total) VALUES (2, 1325334482, 33.0); -INSERT INTO "order_with_null_fk" (customer_id, created_at, total) VALUES (2, 1325502201, 40.0); - -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0); - -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0); +INSERT INTO "item" (id, name, category_id) VALUES (21, 'Agile Web Application Development with Yii1.1 and PHP5', 1); +INSERT INTO "item" (id, name, category_id) VALUES (22, 'Yii 1.1 Application Development Cookbook', 1); +INSERT INTO "item" (id, name, category_id) VALUES (23, 'Ice Age', 2); +INSERT INTO "item" (id, name, category_id) VALUES (24, 'Toy Story', 2); +INSERT INTO "item" (id, name, category_id) VALUES (25, 'Cars', 2); + +INSERT INTO "order" (id, customer_id, created_at, total) VALUES (11, 1, 1325282384, 110.0); +INSERT INTO "order" (id, customer_id, created_at, total) VALUES (12, 2, 1325334482, 33.0); +INSERT INTO "order" (id, customer_id, created_at, total) VALUES (13, 2, 1325502201, 40.0); + +INSERT INTO "order_with_null_fk" (id, customer_id, created_at, total) VALUES (11, 1, 1325282384, 110.0); +INSERT INTO "order_with_null_fk" (id, customer_id, created_at, total) VALUES (12, 2, 1325334482, 33.0); +INSERT INTO "order_with_null_fk" (id, customer_id, created_at, total) VALUES (13, 2, 1325502201, 40.0); + +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (11, 21, 1, 30.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (11, 22, 2, 40.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (12, 24, 1, 10.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (12, 25, 1, 15.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (12, 23, 1, 8.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (13, 22, 1, 40.0); + +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (11, 21, 1, 30.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (11, 22, 2, 40.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (12, 24, 1, 10.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (12, 25, 1, 15.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (12, 23, 1, 8.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (13, 22, 1, 40.0); INSERT INTO "document" (title, content, version) VALUES ('Yii 2.0 guide', 'This is Yii 2.0 guide', 0); diff --git a/tests/data/sqlite.sql b/tests/data/sqlite.sql index fdcc199..c5e5b27 100644 --- a/tests/data/sqlite.sql +++ b/tests/data/sqlite.sql @@ -147,33 +147,33 @@ INSERT INTO "customer" (email, name, address, status, profile_id) VALUES ('user3 INSERT INTO "category" (name) VALUES ('Books'); INSERT INTO "category" (name) VALUES ('Movies'); -INSERT INTO "item" (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1); -INSERT INTO "item" (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1); -INSERT INTO "item" (name, category_id) VALUES ('Ice Age', 2); -INSERT INTO "item" (name, category_id) VALUES ('Toy Story', 2); -INSERT INTO "item" (name, category_id) VALUES ('Cars', 2); - -INSERT INTO "order" (customer_id, created_at, total) VALUES (1, 1325282384, 110.0); -INSERT INTO "order" (customer_id, created_at, total) VALUES (2, 1325334482, 33.0); -INSERT INTO "order" (customer_id, created_at, total) VALUES (2, 1325502201, 40.0); - -INSERT INTO "order_with_null_fk" (customer_id, created_at, total) VALUES (1, 1325282384, 110.0); -INSERT INTO "order_with_null_fk" (customer_id, created_at, total) VALUES (2, 1325334482, 33.0); -INSERT INTO "order_with_null_fk" (customer_id, created_at, total) VALUES (2, 1325502201, 40.0); - -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0); -INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0); - -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0); -INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0); +INSERT INTO "item" (id, name, category_id) VALUES (21, 'Agile Web Application Development with Yii1.1 and PHP5', 1); +INSERT INTO "item" (id, name, category_id) VALUES (22, 'Yii 1.1 Application Development Cookbook', 1); +INSERT INTO "item" (id, name, category_id) VALUES (23, 'Ice Age', 2); +INSERT INTO "item" (id, name, category_id) VALUES (24, 'Toy Story', 2); +INSERT INTO "item" (id, name, category_id) VALUES (25, 'Cars', 2); + +INSERT INTO "order" (id, customer_id, created_at, total) VALUES (11, 1, 1325282384, 110.0); +INSERT INTO "order" (id, customer_id, created_at, total) VALUES (12, 2, 1325334482, 33.0); +INSERT INTO "order" (id, customer_id, created_at, total) VALUES (13, 2, 1325502201, 40.0); + +INSERT INTO "order_with_null_fk" (id, customer_id, created_at, total) VALUES (11, 1, 1325282384, 110.0); +INSERT INTO "order_with_null_fk" (id, customer_id, created_at, total) VALUES (12, 2, 1325334482, 33.0); +INSERT INTO "order_with_null_fk" (id, customer_id, created_at, total) VALUES (13, 2, 1325502201, 40.0); + +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (11, 21, 1, 30.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (11, 22, 2, 40.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (12, 24, 1, 10.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (12, 25, 1, 15.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (12, 23, 1, 8.0); +INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (13, 22, 1, 40.0); + +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (11, 21, 1, 30.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (11, 22, 2, 40.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (12, 24, 1, 10.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (12, 25, 1, 15.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (12, 23, 1, 8.0); +INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (13, 22, 1, 40.0); INSERT INTO "document" (title, content, version) VALUES ('Yii 2.0 guide', 'This is Yii 2.0 guide', 0); diff --git a/tests/framework/ar/ActiveRecordTestTrait.php b/tests/framework/ar/ActiveRecordTestTrait.php index 7eaf4c5..3f9240d 100644 --- a/tests/framework/ar/ActiveRecordTestTrait.php +++ b/tests/framework/ar/ActiveRecordTestTrait.php @@ -275,7 +275,7 @@ trait ActiveRecordTestTrait $this->assertTrue($customerA->equals($customerB)); $customerA = $customerClass::findOne(1); - $customerB = $itemClass::findOne(1); + $customerB = $itemClass::findOne(21); $this->assertFalse($customerA->equals($customerB)); } @@ -415,12 +415,12 @@ trait ActiveRecordTestTrait /* @var $customer Customer */ $customer = $customerClass::findOne(2); $this->assertFalse($customer->isRelationPopulated('orders')); - $orders = $customer->getOrders()->where(['id' => 3])->all(); + $orders = $customer->getOrders()->where(['id' => 13])->all(); $this->assertFalse($customer->isRelationPopulated('orders')); $this->assertEquals(0, count($customer->relatedRecords)); $this->assertEquals(1, count($orders)); - $this->assertEquals(3, $orders[0]->id); + $this->assertEquals(13, $orders[0]->id); } public function testFindEager() @@ -467,11 +467,11 @@ trait ActiveRecordTestTrait /* @var $this TestCase|ActiveRecordTestTrait */ /* @var $order Order */ - $order = $orderClass::findOne(1); - $this->assertEquals(1, $order->id); + $order = $orderClass::findOne(11); + $this->assertEquals(11, $order->id); $this->assertEquals(2, count($order->items)); - $this->assertEquals(1, $order->items[0]->id); - $this->assertEquals(2, $order->items[1]->id); + $this->assertEquals(21, $order->items[0]->id); + $this->assertEquals(22, $order->items[1]->id); } public function testFindLazyVia2() @@ -481,7 +481,7 @@ trait ActiveRecordTestTrait /* @var $this TestCase|ActiveRecordTestTrait */ /* @var $order Order */ - $order = $orderClass::findOne(1); + $order = $orderClass::findOne(11); $order->id = 100; $this->assertEquals([], $order->items); } @@ -495,11 +495,11 @@ trait ActiveRecordTestTrait $orders = $orderClass::find()->with('items')->orderBy('id')->all(); $this->assertEquals(3, count($orders)); $order = $orders[0]; - $this->assertEquals(1, $order->id); + $this->assertEquals(11, $order->id); $this->assertTrue($order->isRelationPopulated('items')); $this->assertEquals(2, count($order->items)); - $this->assertEquals(1, $order->items[0]->id); - $this->assertEquals(2, $order->items[1]->id); + $this->assertEquals(21, $order->items[0]->id); + $this->assertEquals(22, $order->items[1]->id); } public function testFindNestedRelation() @@ -579,25 +579,25 @@ trait ActiveRecordTestTrait $this->assertEquals(3, count($orders)); $order = $orders[0]; - $this->assertEquals(1, $order->id); + $this->assertEquals(11, $order->id); $this->assertTrue($order->isRelationPopulated('itemsInOrder1')); $this->assertEquals(2, count($order->itemsInOrder1)); - $this->assertEquals(1, $order->itemsInOrder1[0]->id); - $this->assertEquals(2, $order->itemsInOrder1[1]->id); + $this->assertEquals(21, $order->itemsInOrder1[0]->id); + $this->assertEquals(22, $order->itemsInOrder1[1]->id); $order = $orders[1]; - $this->assertEquals(2, $order->id); + $this->assertEquals(12, $order->id); $this->assertTrue($order->isRelationPopulated('itemsInOrder1')); $this->assertEquals(3, count($order->itemsInOrder1)); - $this->assertEquals(5, $order->itemsInOrder1[0]->id); - $this->assertEquals(3, $order->itemsInOrder1[1]->id); - $this->assertEquals(4, $order->itemsInOrder1[2]->id); + $this->assertEquals(25, $order->itemsInOrder1[0]->id); + $this->assertEquals(23, $order->itemsInOrder1[1]->id); + $this->assertEquals(24, $order->itemsInOrder1[2]->id); $order = $orders[2]; - $this->assertEquals(3, $order->id); + $this->assertEquals(13, $order->id); $this->assertTrue($order->isRelationPopulated('itemsInOrder1')); $this->assertEquals(1, count($order->itemsInOrder1)); - $this->assertEquals(2, $order->itemsInOrder1[0]->id); + $this->assertEquals(22, $order->itemsInOrder1[0]->id); } // different order in via table @@ -610,25 +610,25 @@ trait ActiveRecordTestTrait $this->assertEquals(3, count($orders)); $order = $orders[0]; - $this->assertEquals(1, $order->id); + $this->assertEquals(11, $order->id); $this->assertTrue($order->isRelationPopulated('itemsInOrder2')); $this->assertEquals(2, count($order->itemsInOrder2)); - $this->assertEquals(1, $order->itemsInOrder2[0]->id); - $this->assertEquals(2, $order->itemsInOrder2[1]->id); + $this->assertEquals(21, $order->itemsInOrder2[0]->id); + $this->assertEquals(22, $order->itemsInOrder2[1]->id); $order = $orders[1]; - $this->assertEquals(2, $order->id); + $this->assertEquals(12, $order->id); $this->assertTrue($order->isRelationPopulated('itemsInOrder2')); $this->assertEquals(3, count($order->itemsInOrder2)); - $this->assertEquals(5, $order->itemsInOrder2[0]->id); - $this->assertEquals(3, $order->itemsInOrder2[1]->id); - $this->assertEquals(4, $order->itemsInOrder2[2]->id); + $this->assertEquals(25, $order->itemsInOrder2[0]->id); + $this->assertEquals(23, $order->itemsInOrder2[1]->id); + $this->assertEquals(24, $order->itemsInOrder2[2]->id); $order = $orders[2]; - $this->assertEquals(3, $order->id); + $this->assertEquals(13, $order->id); $this->assertTrue($order->isRelationPopulated('itemsInOrder2')); $this->assertEquals(1, count($order->itemsInOrder2)); - $this->assertEquals(2, $order->itemsInOrder2[0]->id); + $this->assertEquals(22, $order->itemsInOrder2[0]->id); } public function testLink() @@ -668,17 +668,17 @@ trait ActiveRecordTestTrait $this->assertEquals(1, $order->customer->primaryKey); // via model - $order = $orderClass::findOne(1); + $order = $orderClass::findOne(11); $this->assertEquals(2, count($order->items)); $this->assertEquals(2, count($order->orderItems)); $orderItem = $orderItemClass::findOne(['order_id' => 1, 'item_id' => 3]); $this->assertNull($orderItem); - $item = $itemClass::findOne(3); + $item = $itemClass::findOne(23); $order->link('items', $item, ['quantity' => 10, 'subtotal' => 100]); $this->afterSave(); $this->assertEquals(3, count($order->items)); $this->assertEquals(3, count($order->orderItems)); - $orderItem = $orderItemClass::findOne(['order_id' => 1, 'item_id' => 3]); + $orderItem = $orderItemClass::findOne(['order_id' => 11, 'item_id' => 23]); $this->assertTrue($orderItem instanceof $orderItemClass); $this->assertEquals(10, $orderItem->quantity); $this->assertEquals(100, $orderItem->subtotal); @@ -704,9 +704,9 @@ trait ActiveRecordTestTrait $customer->unlink('ordersWithNullFK', $customer->ordersWithNullFK[1], false); $this->assertEquals(1, count($customer->ordersWithNullFK)); - $orderWithNullFK = $orderWithNullFKClass::findOne(3); + $orderWithNullFK = $orderWithNullFKClass::findOne(13); - $this->assertEquals(3,$orderWithNullFK->id); + $this->assertEquals(13,$orderWithNullFK->id); $this->assertNull($orderWithNullFK->customer_id); // has many with delete @@ -716,10 +716,10 @@ trait ActiveRecordTestTrait $this->afterSave(); $this->assertEquals(1, count($customer->orders)); - $this->assertNull($orderClass::findOne(3)); + $this->assertNull($orderClass::findOne(13)); // via model with delete - $order = $orderClass::findOne(2); + $order = $orderClass::findOne(12); $this->assertEquals(3, count($order->items)); $this->assertEquals(3, count($order->orderItems)); $order->unlink('items', $order->items[2], true); @@ -762,8 +762,8 @@ trait ActiveRecordTestTrait $this->assertEquals(1, $orderClass::find()->count()); $this->assertEquals(0, count($customer->orders)); - $this->assertNull($orderClass::findOne(2)); - $this->assertNull($orderClass::findOne(3)); + $this->assertNull($orderClass::findOne(12)); + $this->assertNull($orderClass::findOne(13)); // has many without delete @@ -774,12 +774,12 @@ trait ActiveRecordTestTrait $this->afterSave(); $this->assertEquals(0, count($customer->ordersWithNullFK)); $this->assertEquals(3, $orderWithNullFKClass::find()->count()); - $this->assertEquals(2, $orderWithNullFKClass::find()->where(['AND', ['id' => [2, 3]], ['customer_id' => null]])->count()); + $this->assertEquals(2, $orderWithNullFKClass::find()->where(['AND', ['id' => [12, 13]], ['customer_id' => null]])->count()); // via model with delete /* @var $order Order */ - $order = $orderClass::findOne(1); + $order = $orderClass::findOne(11); $this->assertEquals(2, count($order->books)); $orderItemCount = $orderItemClass::find()->count(); $this->assertEquals(5, $itemClass::find()->count()); @@ -796,7 +796,7 @@ trait ActiveRecordTestTrait $order->unlinkAll('booksWithNullFK',false); $this->afterSave(); $this->assertEquals(0, count($order->booksWithNullFK)); - $this->assertEquals(2, $orderItemsWithNullFKClass::find()->where(['AND', ['item_id' => [1, 2]], ['order_id' => null]])->count()); + $this->assertEquals(2, $orderItemsWithNullFKClass::find()->where(['AND', ['item_id' => [21, 22]], ['order_id' => null]])->count()); $this->assertEquals($orderItemCount, $orderItemsWithNullFKClass::find()->count()); $this->assertEquals(5, $itemClass::find()->count()); @@ -985,7 +985,7 @@ trait ActiveRecordTestTrait $orderItemClass = $this->getOrderItemClass(); /* @var $this TestCase|ActiveRecordTestTrait */ // updateCounters - $pk = ['order_id' => 2, 'item_id' => 4]; + $pk = ['order_id' => 12, 'item_id' => 24]; $orderItem = $orderItemClass::findOne($pk); $this->assertEquals(1, $orderItem->quantity); $ret = $orderItem->updateCounters(['quantity' => -1]); @@ -996,7 +996,7 @@ trait ActiveRecordTestTrait $this->assertEquals(0, $orderItem->quantity); // updateAllCounters - $pk = ['order_id' => 1, 'item_id' => 2]; + $pk = ['order_id' => 11, 'item_id' => 22]; $orderItem = $orderItemClass::findOne($pk); $this->assertEquals(2, $orderItem->quantity); $ret = $orderItemClass::updateAllCounters([ @@ -1102,7 +1102,7 @@ trait ActiveRecordTestTrait $customer = $customerClass::find()->where(['id' => 1])->with('orders')->all(); $this->assertNotNull($customer); $this->assertEquals([ - [$this->getOrderClass(), false, 1, false], + [$this->getOrderClass(), false, 11, false], [$customerClass, false, 1, true], ], $afterFindCalls); $afterFindCalls = []; @@ -1115,9 +1115,9 @@ trait ActiveRecordTestTrait } $this->assertNotNull($customer); $this->assertEquals([ - [$orderClass, false, 1, false], - [$orderClass, false, 2, false], - [$orderClass, false, 3, false], + [$orderClass, false, 11, false], + [$orderClass, false, 12, false], + [$orderClass, false, 13, false], [$customerClass, false, 1, true], [$customerClass, false, 2, true], ], $afterFindCalls); @@ -1174,21 +1174,21 @@ trait ActiveRecordTestTrait $orderClass = $this->getOrderClass(); /* @var $order Order */ - $order = $orderClass::find()->with('itemsIndexed')->where(['id' => 1])->one(); + $order = $orderClass::find()->with('itemsIndexed')->where(['id' => 11])->one(); $this->assertTrue($order->isRelationPopulated('itemsIndexed')); $items = $order->itemsIndexed; $this->assertEquals(2, count($items)); - $this->assertTrue(isset($items[1])); - $this->assertTrue(isset($items[2])); + $this->assertTrue(isset($items[21])); + $this->assertTrue(isset($items[22])); /* @var $order Order */ - $order = $orderClass::find()->with('itemsIndexed')->where(['id' => 2])->one(); + $order = $orderClass::find()->with('itemsIndexed')->where(['id' => 12])->one(); $this->assertTrue($order->isRelationPopulated('itemsIndexed')); $items = $order->itemsIndexed; $this->assertEquals(3, count($items)); - $this->assertTrue(isset($items[3])); - $this->assertTrue(isset($items[4])); - $this->assertTrue(isset($items[5])); + $this->assertTrue(isset($items[23])); + $this->assertTrue(isset($items[24])); + $this->assertTrue(isset($items[25])); } public function testEagerLoadingWithViaRelation() @@ -1197,6 +1197,24 @@ trait ActiveRecordTestTrait /* @var $customerClass \yii\db\ActiveRecordInterface */ $customerClass = $this->getCustomerClass(); + + // two level deep + // customer -> orders -> order_items + + /** @var $customer \yii\db\ActiveRecord $customer */ + $customer = $customerClass::find()->where(['id' => 1])->with(['orderItems2'])->one(); + $this->assertTrue($customer->isRelationPopulated('orderItems2')); + + // three level deep + // customer -> orders -> order_items -> items + + /** @var $customer \yii\db\ActiveRecord $customer */ + $customer = $customerClass::find()->where(['id' => 1])->with(['items'])->one(); + $this->assertTrue($customer->isRelationPopulated('items')); + + // four level deep + // customer -> orders -> order_items -> items -> categories + /** @var $customer \yii\db\ActiveRecord $customer */ $customer = $customerClass::find()->where(['id' => 1])->with(['categories'])->one(); $this->assertTrue($customer->isRelationPopulated('categories')); diff --git a/tests/framework/db/ActiveRecordTest.php b/tests/framework/db/ActiveRecordTest.php index b1d5780..1d93f68 100644 --- a/tests/framework/db/ActiveRecordTest.php +++ b/tests/framework/db/ActiveRecordTest.php @@ -142,17 +142,17 @@ abstract class ActiveRecordTest extends DatabaseTestCase public function testFindLazyViaTable() { /* @var $order Order */ - $order = Order::findOne(1); - $this->assertEquals(1, $order->id); + $order = Order::findOne(11); + $this->assertEquals(11, $order->id); $this->assertEquals(2, count($order->books)); - $this->assertEquals(1, $order->items[0]->id); - $this->assertEquals(2, $order->items[1]->id); + $this->assertEquals(21, $order->items[0]->id); + $this->assertEquals(22, $order->items[1]->id); - $order = Order::findOne(2); - $this->assertEquals(2, $order->id); + $order = Order::findOne(12); + $this->assertEquals(12, $order->id); $this->assertEquals(0, count($order->books)); - $order = Order::find()->where(['id' => 1])->asArray()->one(); + $order = Order::find()->where(['id' => 11])->asArray()->one(); $this->assertTrue(is_array($order)); } @@ -162,19 +162,19 @@ abstract class ActiveRecordTest extends DatabaseTestCase $this->assertEquals(3, count($orders)); $order = $orders[0]; - $this->assertEquals(1, $order->id); + $this->assertEquals(11, $order->id); $this->assertEquals(2, count($order->books)); - $this->assertEquals(1, $order->books[0]->id); - $this->assertEquals(2, $order->books[1]->id); + $this->assertEquals(21, $order->books[0]->id); + $this->assertEquals(22, $order->books[1]->id); $order = $orders[1]; - $this->assertEquals(2, $order->id); + $this->assertEquals(12, $order->id); $this->assertEquals(0, count($order->books)); $order = $orders[2]; - $this->assertEquals(3, $order->id); + $this->assertEquals(13, $order->id); $this->assertEquals(1, count($order->books)); - $this->assertEquals(2, $order->books[0]->id); + $this->assertEquals(22, $order->books[0]->id); // https://github.com/yiisoft/yii2/issues/1402 $orders = Order::find()->with('books')->orderBy('id')->asArray()->all(); @@ -183,10 +183,10 @@ abstract class ActiveRecordTest extends DatabaseTestCase $order = $orders[0]; $this->assertTrue(is_array($order)); - $this->assertEquals(1, $order['id']); + $this->assertEquals(11, $order['id']); $this->assertEquals(2, count($order['books'])); - $this->assertEquals(1, $order['books'][0]['id']); - $this->assertEquals(2, $order['books'][1]['id']); + $this->assertEquals(21, $order['books'][0]['id']); + $this->assertEquals(22, $order['books'][1]['id']); } // deeply nested table relation @@ -201,8 +201,8 @@ abstract class ActiveRecordTest extends DatabaseTestCase $this->assertEquals(2, count($items)); $this->assertInstanceOf(Item::className(), $items[0]); $this->assertInstanceOf(Item::className(), $items[1]); - $this->assertEquals(1, $items[0]->id); - $this->assertEquals(2, $items[1]->id); + $this->assertEquals(21, $items[0]->id); + $this->assertEquals(22, $items[1]->id); } /** @@ -222,14 +222,14 @@ abstract class ActiveRecordTest extends DatabaseTestCase $this->assertInstanceOf(Order::className(), $orders[1]); $ids = [$orders[0]->id, $orders[1]->id]; sort($ids); - $this->assertEquals([1, 3], $ids); + $this->assertEquals([11, 13], $ids); $category = Category::findOne(2); $this->assertNotNull($category); $orders = $category->orders; $this->assertEquals(1, count($orders)); $this->assertInstanceOf(Order::className(), $orders[0]); - $this->assertEquals(2, $orders[0]->id); + $this->assertEquals(12, $orders[0]->id); } @@ -321,9 +321,9 @@ abstract class ActiveRecordTest extends DatabaseTestCase // left join and eager loading $orders = Order::find()->joinWith('customer')->orderBy('customer.id DESC, order.id')->all(); $this->assertEquals(3, count($orders)); - $this->assertEquals(2, $orders[0]->id); - $this->assertEquals(3, $orders[1]->id); - $this->assertEquals(1, $orders[2]->id); + $this->assertEquals(12, $orders[0]->id); + $this->assertEquals(13, $orders[1]->id); + $this->assertEquals(11, $orders[2]->id); $this->assertTrue($orders[0]->isRelationPopulated('customer')); $this->assertTrue($orders[1]->isRelationPopulated('customer')); $this->assertTrue($orders[2]->isRelationPopulated('customer')); @@ -335,8 +335,8 @@ abstract class ActiveRecordTest extends DatabaseTestCase }, ])->orderBy('order.id')->all(); $this->assertEquals(2, count($orders)); - $this->assertEquals(2, $orders[0]->id); - $this->assertEquals(3, $orders[1]->id); + $this->assertEquals(12, $orders[0]->id); + $this->assertEquals(13, $orders[1]->id); $this->assertTrue($orders[0]->isRelationPopulated('customer')); $this->assertTrue($orders[1]->isRelationPopulated('customer')); @@ -345,9 +345,9 @@ abstract class ActiveRecordTest extends DatabaseTestCase 'customer' => function ($query) { $query->where(['customer.id' => 2]); }, - ])->where(['order.id' => [1, 2]])->orderBy('order.id')->all(); + ])->where(['order.id' => [11, 12]])->orderBy('order.id')->all(); $this->assertEquals(1, count($orders)); - $this->assertEquals(2, $orders[0]->id); + $this->assertEquals(12, $orders[0]->id); $this->assertTrue($orders[0]->isRelationPopulated('customer')); // inner join filtering without eager loading @@ -357,8 +357,8 @@ abstract class ActiveRecordTest extends DatabaseTestCase }, ], false)->orderBy('order.id')->all(); $this->assertEquals(2, count($orders)); - $this->assertEquals(2, $orders[0]->id); - $this->assertEquals(3, $orders[1]->id); + $this->assertEquals(12, $orders[0]->id); + $this->assertEquals(13, $orders[1]->id); $this->assertFalse($orders[0]->isRelationPopulated('customer')); $this->assertFalse($orders[1]->isRelationPopulated('customer')); @@ -367,16 +367,16 @@ abstract class ActiveRecordTest extends DatabaseTestCase 'customer' => function ($query) { $query->where(['customer.id' => 2]); }, - ], false)->where(['order.id' => [1, 2]])->orderBy('order.id')->all(); + ], false)->where(['order.id' => [11, 12]])->orderBy('order.id')->all(); $this->assertEquals(1, count($orders)); - $this->assertEquals(2, $orders[0]->id); + $this->assertEquals(12, $orders[0]->id); $this->assertFalse($orders[0]->isRelationPopulated('customer')); // join with via-relation $orders = Order::find()->innerJoinWith('books')->orderBy('order.id')->all(); $this->assertEquals(2, count($orders)); - $this->assertEquals(1, $orders[0]->id); - $this->assertEquals(3, $orders[1]->id); + $this->assertEquals(11, $orders[0]->id); + $this->assertEquals(13, $orders[1]->id); $this->assertTrue($orders[0]->isRelationPopulated('books')); $this->assertTrue($orders[1]->isRelationPopulated('books')); $this->assertEquals(2, count($orders[0]->books)); @@ -393,7 +393,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase ])->orderBy('order.id')->all(); $this->assertEquals(1, count($orders)); $this->assertTrue($orders[0]->isRelationPopulated('items')); - $this->assertEquals(2, $orders[0]->id); + $this->assertEquals(12, $orders[0]->id); $this->assertEquals(3, count($orders[0]->items)); $this->assertTrue($orders[0]->items[0]->isRelationPopulated('category')); $this->assertEquals(2, $orders[0]->items[0]->category->id); @@ -405,9 +405,9 @@ abstract class ActiveRecordTest extends DatabaseTestCase } ])->orderBy('c.id DESC, order.id')->all(); $this->assertEquals(3, count($orders)); - $this->assertEquals(2, $orders[0]->id); - $this->assertEquals(3, $orders[1]->id); - $this->assertEquals(1, $orders[2]->id); + $this->assertEquals(12, $orders[0]->id); + $this->assertEquals(13, $orders[1]->id); + $this->assertEquals(11, $orders[2]->id); $this->assertTrue($orders[0]->isRelationPopulated('customer')); $this->assertTrue($orders[1]->isRelationPopulated('customer')); $this->assertTrue($orders[2]->isRelationPopulated('customer')); @@ -415,9 +415,9 @@ abstract class ActiveRecordTest extends DatabaseTestCase // join with table alias $orders = Order::find()->joinWith('customer as c')->orderBy('c.id DESC, order.id')->all(); $this->assertEquals(3, count($orders)); - $this->assertEquals(2, $orders[0]->id); - $this->assertEquals(3, $orders[1]->id); - $this->assertEquals(1, $orders[2]->id); + $this->assertEquals(12, $orders[0]->id); + $this->assertEquals(13, $orders[1]->id); + $this->assertEquals(11, $orders[2]->id); $this->assertTrue($orders[0]->isRelationPopulated('customer')); $this->assertTrue($orders[1]->isRelationPopulated('customer')); $this->assertTrue($orders[2]->isRelationPopulated('customer')); @@ -433,7 +433,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase ])->orderBy('order.id')->all(); $this->assertEquals(1, count($orders)); $this->assertTrue($orders[0]->isRelationPopulated('items')); - $this->assertEquals(2, $orders[0]->id); + $this->assertEquals(12, $orders[0]->id); $this->assertEquals(3, count($orders[0]->items)); $this->assertTrue($orders[0]->items[0]->isRelationPopulated('category')); $this->assertEquals(2, $orders[0]->items[0]->category->id); @@ -441,9 +441,9 @@ abstract class ActiveRecordTest extends DatabaseTestCase // join with ON condition $orders = Order::find()->joinWith('books2')->orderBy('order.id')->all(); $this->assertEquals(3, count($orders)); - $this->assertEquals(1, $orders[0]->id); - $this->assertEquals(2, $orders[1]->id); - $this->assertEquals(3, $orders[2]->id); + $this->assertEquals(11, $orders[0]->id); + $this->assertEquals(12, $orders[1]->id); + $this->assertEquals(13, $orders[2]->id); $this->assertTrue($orders[0]->isRelationPopulated('books2')); $this->assertTrue($orders[1]->isRelationPopulated('books2')); $this->assertTrue($orders[2]->isRelationPopulated('books2')); @@ -452,19 +452,19 @@ abstract class ActiveRecordTest extends DatabaseTestCase $this->assertEquals(1, count($orders[2]->books2)); // lazy loading with ON condition - $order = Order::findOne(1); + $order = Order::findOne(11); $this->assertEquals(2, count($order->books2)); - $order = Order::findOne(2); + $order = Order::findOne(12); $this->assertEquals(0, count($order->books2)); - $order = Order::findOne(3); + $order = Order::findOne(13); $this->assertEquals(1, count($order->books2)); // eager loading with ON condition $orders = Order::find()->with('books2')->all(); $this->assertEquals(3, count($orders)); - $this->assertEquals(1, $orders[0]->id); - $this->assertEquals(2, $orders[1]->id); - $this->assertEquals(3, $orders[2]->id); + $this->assertEquals(11, $orders[0]->id); + $this->assertEquals(12, $orders[1]->id); + $this->assertEquals(13, $orders[2]->id); $this->assertTrue($orders[0]->isRelationPopulated('books2')); $this->assertTrue($orders[1]->isRelationPopulated('books2')); $this->assertTrue($orders[2]->isRelationPopulated('books2')); @@ -480,7 +480,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase $this->assertEquals(3, count($orders)); // https://github.com/yiisoft/yii2/issues/2880 - $query = Order::findOne(1); + $query = Order::findOne(11); $customer = $query->getCustomer()->joinWith([ 'orders' => function ($q) { $q->orderBy([]); } ])->one(); @@ -505,7 +505,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase ])->orderBy('order.id')->all(); $this->assertEquals(1, count($orders)); $this->assertTrue($orders[0]->isRelationPopulated('items')); - $this->assertEquals(2, $orders[0]->id); + $this->assertEquals(12, $orders[0]->id); $this->assertEquals(3, count($orders[0]->items)); $this->assertTrue($orders[0]->items[0]->isRelationPopulated('category')); $this->assertEquals(2, $orders[0]->items[0]->category->id); @@ -584,9 +584,9 @@ abstract class ActiveRecordTest extends DatabaseTestCase $orders = $query->orderBy($query->applyAlias('customer', 'id') . ' DESC,' . $query->applyAlias('order', 'id'))->all(); } $this->assertEquals(3, count($orders)); - $this->assertEquals(2, $orders[0]->id); - $this->assertEquals(3, $orders[1]->id); - $this->assertEquals(1, $orders[2]->id); + $this->assertEquals(12, $orders[0]->id); + $this->assertEquals(13, $orders[1]->id); + $this->assertEquals(11, $orders[2]->id); $this->assertTrue($orders[0]->isRelationPopulated('customer')); $this->assertTrue($orders[1]->isRelationPopulated('customer')); $this->assertTrue($orders[2]->isRelationPopulated('customer')); @@ -601,8 +601,8 @@ abstract class ActiveRecordTest extends DatabaseTestCase $orders = $query->where([$query->applyAlias('customer', 'id') => 2])->orderBy($query->applyAlias('order', 'id'))->all(); } $this->assertEquals(2, count($orders)); - $this->assertEquals(2, $orders[0]->id); - $this->assertEquals(3, $orders[1]->id); + $this->assertEquals(12, $orders[0]->id); + $this->assertEquals(13, $orders[1]->id); $this->assertTrue($orders[0]->isRelationPopulated('customer')); $this->assertTrue($orders[1]->isRelationPopulated('customer')); @@ -616,8 +616,8 @@ abstract class ActiveRecordTest extends DatabaseTestCase $orders = $query->where([$query->applyAlias('customer', 'id') => 2])->orderBy($query->applyAlias('order', 'id'))->all(); } $this->assertEquals(2, count($orders)); - $this->assertEquals(2, $orders[0]->id); - $this->assertEquals(3, $orders[1]->id); + $this->assertEquals(12, $orders[0]->id); + $this->assertEquals(13, $orders[1]->id); $this->assertFalse($orders[0]->isRelationPopulated('customer')); $this->assertFalse($orders[1]->isRelationPopulated('customer')); @@ -631,8 +631,8 @@ abstract class ActiveRecordTest extends DatabaseTestCase $orders = $query->where([$query->applyAlias('book', 'name') => 'Yii 1.1 Application Development Cookbook'])->orderBy($query->applyAlias('order', 'id'))->all(); } $this->assertEquals(2, count($orders)); - $this->assertEquals(1, $orders[0]->id); - $this->assertEquals(3, $orders[1]->id); + $this->assertEquals(11, $orders[0]->id); + $this->assertEquals(13, $orders[1]->id); $this->assertTrue($orders[0]->isRelationPopulated('books')); $this->assertTrue($orders[1]->isRelationPopulated('books')); $this->assertEquals(2, count($orders[0]->books)); @@ -671,7 +671,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase } $this->assertEquals(1, count($orders)); $this->assertTrue($orders[0]->isRelationPopulated('items')); - $this->assertEquals(2, $orders[0]->id); + $this->assertEquals(12, $orders[0]->id); $this->assertEquals(3, count($orders[0]->items)); $this->assertTrue($orders[0]->items[0]->isRelationPopulated('category')); $this->assertEquals(2, $orders[0]->items[0]->category->id); @@ -681,9 +681,9 @@ abstract class ActiveRecordTest extends DatabaseTestCase $relationName = 'books' . ucfirst($aliasMethod); $orders = Order::find()->joinWith(["$relationName b"])->orderBy('order.id')->all(); $this->assertEquals(3, count($orders)); - $this->assertEquals(1, $orders[0]->id); - $this->assertEquals(2, $orders[1]->id); - $this->assertEquals(3, $orders[2]->id); + $this->assertEquals(11, $orders[0]->id); + $this->assertEquals(12, $orders[1]->id); + $this->assertEquals(13, $orders[2]->id); $this->assertTrue($orders[0]->isRelationPopulated($relationName)); $this->assertTrue($orders[1]->isRelationPopulated($relationName)); $this->assertTrue($orders[2]->isRelationPopulated($relationName)); @@ -697,9 +697,9 @@ abstract class ActiveRecordTest extends DatabaseTestCase $relationName = 'books' . ucfirst($aliasMethod) . 'A'; $orders = Order::find()->joinWith(["$relationName"])->orderBy('order.id')->all(); $this->assertEquals(3, count($orders)); - $this->assertEquals(1, $orders[0]->id); - $this->assertEquals(2, $orders[1]->id); - $this->assertEquals(3, $orders[2]->id); + $this->assertEquals(11, $orders[0]->id); + $this->assertEquals(12, $orders[1]->id); + $this->assertEquals(13, $orders[2]->id); $this->assertTrue($orders[0]->isRelationPopulated($relationName)); $this->assertTrue($orders[1]->isRelationPopulated($relationName)); $this->assertTrue($orders[2]->isRelationPopulated($relationName)); @@ -724,14 +724,14 @@ abstract class ActiveRecordTest extends DatabaseTestCase // relational query /** @var $order Order */ - $order = Order::findOne(1); + $order = Order::findOne(11); $customerQuery = $order->getCustomer()->innerJoinWith(['orders o'], false); if ($aliasMethod === 'explicit') { - $customer = $customerQuery->where(['o.id' => 1])->one(); + $customer = $customerQuery->where(['o.id' => 11])->one(); } elseif ($aliasMethod === 'querysyntax') { - $customer = $customerQuery->where(['{{@order}}.id' => 1])->one(); + $customer = $customerQuery->where(['{{@order}}.id' => 11])->one(); } elseif ($aliasMethod === 'applyAlias') { - $customer = $customerQuery->where([$query->applyAlias('order', 'id') => 1])->one(); + $customer = $customerQuery->where([$query->applyAlias('order', 'id') => 11])->one(); } $this->assertNotNull($customer); $this->assertEquals(1, $customer->id); @@ -753,7 +753,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase ])->orderBy('order.id')->all(); $this->assertEquals(1, count($orders)); $this->assertTrue($orders[0]->isRelationPopulated('items')); - $this->assertEquals(2, $orders[0]->id); + $this->assertEquals(12, $orders[0]->id); $this->assertEquals(3, count($orders[0]->items)); $this->assertTrue($orders[0]->items[0]->isRelationPopulated('category')); $this->assertEquals(2, $orders[0]->items[0]->category->id); @@ -771,7 +771,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase ->where(['movies.name' => 'Toy Story']); $orders = $query->all(); $this->assertEquals(1, count($orders), $query->createCommand()->rawSql . print_r($orders, true)); - $this->assertEquals(2, $orders[0]->id); + $this->assertEquals(12, $orders[0]->id); $this->assertFalse($orders[0]->isRelationPopulated('bookItems')); $this->assertFalse($orders[0]->isRelationPopulated('movieItems')); // with eager loading @@ -781,7 +781,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase ->where(['movies.name' => 'Toy Story']); $orders = $query->all(); $this->assertEquals(1, count($orders), $query->createCommand()->rawSql . print_r($orders, true)); - $this->assertEquals(2, $orders[0]->id); + $this->assertEquals(12, $orders[0]->id); $this->assertTrue($orders[0]->isRelationPopulated('bookItems')); $this->assertTrue($orders[0]->isRelationPopulated('movieItems')); $this->assertEquals(0, count($orders[0]->bookItems)); @@ -796,7 +796,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase ->where(['movies.name' => 'Toy Story']); $orders = $query->all(); $this->assertEquals(1, count($orders), $query->createCommand()->rawSql . print_r($orders, true)); - $this->assertEquals(2, $orders[0]->id); + $this->assertEquals(12, $orders[0]->id); $this->assertFalse($orders[0]->isRelationPopulated('itemsIndexed')); // with eager loading, only for one relation as it would be overwritten otherwise. $query = Order::find() @@ -805,7 +805,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase ->where(['movies.name' => 'Toy Story']); $orders = $query->all(); $this->assertEquals(1, count($orders), $query->createCommand()->rawSql . print_r($orders, true)); - $this->assertEquals(2, $orders[0]->id); + $this->assertEquals(12, $orders[0]->id); $this->assertTrue($orders[0]->isRelationPopulated('itemsIndexed')); $this->assertEquals(3, count($orders[0]->itemsIndexed)); // with eager loading, and the other relation @@ -815,7 +815,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase ->where(['movies.name' => 'Toy Story']); $orders = $query->all(); $this->assertEquals(1, count($orders), $query->createCommand()->rawSql . print_r($orders, true)); - $this->assertEquals(2, $orders[0]->id); + $this->assertEquals(12, $orders[0]->id); $this->assertTrue($orders[0]->isRelationPopulated('itemsIndexed')); $this->assertEquals(0, count($orders[0]->itemsIndexed)); } @@ -827,7 +827,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase public function testFindCompositeRelationWithJoin() { /* @var $orderItem OrderItem */ - $orderItem = OrderItem::findOne([1, 1]); + $orderItem = OrderItem::findOne([11, 21]); $orderItemNoJoin = $orderItem->orderItemCompositeNoJoin; $this->assertInstanceOf('yiiunit\data\ar\OrderItem', $orderItemNoJoin); @@ -839,7 +839,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase public function testFindSimpleRelationWithJoin() { /* @var $order Order */ - $order = Order::findOne(1); + $order = Order::findOne(11); $customerNoJoin = $order->customer; $this->assertInstanceOf('yiiunit\data\ar\Customer', $customerNoJoin); @@ -874,14 +874,14 @@ abstract class ActiveRecordTest extends DatabaseTestCase OrderItem::$tableName = $orderItemTableName; /** @var $order Order */ - $order = Order::findOne(1); + $order = Order::findOne(11); $itemsSQL = $order->getOrderitems()->createCommand()->rawSql; - $expectedSQL = $this->replaceQuotes("SELECT * FROM [[order_item]] WHERE [[order_id]]=1"); + $expectedSQL = $this->replaceQuotes("SELECT * FROM [[order_item]] WHERE [[order_id]]=11"); $this->assertEquals($expectedSQL, $itemsSQL); - $order = Order::findOne(1); + $order = Order::findOne(11); $itemsSQL = $order->getOrderItems()->joinWith('item')->createCommand()->rawSql; - $expectedSQL = $this->replaceQuotes("SELECT [[order_item]].* FROM [[order_item]] LEFT JOIN [[item]] ON [[order_item]].[[item_id]] = [[item]].[[id]] WHERE [[order_item]].[[order_id]]=1"); + $expectedSQL = $this->replaceQuotes("SELECT [[order_item]].* FROM [[order_item]] LEFT JOIN [[item]] ON [[order_item]].[[item_id]] = [[item]].[[id]] WHERE [[order_item]].[[order_id]]=11"); $this->assertEquals($expectedSQL, $itemsSQL); Order::$tableName = null; @@ -939,25 +939,25 @@ abstract class ActiveRecordTest extends DatabaseTestCase $this->assertTrue($customer['orders2'][0]['customer2']['id'] === $customers[0]['id']); $this->assertTrue(empty($customers[1]['orders2'])); - $orders = Order::find()->with('customer2')->where(['id' => 1])->all(); + $orders = Order::find()->with('customer2')->where(['id' => 11])->all(); $this->assertTrue($orders[0]->customer2->orders2 === [$orders[0]]); - $order = Order::find()->with('customer2')->where(['id' => 1])->one(); + $order = Order::find()->with('customer2')->where(['id' => 11])->one(); $this->assertTrue($order->customer2->orders2 === [$order]); - $orders = Order::find()->with('customer2')->where(['id' => 1])->asArray()->all(); + $orders = Order::find()->with('customer2')->where(['id' => 11])->asArray()->all(); $this->assertTrue($orders[0]['customer2']['orders2'][0]['id'] === $orders[0]['id']); - $order = Order::find()->with('customer2')->where(['id' => 1])->asArray()->one(); + $order = Order::find()->with('customer2')->where(['id' => 11])->asArray()->one(); $this->assertTrue($order['customer2']['orders2'][0]['id'] === $orders[0]['id']); - $orders = Order::find()->with('customer2')->where(['id' => [1, 3]])->all(); + $orders = Order::find()->with('customer2')->where(['id' => [11, 13]])->all(); $this->assertTrue($orders[0]->customer2->orders2 === [$orders[0]]); $this->assertTrue($orders[1]->customer2->orders2 === [$orders[1]]); - $orders = Order::find()->with('customer2')->where(['id' => [2, 3]])->orderBy('id')->all(); + $orders = Order::find()->with('customer2')->where(['id' => [12, 13]])->orderBy('id')->all(); $this->assertTrue($orders[0]->customer2->orders2 === $orders); $this->assertTrue($orders[1]->customer2->orders2 === $orders); - $orders = Order::find()->with('customer2')->where(['id' => [2, 3]])->orderBy('id')->asArray()->all(); + $orders = Order::find()->with('customer2')->where(['id' => [12, 13]])->orderBy('id')->asArray()->all(); $this->assertTrue($orders[0]['customer2']['orders2'][0]['id'] === $orders[0]['id']); $this->assertTrue($orders[0]['customer2']['orders2'][1]['id'] === $orders[1]['id']); $this->assertTrue($orders[1]['customer2']['orders2'][0]['id'] === $orders[0]['id']); @@ -1033,7 +1033,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase // via table with delete /* @var $order Order */ - $order = $orderClass::findOne(1); + $order = $orderClass::findOne(11); $this->assertEquals(2, count($order->booksViaTable)); $orderItemCount = $orderItemClass::find()->count(); $this->assertEquals(5, $itemClass::find()->count()); @@ -1049,7 +1049,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase $this->assertEquals(5, $itemClass::find()->count()); $order->unlinkAll('booksWithNullFKViaTable',false); $this->assertEquals(0, count($order->booksWithNullFKViaTable)); - $this->assertEquals(2,$orderItemsWithNullFKClass::find()->where(['AND', ['item_id' => [1, 2]], ['order_id' => null]])->count()); + $this->assertEquals(2,$orderItemsWithNullFKClass::find()->where(['AND', ['item_id' => [21, 22]], ['order_id' => null]])->count()); $this->assertEquals($orderItemCount, $orderItemsWithNullFKClass::find()->count()); $this->assertEquals(5, $itemClass::find()->count()); } @@ -1198,15 +1198,15 @@ abstract class ActiveRecordTest extends DatabaseTestCase ->all(); $expected = [ [ - 'order_id' => 1, + 'order_id' => 11, 'subtotal' => 70, ], [ - 'order_id' => 2, + 'order_id' => 12, 'subtotal' => 33, ], [ - 'order_id' => 3, + 'order_id' => 13, 'subtotal' => 40, ], ]; @@ -1248,31 +1248,31 @@ abstract class ActiveRecordTest extends DatabaseTestCase { $order = Order::find() ->with('orderItems2') - ->where(['id' => 1]) + ->where(['id' => 11]) ->one(); $orderItem = new OrderItem([ 'order_id' => $order->id, - 'item_id' => 3, + 'item_id' => 23, 'quantity' => 1, 'subtotal' => 10.0, ]); $order->link('orderItems2', $orderItem); - $this->assertTrue(isset($order->orderItems2['3'])); + $this->assertTrue(isset($order->orderItems2['23'])); } public function testLinkWhenRelationIsIndexed3() { $order = Order::find() ->with('orderItems3') - ->where(['id' => 1]) + ->where(['id' => 11]) ->one(); $orderItem = new OrderItem([ 'order_id' => $order->id, - 'item_id' => 3, + 'item_id' => 23, 'quantity' => 1, 'subtotal' => 10.0, ]); $order->link('orderItems3', $orderItem); - $this->assertTrue(isset($order->orderItems3['1_3'])); + $this->assertTrue(isset($order->orderItems3['11_23'])); } }