diff --git a/tests/ActiveQueryFindTest.php b/tests/ActiveQueryFindTest.php index e59d63da9..8e0c41d30 100644 --- a/tests/ActiveQueryFindTest.php +++ b/tests/ActiveQueryFindTest.php @@ -20,8 +20,6 @@ abstract class ActiveQueryFindTest extends TestCase { public function testFindAll(): void { - $this->checkFixture($this->db(), 'customer', true); - $customerQuery = new ActiveQuery(Customer::class); $this->assertCount(1, $customerQuery->findAll(['id' => 1])); $this->assertCount(3, $customerQuery->findAll(['id' => [1, 2, 3]])); @@ -29,8 +27,6 @@ public function testFindAll(): void public function testFindScalar(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); /** query scalar */ @@ -41,8 +37,6 @@ public function testFindScalar(): void public function testFindExists(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $this->assertTrue($customerQuery->where(['[[id]]' => 2])->exists()); @@ -54,8 +48,6 @@ public function testFindExists(): void public function testFindColumn(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $this->assertEquals( @@ -63,7 +55,7 @@ public function testFindColumn(): void $customerQuery->select('[[name]]')->column() ); - $this->assertEquals( + $this->assertSame( ['user3', 'user2', 'user1'], $customerQuery->orderBy(['[[name]]' => SORT_DESC])->select('[[name]]')->column() ); @@ -71,8 +63,6 @@ public function testFindColumn(): void public function testFindBySql(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); /** find one() */ @@ -94,8 +84,6 @@ public function testFindBySql(): void public function testFindLazyViaTable(): void { - $this->checkFixture($this->db(), 'order'); - $orderQuery = new ActiveQuery(Order::class); $orders = $orderQuery->findByPk(2); @@ -108,8 +96,6 @@ public function testFindLazyViaTable(): void public function testFindEagerViaTable(): void { - $this->checkFixture($this->db(), 'order'); - $orderQuery = new ActiveQuery(Order::class); $orders = $orderQuery->with('books')->orderBy('id')->all(); $this->assertCount(3, $orders); @@ -149,8 +135,6 @@ public function testFindEagerViaTable(): void */ public function testFindCompositeRelationWithJoin(): void { - $this->checkFixture($this->db(), 'order_item'); - $orderItemQuery = new ActiveQuery(OrderItem::class); /** @var $orderItems OrderItem */ @@ -165,8 +149,6 @@ public function testFindCompositeRelationWithJoin(): void public function testFindSimpleRelationWithJoin(): void { - $this->checkFixture($this->db(), 'order'); - $orderQuery = new ActiveQuery(Order::class); $orders = $orderQuery->findByPk(1); @@ -184,8 +166,6 @@ public function testFindSimpleRelationWithJoin(): void public function testFindOneByColumnName(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new ActiveQuery(Customer::class); $customerQuery = new CustomerQuery(Customer::class); @@ -202,8 +182,6 @@ public function testFindOneByColumnName(): void public function testFind(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $this->assertInstanceOf(ActiveQueryInterface::class, $customerQuery); @@ -264,8 +242,6 @@ public function testFind(): void public function testFindAsArray(): void { - $this->checkFixture($this->db(), 'customer'); - /** asArray */ $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->where(['id' => 2])->asArray()->one(); @@ -302,8 +278,6 @@ public function testFindAsArray(): void public function testFindIndexBy(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customers = $customerQuery->indexBy('name')->orderBy('id')->all(); @@ -329,8 +303,6 @@ public function testFindIndexBy(): void public function testFindIndexByAsArray(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customers = $customerQuery->asArray()->indexBy('name')->all(); $this->assertCount(3, $customers); @@ -373,8 +345,6 @@ public function testFindIndexByAsArray(): void public function testFindCount(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $this->assertEquals(3, $customerQuery->count()); $this->assertEquals(1, $customerQuery->where(['id' => 1])->count()); @@ -391,8 +361,6 @@ public function testFindCount(): void public function testFindLimit(): void { - $this->checkFixture($this->db(), 'customer'); - /** one */ $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->orderBy('id')->one(); @@ -442,8 +410,6 @@ public function testFindLimit(): void public function testFindComplexCondition(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $this->assertEquals( @@ -479,7 +445,7 @@ public function testFindComplexCondition(): void public function testFindNullValues(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customerQuery = new ActiveQuery(Customer::class); @@ -494,8 +460,6 @@ public function testFindNullValues(): void public function testFindEager(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customers = $customerQuery->with('orders')->indexBy('id')->all(); @@ -531,8 +495,6 @@ public function testFindEager(): void public function testFindEagerViaRelation(): void { - $this->checkFixture($this->db(), 'order'); - $orderQuery = new ActiveQuery(Order::class); $orders = $orderQuery->with('items')->orderBy('id')->all(); $this->assertCount(3, $orders); @@ -547,8 +509,6 @@ public function testFindEagerViaRelation(): void public function testFindNestedRelation(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customers = $customerQuery->with('orders', 'orders.items')->indexBy('id')->all(); @@ -583,8 +543,6 @@ public function testFindNestedRelation(): void */ public function testFindEagerViaRelationPreserveOrder(): void { - $this->checkFixture($this->db(), 'order'); - $orderQuery = new ActiveQuery(Order::class); $orders = $orderQuery->with('itemsInOrder1')->orderBy('created_at')->all(); $this->assertCount(3, $orders); @@ -613,8 +571,6 @@ public function testFindEagerViaRelationPreserveOrder(): void public function testFindEagerViaRelationPreserveOrderB(): void { - $this->checkFixture($this->db(), 'order'); - /** different order in via table. */ $orderQuery = new ActiveQuery(Order::class); $orders = $orderQuery->with('itemsInOrder2')->orderBy('created_at')->all(); @@ -644,8 +600,6 @@ public function testFindEagerViaRelationPreserveOrderB(): void public function testFindEmptyInCondition(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customers = $customerQuery->where(['id' => [1]])->all(); $this->assertCount(1, $customers); @@ -662,8 +616,6 @@ public function testFindEmptyInCondition(): void public function testFindEagerIndexBy(): void { - $this->checkFixture($this->db(), 'order'); - $orderQuery = new ActiveQuery(Order::class); $order = $orderQuery->with('itemsIndexed')->where(['id' => 1])->one(); $this->assertTrue($order->isRelationPopulated('itemsIndexed')); @@ -685,8 +637,6 @@ public function testFindEagerIndexBy(): void public function testFindLazy(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->findByPk(2); $this->assertFalse($customer->isRelationPopulated('orders')); @@ -711,8 +661,6 @@ public function testFindLazy(): void public function testFindLazyVia(): void { - $this->checkFixture($this->db(), 'order'); - $orderQuery = new ActiveQuery(Order::class); $order = $orderQuery->findByPk(1); @@ -724,8 +672,6 @@ public function testFindLazyVia(): void public function testFindByPkComposite(): void { - $this->checkFixture($this->db(), 'order_item'); - $query = new ActiveQuery(OrderItem::class); $orderItem = $query->findByPk([1, 1]); @@ -742,8 +688,6 @@ public function testFindByPkComposite(): void public function testFindByPkWithoutPk(): void { - $this->checkFixture($this->db(), 'type'); - $query = new ActiveQuery(Type::class); $this->expectException(InvalidConfigException::class); @@ -754,8 +698,6 @@ public function testFindByPkWithoutPk(): void public function testFindByPkWithJoin(): void { - $this->checkFixture($this->db(), 'order'); - $query = new ActiveQuery(Order::class); $query->joinWith('items'); diff --git a/tests/ActiveQueryTest.php b/tests/ActiveQueryTest.php index 85e3ddf5b..024639f86 100644 --- a/tests/ActiveQueryTest.php +++ b/tests/ActiveQueryTest.php @@ -37,8 +37,6 @@ abstract class ActiveQueryTest extends TestCase { public function testOptions(): void { - $this->checkFixture($this->db(), 'customer', true); - $customerQuery = new ActiveQuery(Customer::class); $query = $customerQuery->on(['a' => 'b'])->joinWith('profile'); @@ -51,24 +49,18 @@ public function testOptions(): void public function testPrepare(): void { - $this->checkFixture($this->db(), 'customer'); - $query = new ActiveQuery(Customer::class); $this->assertInstanceOf(QueryInterface::class, $query->prepare($this->db()->getQueryBuilder())); } public function testPopulateEmptyRows(): void { - $this->checkFixture($this->db(), 'customer'); - $query = new ActiveQuery(Customer::class); $this->assertEquals([], $query->populate([])); } public function testPopulateFilledRows(): void { - $this->checkFixture($this->db(), 'customer'); - $query = new ActiveQuery(Customer::class); $rows = $query->all(); $result = $query->populate($rows); @@ -77,8 +69,6 @@ public function testPopulateFilledRows(): void public function testAll(): void { - $this->checkFixture($this->db(), 'customer'); - $query = new ActiveQuery(Customer::class); foreach ($query->all() as $customer) { @@ -90,32 +80,24 @@ public function testAll(): void public function testOne(): void { - $this->checkFixture($this->db(), 'customer'); - $query = new ActiveQuery(Customer::class); $this->assertInstanceOf(Customer::class, $query->one()); } public function testCreateCommand(): void { - $this->checkFixture($this->db(), 'customer'); - $query = new ActiveQuery(Customer::class); $this->assertInstanceOf(AbstractCommand::class, $query->createCommand()); } public function testQueryScalar(): void { - $this->checkFixture($this->db(), 'customer'); - $query = new ActiveQuery(Customer::class); $this->assertEquals('user1', Assert::invokeMethod($query, 'queryScalar', ['name'])); } public function testGetJoinWith(): void { - $this->checkFixture($this->db(), 'customer'); - $query = new ActiveQuery(Customer::class); $query->joinWith('profile'); $this->assertEquals([[['profile'], true, 'LEFT JOIN']], $query->getJoinWith()); @@ -123,8 +105,6 @@ public function testGetJoinWith(): void public function testInnerJoinWith(): void { - $this->checkFixture($this->db(), 'customer'); - $query = new ActiveQuery(Customer::class); $query->innerJoinWith('profile'); $this->assertEquals([[['profile'], true, 'INNER JOIN']], $query->getJoinWith()); @@ -132,8 +112,6 @@ public function testInnerJoinWith(): void public function testBuildJoinWithRemoveDuplicateJoinByTableName(): void { - $this->checkFixture($this->db(), 'customer'); - $query = new ActiveQuery(Customer::class); $query->innerJoinWith('orders')->joinWith('orders.orderItems'); Assert::invokeMethod($query, 'buildJoinWith'); @@ -153,16 +131,12 @@ public function testBuildJoinWithRemoveDuplicateJoinByTableName(): void public function testGetQueryTableNameFromNotSet(): void { - $this->checkFixture($this->db(), 'customer'); - $query = new ActiveQuery(Customer::class); $this->assertEquals(['customer', 'customer'], Assert::invokeMethod($query, 'getTableNameAndAlias')); } public function testGetQueryTableNameFromSet(): void { - $this->checkFixture($this->db(), 'customer'); - $query = new ActiveQuery(Customer::class); $query->from(['alias' => 'customer']); $this->assertEquals(['customer', 'alias'], Assert::invokeMethod($query, 'getTableNameAndAlias')); @@ -170,8 +144,6 @@ public function testGetQueryTableNameFromSet(): void public function testOnCondition(): void { - $this->checkFixture($this->db(), 'customer'); - $on = ['active' => true]; $params = ['a' => 'b']; @@ -183,8 +155,6 @@ public function testOnCondition(): void public function testAndOnConditionOnNotSet(): void { - $this->checkFixture($this->db(), 'customer'); - $on = ['active' => true]; $params = ['a' => 'b']; $query = new ActiveQuery(Customer::class); @@ -195,8 +165,6 @@ public function testAndOnConditionOnNotSet(): void public function testAndOnConditionOnSet(): void { - $this->checkFixture($this->db(), 'customer'); - $onOld = ['active' => true]; $on = ['active' => true]; $params = ['a' => 'b']; @@ -211,8 +179,6 @@ public function testAndOnConditionOnSet(): void public function testOrOnConditionOnNotSet(): void { - $this->checkFixture($this->db(), 'customer'); - $on = ['active' => true]; $params = ['a' => 'b']; @@ -226,8 +192,6 @@ public function testOrOnConditionOnNotSet(): void public function testOrOnConditionOnSet(): void { - $this->checkFixture($this->db(), 'customer'); - $onOld = ['active' => true]; $on = ['active' => true]; $params = ['a' => 'b']; @@ -252,8 +216,6 @@ public function testViaWithEmptyPrimaryModel(): void public function testViaTable(): void { - $this->checkFixture($this->db(), 'customer'); - $order = new Order(); $query = new ActiveQuery(Customer::class); @@ -266,8 +228,6 @@ public function testViaTable(): void public function testAliasNotSet(): void { - $this->checkFixture($this->db(), 'customer'); - $query = new ActiveQuery(Customer::class); $query->alias('alias'); @@ -278,8 +238,6 @@ public function testAliasNotSet(): void public function testAliasYetSet(): void { - $this->checkFixture($this->db(), 'customer'); - $aliasOld = ['old']; $query = new ActiveQuery(Customer::class); @@ -292,8 +250,6 @@ public function testAliasYetSet(): void public function testGetTableNamesNotFilledFrom(): void { - $this->checkFixture($this->db(), 'profile'); - $query = new ActiveQuery(Profile::class); $tableName = Profile::TABLE_NAME; @@ -307,8 +263,6 @@ public function testGetTableNamesNotFilledFrom(): void public function testGetTableNamesWontFillFrom(): void { - $this->checkFixture($this->db(), 'profile'); - $query = new ActiveQuery(Profile::class); $this->assertSame([], $query->getFrom()); @@ -326,8 +280,6 @@ public function testGetTableNamesWontFillFrom(): void */ public function testDeeplyNestedTableRelationWith(): void { - $this->checkFixture($this->db(), 'category', true); - /** @var $category Category */ $categoriesQuery = new ActiveQuery(Category::class); @@ -355,8 +307,6 @@ public function testDeeplyNestedTableRelationWith(): void public function testGetSql(): void { - $this->checkFixture($this->db(), 'customer'); - $query = new ActiveQuery(Customer::class); $query->sql('SELECT * FROM {{customer}} ORDER BY [[id]] DESC'); @@ -366,8 +316,6 @@ public function testGetSql(): void public function testCustomColumns(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); /** find custom column */ @@ -387,8 +335,6 @@ public function testCustomColumns(): void public function testCallFind(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); /** find count, sum, average, min, max, scalar */ @@ -406,8 +352,6 @@ public function testCallFind(): void */ public function testCountWithFindBySql(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $query = $customerQuery->findBySql('SELECT * FROM {{customer}}'); @@ -419,8 +363,6 @@ public function testCountWithFindBySql(): void public function testDeeplyNestedTableRelation(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customers = $customerQuery->findByPk(1); @@ -442,8 +384,6 @@ public function testDeeplyNestedTableRelation(): void */ public function testDeeplyNestedTableRelation2(): void { - $this->checkFixture($this->db(), 'category'); - $categoryQuery = new ActiveQuery(Category::class); $categories = $categoryQuery->where(['id' => 1])->one(); @@ -469,8 +409,6 @@ public function testDeeplyNestedTableRelation2(): void public function testJoinWith(): void { - $this->checkFixture($this->db(), 'order'); - /** left join and eager loading */ $orderQuery = new ActiveQuery(Order::class); $orders = $orderQuery->joinWith('customer')->orderBy('customer.id DESC, order.id')->all(); @@ -715,8 +653,6 @@ public function testJoinWith(): void */ public function testJoinWithAndScope(): void { - $this->checkFixture($this->db(), 'customer'); - /** hasOne inner join */ $customer = new CustomerQuery(Customer::class); $customers = $customer->active()->innerJoinWith('profile')->orderBy('customer.id')->all(); @@ -760,7 +696,7 @@ public function testJoinWithAndScope(): void */ public function testJoinWithVia(): void { - $this->checkFixture($this->db(), 'order'); + $this->reloadFixtureAfterTest(); $orderQuery = new ActiveQuery(Order::class); @@ -797,8 +733,6 @@ public static function aliasMethodProvider(): array public function testJoinWithAlias(string $aliasMethod): void { $orders = []; - $this->checkFixture($this->db(), 'order'); - /** left join and eager loading */ $orderQuery = new ActiveQuery(Order::class); $query = $orderQuery->joinWith(['customer c']); @@ -1034,8 +968,6 @@ public function testJoinWithAlias(string $aliasMethod): void */ public function testJoinWithSameTable(): void { - $this->checkFixture($this->db(), 'order'); - /** * join with the same table but different aliases alias is defined in the relation definition without eager * loading @@ -1154,8 +1086,6 @@ public function testJoinWithSameTable(): void */ public function testJoinWithDuplicateSimple(): void { - $this->checkFixture($this->db(), 'order'); - /** left join and eager loading */ $orderQuery = new ActiveQuery(Order::class); @@ -1179,8 +1109,6 @@ public function testJoinWithDuplicateSimple(): void */ public function testJoinWithDuplicateCallbackFiltering(): void { - $this->checkFixture($this->db(), 'order'); - /** inner join filtering and eager loading */ $orderQuery = new ActiveQuery(Order::class); @@ -1204,8 +1132,6 @@ public function testJoinWithDuplicateCallbackFiltering(): void */ public function testJoinWithDuplicateCallbackFilteringConditionsOnPrimary(): void { - $this->checkFixture($this->db(), 'order'); - /** inner join filtering, eager loading, conditions on both primary and relation */ $orderQuery = new ActiveQuery(Order::class); @@ -1227,8 +1153,6 @@ public function testJoinWithDuplicateCallbackFilteringConditionsOnPrimary(): voi */ public function testJoinWithDuplicateWithSubRelation(): void { - $this->checkFixture($this->db(), 'order'); - /** join with sub-relation */ $orderQuery = new ActiveQuery(Order::class); @@ -1253,8 +1177,6 @@ public function testJoinWithDuplicateWithSubRelation(): void */ public function testJoinWithDuplicateTableAlias1(): void { - $this->checkFixture($this->db(), 'order'); - /** join with table alias */ $orderQuery = new ActiveQuery(Order::class); @@ -1280,8 +1202,6 @@ public function testJoinWithDuplicateTableAlias1(): void */ public function testJoinWithDuplicateTableAlias2(): void { - $this->checkFixture($this->db(), 'order'); - /** join with table alias */ $orderQuery = new ActiveQuery(Order::class); @@ -1305,8 +1225,6 @@ public function testJoinWithDuplicateTableAlias2(): void */ public function testJoinWithDuplicateTableAliasSubRelation(): void { - $this->checkFixture($this->db(), 'order'); - /** join with table alias sub-relation */ $orderQuery = new ActiveQuery(Order::class); @@ -1335,8 +1253,6 @@ public function testJoinWithDuplicateTableAliasSubRelation(): void */ public function testJoinWithDuplicateSubRelationCalledInsideClosure(): void { - $this->checkFixture($this->db(), 'order'); - /** join with sub-relation called inside Closure */ $orderQuery = new ActiveQuery(Order::class); @@ -1365,8 +1281,6 @@ public function testJoinWithDuplicateSubRelationCalledInsideClosure(): void public function testAlias(): void { - $this->checkFixture($this->db(), 'order'); - $order = new Order(); $query = new ActiveQuery(Order::class); @@ -1384,8 +1298,6 @@ public function testAlias(): void public function testInverseOf(): void { - $this->checkFixture($this->db(), 'customer'); - /** eager loading: find one and all */ $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->with('orders2')->where(['id' => 1])->one(); @@ -1465,7 +1377,7 @@ public function testInverseOf(): void public function testUnlinkAllViaTable(): void { - $this->checkFixture($this->db(), 'order', true); + $this->reloadFixtureAfterTest(); /** via table with delete. */ $orderQuery = new ActiveQuery(Order::class); @@ -1503,7 +1415,7 @@ public function testUnlinkAllViaTable(): void public function testIssues(): void { - $this->checkFixture($this->db(), 'category', true); + $this->reloadFixtureAfterTest(); /** {@see https://github.com/yiisoft/yii2/issues/4938} */ $categoryQuery = new ActiveQuery(Category::class); @@ -1547,8 +1459,6 @@ public function testIssues(): void public function testPopulateWithoutPk(): void { - $this->checkFixture($this->db(), 'customer', true); - /** tests with single pk asArray */ $customerQuery = new ActiveQuery(Customer::class); $aggregation = $customerQuery @@ -1667,7 +1577,7 @@ public function testPopulateWithoutPk(): void public function testLinkWhenRelationIsIndexed2(): void { - $this->checkFixture($this->db(), 'order'); + $this->reloadFixtureAfterTest(); $orderQuery = new ActiveQuery(Order::class); $order = $orderQuery->with('orderItems2')->where(['id' => 1])->one(); @@ -1685,8 +1595,6 @@ public function testLinkWhenRelationIsIndexed2(): void public function testEmulateExecution(): void { - $this->checkFixture($this->db(), 'order'); - $customerQuery = new ActiveQuery(Customer::class); $this->assertGreaterThan(0, $customerQuery->count()); @@ -1707,7 +1615,7 @@ public function testEmulateExecution(): void */ public function testUnlinkAllOnCondition(): void { - $this->checkFixture($this->db(), 'item'); + $this->reloadFixtureAfterTest(); /** Ensure there are three items with category_id = 2 in the Items table */ $itemQuery = new ActiveQuery(Item::class); @@ -1739,7 +1647,7 @@ public function testUnlinkAllOnCondition(): void */ public function testUnlinkAllOnConditionViaTable(): void { - $this->checkFixture($this->db(), 'item', true); + $this->reloadFixtureAfterTest(); /** Ensure there are three items with category_id = 2 in the Items table */ $itemQuery = new ActiveQuery(Item::class); @@ -1770,8 +1678,6 @@ public function testUnlinkAllOnConditionViaTable(): void */ public function testIndexByAfterLoadingRelations(): void { - $this->checkFixture($this->db(), 'order'); - $orderQuery = new ActiveQuery(Order::class); $orderQuery->with('customer')->indexBy(function (Order $order) { $this->assertTrue($order->isRelationPopulated('customer')); @@ -1789,8 +1695,6 @@ public function testIndexByAfterLoadingRelations(): void public function testExtraFields(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $query = $customerQuery->with('orders2')->where(['id' => 1])->one(); @@ -1823,8 +1727,6 @@ public function testRelationWhereParams(string $orderTableName, string $orderIte { $driverName = $this->db()->getDriverName(); - $this->checkFixture($this->db(), 'order'); - $order = new Order(); $orderItem = new OrderItem(); @@ -1861,8 +1763,6 @@ public function testRelationWhereParams(string $orderTableName, string $orderIte public function testOutdatedRelationsAreResetForExistingRecords(): void { - $this->checkFixture($this->db(), 'order_item', true); - $orderItemQuery = new ActiveQuery(OrderItem::class); $orderItems = $orderItemQuery->findByPk([1, 1]); $this->assertEquals(1, $orderItems->getOrder()->getId()); @@ -1883,8 +1783,6 @@ public function testOutdatedRelationsAreResetForExistingRecords(): void public function testOutdatedCompositeKeyRelationsAreReset(): void { - $this->checkFixture($this->db(), 'dossier'); - $dossierQuery = new ActiveQuery(Dossier::class); $dossiers = $dossierQuery->findOne(['department_id' => 1, 'employee_id' => 1]); @@ -1913,8 +1811,6 @@ public function testOutdatedCompositeKeyRelationsAreReset(): void public function testOutdatedViaTableRelationsAreReset(): void { - $this->checkFixture($this->db(), 'order', true); - $orderQuery = new ActiveQuery(Order::class); $orders = $orderQuery->findByPk(1); @@ -1940,8 +1836,6 @@ public function testOutdatedViaTableRelationsAreReset(): void public function testInverseOfDynamic(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->findByPk(1); @@ -1973,7 +1867,7 @@ public function testInverseOfDynamic(): void public function testOptimisticLock(): void { - $this->checkFixture($this->db(), 'document'); + $this->reloadFixtureAfterTest(); $documentQuery = new ActiveQuery(Document::class); $record = $documentQuery->findByPk(1); @@ -1992,7 +1886,7 @@ public function testOptimisticLock(): void public function testOptimisticLockOnDelete(): void { - $this->checkFixture($this->db(), 'document', true); + $this->reloadFixtureAfterTest(); $documentQuery = new ActiveQuery(Document::class); $document = $documentQuery->findByPk(1); @@ -2007,7 +1901,7 @@ public function testOptimisticLockOnDelete(): void public function testOptimisticLockAfterDelete(): void { - $this->checkFixture($this->db(), 'document', true); + $this->reloadFixtureAfterTest(); $documentQuery = new ActiveQuery(Document::class); $document = $documentQuery->findByPk(1); @@ -2023,8 +1917,6 @@ public function testOptimisticLockAfterDelete(): void /** @link https://github.com/yiisoft/yii2/issues/9006 */ public function testBit(): void { - $this->checkFixture($this->db(), 'bit_values'); - $bitValueQuery = new ActiveQuery(BitValues::class); $falseBit = $bitValueQuery->findByPk(1); $this->assertFalse($falseBit->val); @@ -2036,7 +1928,7 @@ public function testBit(): void public function testUpdateProperties(): void { - $this->checkFixture($this->db(), 'order'); + $this->reloadFixtureAfterTest(); $orderQuery = new ActiveQuery(Order::class); $order = $orderQuery->findByPk(1); @@ -2064,8 +1956,6 @@ public function testUpdateProperties(): void */ public function testAmbiguousColumnFindOne(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new CustomerQuery(Customer::class); $customerQuery->joinWithProfile = true; @@ -2079,8 +1969,6 @@ public function testAmbiguousColumnFindOne(): void public function testCustomARRelation(): void { - $this->checkFixture($this->db(), 'order_item'); - $orderItem = new ActiveQuery(OrderItem::class); $orderItem = $orderItem->findByPk([1, 1]); @@ -2090,8 +1978,6 @@ public function testCustomARRelation(): void public function testPropertyValues(): void { - $this->checkFixture($this->db(), 'customer'); - $expectedValues = [ 'id' => 1, 'email' => 'user1@example.com', @@ -2111,8 +1997,6 @@ public function testPropertyValues(): void public function testPropertyValuesOnly(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new ActiveQuery(Customer::class); $values = $customer->findByPk(1)->propertyValues(['id', 'email', 'name']); @@ -2122,8 +2006,6 @@ public function testPropertyValuesOnly(): void public function testPropertyValuesExcept(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new ActiveQuery(Customer::class); $values = $customer->findByPk(1)->propertyValues(null, ['status', 'bool_status', 'profile_id']); @@ -2136,8 +2018,6 @@ public function testPropertyValuesExcept(): void public function testGetOldValue(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new ActiveQuery(Customer::class); $query = $customer->findByPk(1); @@ -2152,8 +2032,6 @@ public function testGetOldValue(): void public function testGetOldValues(): void { - $this->checkFixture($this->db(), 'customer'); - $expectedValues = [ 'id' => 1, 'email' => 'user1@example.com', @@ -2182,8 +2060,6 @@ public function testGetOldValues(): void public function testIsPropertyChanged(): void { - $this->checkFixture($this->db(), 'customer', true); - $query = new ActiveQuery(Customer::class); $customer = $query->findByPk(1); @@ -2203,7 +2079,7 @@ public function testIsPropertyChanged(): void public function testOldPropertyAfterInsertAndUpdate(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customer = new Customer(); @@ -2228,8 +2104,6 @@ public function testCheckRelationUnknownPropertyException(): void { self::markTestSkipped('There is no check for access to an unknown property.'); - $this->checkFixture($this->db(), 'customer'); - $customer = new ActiveQuery(Customer::class); $query = $customer->findByPk(1); @@ -2243,8 +2117,6 @@ public function testCheckRelationInvalidCallException(): void { self::markTestSkipped('There is no check for access to an unknown property.'); - $this->checkFixture($this->db(), 'customer'); - $customer = new ActiveQuery(Customer::class); $query = $customer->findByPk(2); @@ -2258,8 +2130,6 @@ public function testCheckRelationInvalidCallException(): void public function testGetRelationInvalidArgumentException(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new ActiveQuery(Customer::class); $query = $customer->findByPk(1); @@ -2276,8 +2146,6 @@ public function testGetRelationInvalidArgumentExceptionHasNoRelationNamed(): voi { self::markTestSkipped('The same as test testGetRelationInvalidArgumentException()'); - $this->checkFixture($this->db(), 'customer'); - $customer = new ActiveQuery(Customer::class); $query = $customer->findByPk(1); @@ -2294,8 +2162,6 @@ public function testGetRelationInvalidArgumentExceptionCaseSensitive(): void { self::markTestSkipped('The same as test testGetRelationInvalidArgumentException()'); - $this->checkFixture($this->db(), 'customer'); - $customer = new ActiveQuery(Customer::class); $query = $customer->findByPk(1); @@ -2310,8 +2176,6 @@ public function testGetRelationInvalidArgumentExceptionCaseSensitive(): void public function testExists(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new ActiveQuery(Customer::class); $this->assertTrue($customer->where(['id' => 2])->exists()); @@ -2325,7 +2189,7 @@ public function testExists(): void public function testUnlink(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); /** has many without delete */ $customerQuery = new ActiveQuery(Customer::class); @@ -2369,7 +2233,7 @@ public function testUnlink(): void public function testUnlinkAllAndConditionSetNull(): void { - $this->checkFixture($this->db(), 'order_item_with_null_fk'); + $this->reloadFixtureAfterTest(); /** in this test all orders are owned by customer 1 */ $orderWithNullFKInstance = new OrderWithNullFK(); @@ -2395,7 +2259,7 @@ public function testUnlinkAllAndConditionSetNull(): void public function testUnlinkAllAndConditionDelete(): void { - $this->checkFixture($this->db(), 'customer', true); + $this->reloadFixtureAfterTest(); /** in this test all orders are owned by customer 1 */ $orderInstance = new Order(); @@ -2421,7 +2285,7 @@ public function testUnlinkAllAndConditionDelete(): void public function testUpdate(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->findByPk(2); @@ -2465,7 +2329,7 @@ public function testUpdate(): void public function testUpdateCounters(): void { - $this->checkFixture($this->db(), 'order_item', true); + $this->reloadFixtureAfterTest(); /** updateCounters */ $pk = ['order_id' => 2, 'item_id' => 4]; @@ -2497,7 +2361,7 @@ public function testUpdateCounters(): void public function testDelete(): void { - $this->checkFixture($this->db(), 'customer', true); + $this->reloadFixtureAfterTest(); /** delete */ $customerQuery = new ActiveQuery(Customer::class); @@ -2531,8 +2395,6 @@ public function testDelete(): void */ public function testViaWithCallable(): void { - $this->checkFixture($this->db(), 'order', true); - $orderQuery = new ActiveQuery(Order::class); $order = $orderQuery->findByPk(2); @@ -2549,7 +2411,7 @@ public function testViaWithCallable(): void public function testLink(): void { - $this->checkFixture($this->db(), 'customer', true); + $this->reloadFixtureAfterTest(); $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->findByPk(2); @@ -2603,8 +2465,6 @@ public function testLink(): void public function testEqual(): void { - $this->checkFixture($this->db(), 'customer'); - $customerA = (new ActiveQuery(Customer::class))->findByPk(1); $customerB = (new ActiveQuery(Customer::class))->findByPk(2); $this->assertFalse($customerA->equals($customerB)); diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php index c762e516a..0d2d59fe5 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -26,6 +26,7 @@ use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Promotion; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Profile; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Type; +use Yiisoft\ActiveRecord\Tests\Support\DbHelper; use Yiisoft\ActiveRecord\Tests\Support\ModelFactory; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidArgumentException; @@ -41,7 +42,7 @@ abstract protected function createFactory(): Factory; public function testStoreNull(): void { - $this->checkFixture($this->db(), 'null_values', true); + $this->reloadFixtureAfterTest(); $record = new NullValues(); @@ -89,7 +90,7 @@ public function testStoreNull(): void public function testStoreEmpty(): void { - $this->checkFixture($this->db(), 'null_values'); + $this->reloadFixtureAfterTest(); $record = new NullValues(); @@ -109,8 +110,6 @@ public function testStoreEmpty(): void public function testIsPrimaryKey(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new Customer(); $orderItem = new OrderItem(); @@ -131,8 +130,6 @@ public function testIsPrimaryKey(): void public function testOutdatedRelationsAreResetForNewRecords(): void { - $this->checkFixture($this->db(), 'order_item'); - $orderItem = new OrderItem(); $orderItem->setOrderId(1); @@ -154,8 +151,6 @@ public function testOutdatedRelationsAreResetForNewRecords(): void public function testDefaultValues(): void { - $this->checkFixture($this->db(), 'type'); - $arClass = new Type(); $arClass->loadDefaultValues(); @@ -186,7 +181,7 @@ public function testDefaultValues(): void public function testCastValues(): void { - $this->checkFixture($this->db(), 'type'); + $this->reloadFixtureAfterTest(); $arClass = new Type(); @@ -224,7 +219,7 @@ public function testCastValues(): void public function testPopulateRecordCallWhenQueryingOnParentClass(): void { - $this->checkFixture($this->db(), 'cat'); + $this->reloadFixtureAfterTest(); $cat = new Cat(); $cat->save(); @@ -243,7 +238,7 @@ public function testPopulateRecordCallWhenQueryingOnParentClass(): void public function testSaveEmpty(): void { - $this->checkFixture($this->db(), 'null_values', true); + $this->reloadFixtureAfterTest(); $record = new NullValues(); @@ -256,7 +251,7 @@ public function testSaveEmpty(): void */ public function testNoTablenameReplacement(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customer = new Customer(); @@ -279,8 +274,6 @@ public function testNoTablenameReplacement(): void public function testRefreshQuerySetAliasFindRecord(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new CustomerWithAlias(); $customer->id = 1; @@ -291,7 +284,7 @@ public function testRefreshQuerySetAliasFindRecord(): void public function testResetNotSavedRelation(): void { - $this->checkFixture($this->db(), 'order'); + $this->reloadFixtureAfterTest(); $order = new Order(); @@ -314,8 +307,6 @@ public function testIssetException(): void { self::markTestSkipped('There are no magic properties in the Cat class'); - $this->checkFixture($this->db(), 'cat'); - $cat = new Cat(); $this->expectException(Exception::class); @@ -326,8 +317,6 @@ public function testIssetThrowable(): void { self::markTestSkipped('There are no magic properties in the Cat class'); - $this->checkFixture($this->db(), 'cat'); - $cat = new Cat(); $this->expectException(DivisionByZeroError::class); @@ -338,8 +327,6 @@ public function testIssetNonExisting(): void { self::markTestSkipped('There are no magic properties in the Cat class'); - $this->checkFixture($this->db(), 'cat'); - $cat = new Cat(); $this->assertFalse(isset($cat->non_existing)); @@ -348,7 +335,7 @@ public function testIssetNonExisting(): void public function testSetProperties(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $properties = [ 'email' => 'samdark@mail.ru', @@ -371,8 +358,6 @@ public function testSetPropertyNoExist(): void { self::markTestSkipped('There are no magic properties in the Cat class'); - $this->checkFixture($this->db(), 'cat'); - $cat = new Cat(); $this->expectException(InvalidArgumentException::class); @@ -385,8 +370,6 @@ public function testSetPropertyNoExist(): void public function testAssignOldValue(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new Customer(); $this->assertEmpty($customer->oldValue('name')); @@ -398,8 +381,6 @@ public function testAssignOldValue(): void public function testaAssignOldValueException(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new Customer(); $this->assertEmpty($customer->oldValue('name')); @@ -413,8 +394,6 @@ public function testaAssignOldValueException(): void public function testIsPropertyChangedNotChanged(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new Customer(); $this->assertEmpty($customer->get('email')); @@ -434,7 +413,7 @@ public function testTableSchemaException(): void public function testInsert(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customer = new Customer(); @@ -458,7 +437,7 @@ public function testInsert(): void */ public function testBooleanProperty(): void { - $this->checkFixture($this->db(), 'customer', true); + $this->reloadFixtureAfterTest(); $customer = new Customer(); @@ -489,8 +468,6 @@ public function testPropertyAccess(): void { self::markTestSkipped('There are no magic properties in the Cat class'); - $this->checkFixture($this->db(), 'customer'); - $arClass = new Customer(); $this->assertTrue($arClass->canSetProperty('name')); @@ -545,8 +522,6 @@ public function testPropertyAccess(): void public function testHasProperty(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new Customer(); $this->assertTrue($customer->hasProperty('id')); @@ -562,8 +537,6 @@ public function testHasProperty(): void public function testRefresh(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new Customer(); $this->assertFalse($customer->refresh()); @@ -578,8 +551,6 @@ public function testRefresh(): void public function testEquals(): void { - $this->checkFixture($this->db(), 'customer'); - $customerA = new Customer(); $customerB = new Customer(); $this->assertFalse($customerA->equals($customerB)); @@ -604,8 +575,7 @@ public static function providerForUnlinkDelete(): array */ public function testUnlinkWithViaOnCondition($delete, $count): void { - $this->checkFixture($this->db(), 'order', true); - $this->checkFixture($this->db(), 'order_item_with_null_fk', true); + $this->reloadFixtureAfterTest(); $orderQuery = new ActiveQuery(Order::class); $order = $orderQuery->findByPk(2); @@ -630,8 +600,6 @@ public function testUnlinkWithViaOnCondition($delete, $count): void public function testVirtualRelation(): void { - $this->checkFixture($this->db(), 'order', true); - $orderQuery = new ActiveQuery(Order::class); /** @var Order $order */ $order = $orderQuery->findByPk(2); @@ -647,8 +615,6 @@ public function testVirtualRelation(): void */ public function testJoinWithEager(): void { - $this->checkFixture($this->db(), 'customer', true); - $customerQuery = new ActiveQuery(Customer::class); $eagerCustomers = $customerQuery->joinWith(['items2'])->all(); $eagerItemsCount = 0; @@ -668,7 +634,7 @@ public function testJoinWithEager(): void public function testSaveWithoutChanges(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customerQuery = new ActiveQuery(Customer::class); @@ -679,8 +645,6 @@ public function testSaveWithoutChanges(): void public function testGetPrimaryKey(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->findByPk(1); @@ -691,8 +655,6 @@ public function testGetPrimaryKey(): void public function testGetOldPrimaryKey(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->findByPk(1); @@ -704,7 +666,7 @@ public function testGetOldPrimaryKey(): void public function testGetDirtyValuesOnNewRecord(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customer = new Customer(); @@ -755,8 +717,6 @@ public function testGetDirtyValuesOnNewRecord(): void public function testGetDirtyValuesAfterFind(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->findByPk(1); @@ -778,8 +738,6 @@ public function testGetDirtyValuesAfterFind(): void public function testRelationWithInstance(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->findByPk(2); @@ -796,7 +754,7 @@ public function testWithCustomConnection(): void $db = $this->createConnection(); ConnectionProvider::set($db, 'custom'); - $this->checkFixture($db, 'customer'); + DbHelper::loadFixture($db); $customer = new CustomerWithCustomConnection(); @@ -813,8 +771,6 @@ public function testWithCustomConnection(): void public function testWithFactory(): void { - $this->checkFixture($this->db(), 'order'); - $factory = $this->createFactory(); $orderQuery = new ActiveQuery($factory->create(OrderWithFactory::class)->withFactory($factory)); @@ -827,8 +783,6 @@ public function testWithFactory(): void public function testWithFactoryClosureRelation(): void { - $this->checkFixture($this->db(), 'order'); - $factory = $this->createFactory(); $orderQuery = new ActiveQuery($factory->create(OrderWithFactory::class)->withFactory($factory)); @@ -840,8 +794,6 @@ public function testWithFactoryClosureRelation(): void public function testWithFactoryInstanceRelation(): void { - $this->checkFixture($this->db(), 'order'); - $factory = $this->createFactory(); $orderQuery = new ActiveQuery($factory->create(OrderWithFactory::class)->withFactory($factory)); @@ -853,8 +805,6 @@ public function testWithFactoryInstanceRelation(): void public function testWithFactoryRelationWithoutFactory(): void { - $this->checkFixture($this->db(), 'order'); - $factory = $this->createFactory(); $orderQuery = new ActiveQuery($factory->create(OrderWithFactory::class)->withFactory($factory)); @@ -866,8 +816,6 @@ public function testWithFactoryRelationWithoutFactory(): void public function testWithFactoryLazyRelation(): void { - $this->checkFixture($this->db(), 'order'); - $factory = $this->createFactory(); $orderQuery = new ActiveQuery($factory->create(OrderWithFactory::class)->withFactory($factory)); @@ -880,8 +828,6 @@ public function testWithFactoryLazyRelation(): void public function testWithFactoryWithConstructor(): void { - $this->checkFixture($this->db(), 'order'); - $factory = $this->createFactory(); $customerQuery = new ActiveQuery($factory->create(CustomerWithFactory::class)); @@ -894,8 +840,6 @@ public function testWithFactoryWithConstructor(): void public function testWithFactoryNonInitiated(): void { - $this->checkFixture($this->db(), 'order'); - $orderQuery = new ActiveQuery(OrderWithFactory::class); $order = $orderQuery->findByPk(2); @@ -911,8 +855,6 @@ public function testWithFactoryNonInitiated(): void public function testSerialization(): void { - $this->checkFixture($this->db(), 'profile'); - $profile = new Profile(); $this->assertEquals( @@ -935,8 +877,6 @@ public function testRelationViaJson(): void $this->markTestSkipped('Oracle and MSSQL drivers do not support JSON columns.'); } - $this->checkFixture($this->db(), 'promotion'); - $promotionQuery = new ActiveQuery(Promotion::class); /** @var Promotion[] $promotions */ $promotions = $promotionQuery->with('itemsViaJson')->all(); @@ -968,8 +908,6 @@ public function testLazzyRelationViaJson(): void $this->markTestSkipped('Oracle and MSSQL drivers do not support JSON columns.'); } - $this->checkFixture($this->db(), 'item'); - $itemQuery = new ActiveQuery(Item::class); /** @var Item[] $items */ $items = $itemQuery->all(); @@ -989,8 +927,6 @@ public function testLazzyRelationViaJson(): void public function testIsChanged(): void { - $this->checkFixture($this->db(), 'item'); - $itemQuery = new ActiveQuery(Item::class); $item = $itemQuery->findByPk(1); diff --git a/tests/ArrayableTraitTest.php b/tests/ArrayableTraitTest.php index d4ee51e40..caaed08c4 100644 --- a/tests/ArrayableTraitTest.php +++ b/tests/ArrayableTraitTest.php @@ -13,8 +13,6 @@ abstract class ArrayableTraitTest extends TestCase { public function testFields(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(CustomerForArrayable::class); $fields = $customerQuery->findOne(['id' => 1])->fields(); @@ -37,8 +35,6 @@ public function testFields(): void public function testToArray(): void { - $this->checkFixture($this->db(), 'customer', true); - $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->findByPk(1); @@ -58,8 +54,6 @@ public function testToArray(): void public function testToArrayWithClosure(): void { - $this->checkFixture($this->db(), 'customer', true); - $customerQuery = new ActiveQuery(CustomerClosureField::class); $customer = $customerQuery->findByPk(1); @@ -79,8 +73,6 @@ public function testToArrayWithClosure(): void public function testToArrayForArrayable(): void { - $this->checkFixture($this->db(), 'customer', true); - $customerQuery = new ActiveQuery(CustomerForArrayable::class); /** @var CustomerForArrayable $customer */ diff --git a/tests/BatchQueryResultTest.php b/tests/BatchQueryResultTest.php index 038cc426f..142f3e2cb 100644 --- a/tests/BatchQueryResultTest.php +++ b/tests/BatchQueryResultTest.php @@ -12,8 +12,6 @@ abstract class BatchQueryResultTest extends TestCase { public function testQuery(): void { - $this->checkFixture($this->db(), 'customer', true); - $customerQuery = new ActiveQuery(Customer::class); $query = $customerQuery->orderBy('id'); @@ -116,8 +114,6 @@ public function testQuery(): void public function testActiveQuery(): void { - $this->checkFixture($this->db(), 'customer'); - /** batch with eager loading */ $customerQuery = new ActiveQuery(Customer::class); @@ -137,8 +133,6 @@ public function testActiveQuery(): void public function testBatchWithIndexBy(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $query = $customerQuery->orderBy('id')->limit(3)->indexBy('id'); diff --git a/tests/ConnectionProviderTest.php b/tests/ConnectionProviderTest.php index e95285cd1..53fc8def0 100644 --- a/tests/ConnectionProviderTest.php +++ b/tests/ConnectionProviderTest.php @@ -51,6 +51,8 @@ public function testConnectionProvider(): void public function testConnectionProviderMiddleware(): void { + $this->reloadFixtureAfterTest(); + ConnectionProvider::remove(); $this->assertEmpty(ConnectionProvider::all()); diff --git a/tests/Driver/Mssql/ActiveQueryFindTest.php b/tests/Driver/Mssql/ActiveQueryFindTest.php index bb39b9f27..d5968a675 100644 --- a/tests/Driver/Mssql/ActiveQueryFindTest.php +++ b/tests/Driver/Mssql/ActiveQueryFindTest.php @@ -9,7 +9,7 @@ final class ActiveQueryFindTest extends \Yiisoft\ActiveRecord\Tests\ActiveQueryFindTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new MssqlHelper())->createConnection(); } diff --git a/tests/Driver/Mssql/ActiveQueryTest.php b/tests/Driver/Mssql/ActiveQueryTest.php index 6abeedf90..8d45e0465 100644 --- a/tests/Driver/Mssql/ActiveQueryTest.php +++ b/tests/Driver/Mssql/ActiveQueryTest.php @@ -9,7 +9,7 @@ final class ActiveQueryTest extends \Yiisoft\ActiveRecord\Tests\ActiveQueryTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new MssqlHelper())->createConnection(); } diff --git a/tests/Driver/Mssql/ActiveRecordTest.php b/tests/Driver/Mssql/ActiveRecordTest.php index 225d90751..2fbf49aa9 100644 --- a/tests/Driver/Mssql/ActiveRecordTest.php +++ b/tests/Driver/Mssql/ActiveRecordTest.php @@ -13,7 +13,7 @@ final class ActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\ActiveRecordTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new MssqlHelper())->createConnection(); } @@ -25,7 +25,7 @@ protected function createFactory(): Factory public function testSaveWithTrigger(): void { - $this->checkFixture($this->db(), 'test_trigger'); + $this->reloadFixtureAfterTest(); // drop trigger if exist $sql = <<createConnection(); } diff --git a/tests/Driver/Mssql/BatchQueryResultTest.php b/tests/Driver/Mssql/BatchQueryResultTest.php index c534f0cb3..a4bcbdfa3 100644 --- a/tests/Driver/Mssql/BatchQueryResultTest.php +++ b/tests/Driver/Mssql/BatchQueryResultTest.php @@ -9,7 +9,7 @@ final class BatchQueryResultTest extends \Yiisoft\ActiveRecord\Tests\BatchQueryResultTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new MssqlHelper())->createConnection(); } diff --git a/tests/Driver/Mssql/ConnectionProviderTest.php b/tests/Driver/Mssql/ConnectionProviderTest.php index 3664548f3..e861d6e99 100644 --- a/tests/Driver/Mssql/ConnectionProviderTest.php +++ b/tests/Driver/Mssql/ConnectionProviderTest.php @@ -9,7 +9,7 @@ final class ConnectionProviderTest extends \Yiisoft\ActiveRecord\Tests\ConnectionProviderTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new MssqlHelper())->createConnection(); } diff --git a/tests/Driver/Mssql/MagicActiveRecordTest.php b/tests/Driver/Mssql/MagicActiveRecordTest.php index 99b671144..7170850b2 100644 --- a/tests/Driver/Mssql/MagicActiveRecordTest.php +++ b/tests/Driver/Mssql/MagicActiveRecordTest.php @@ -12,14 +12,14 @@ final class MagicActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\MagicActiveRecordTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new MssqlHelper())->createConnection(); } public function testSaveWithTrigger(): void { - $this->checkFixture($this->db(), 'test_trigger'); + $this->reloadFixtureAfterTest(); // drop trigger if exist $sql = <<createConnection(); } diff --git a/tests/Driver/Mysql/ActiveQueryFindTest.php b/tests/Driver/Mysql/ActiveQueryFindTest.php index 87f111442..0316c6e36 100644 --- a/tests/Driver/Mysql/ActiveQueryFindTest.php +++ b/tests/Driver/Mysql/ActiveQueryFindTest.php @@ -9,7 +9,7 @@ final class ActiveQueryFindTest extends \Yiisoft\ActiveRecord\Tests\ActiveQueryFindTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new MysqlHelper())->createConnection(); } diff --git a/tests/Driver/Mysql/ActiveQueryTest.php b/tests/Driver/Mysql/ActiveQueryTest.php index be875d749..414f62792 100644 --- a/tests/Driver/Mysql/ActiveQueryTest.php +++ b/tests/Driver/Mysql/ActiveQueryTest.php @@ -9,7 +9,7 @@ final class ActiveQueryTest extends \Yiisoft\ActiveRecord\Tests\ActiveQueryTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new MysqlHelper())->createConnection(); } diff --git a/tests/Driver/Mysql/ActiveRecordTest.php b/tests/Driver/Mysql/ActiveRecordTest.php index 0147aa732..890b7b493 100644 --- a/tests/Driver/Mysql/ActiveRecordTest.php +++ b/tests/Driver/Mysql/ActiveRecordTest.php @@ -14,7 +14,7 @@ final class ActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\ActiveRecordTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new MysqlHelper())->createConnection(); } @@ -26,12 +26,10 @@ protected function createFactory(): Factory public function testCastValues(): void { - $this->checkFixture($this->db(), 'type'); + $this->reloadFixtureAfterTest(); $arClass = new Type(); - $arClass->deleteAll(); - $arClass->int_col = 123; $arClass->int_col2 = 456; $arClass->smallint_col = 42; @@ -67,7 +65,7 @@ public function testCastValues(): void public function testExplicitPkOnAutoIncrement(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customer = new Customer(); @@ -89,8 +87,6 @@ public function testExplicitPkOnAutoIncrement(): void */ public function testEagerLoadingUsingStringIdentifiers(): void { - $this->checkFixture($this->db(), 'beta'); - $betaQuery = new ActiveQuery(Beta::class); $betas = $betaQuery->with('alpha')->all(); diff --git a/tests/Driver/Mysql/ArrayableTraitTest.php b/tests/Driver/Mysql/ArrayableTraitTest.php index 0ae1a1d99..346861079 100644 --- a/tests/Driver/Mysql/ArrayableTraitTest.php +++ b/tests/Driver/Mysql/ArrayableTraitTest.php @@ -9,7 +9,7 @@ final class ArrayableTraitTest extends \Yiisoft\ActiveRecord\Tests\ArrayableTraitTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new MysqlHelper())->createConnection(); } diff --git a/tests/Driver/Mysql/BatchQueryResultTest.php b/tests/Driver/Mysql/BatchQueryResultTest.php index b3d3e3d00..4b2a04d3e 100644 --- a/tests/Driver/Mysql/BatchQueryResultTest.php +++ b/tests/Driver/Mysql/BatchQueryResultTest.php @@ -9,7 +9,7 @@ final class BatchQueryResultTest extends \Yiisoft\ActiveRecord\Tests\BatchQueryResultTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new MysqlHelper())->createConnection(); } diff --git a/tests/Driver/Mysql/ConnectionProviderTest.php b/tests/Driver/Mysql/ConnectionProviderTest.php index aaf56a3b2..2c9a8f92c 100644 --- a/tests/Driver/Mysql/ConnectionProviderTest.php +++ b/tests/Driver/Mysql/ConnectionProviderTest.php @@ -9,7 +9,7 @@ final class ConnectionProviderTest extends \Yiisoft\ActiveRecord\Tests\ConnectionProviderTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new MysqlHelper())->createConnection(); } diff --git a/tests/Driver/Mysql/MagicActiveRecordTest.php b/tests/Driver/Mysql/MagicActiveRecordTest.php index f63839acb..61ba83d00 100644 --- a/tests/Driver/Mysql/MagicActiveRecordTest.php +++ b/tests/Driver/Mysql/MagicActiveRecordTest.php @@ -12,14 +12,14 @@ final class MagicActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\MagicActiveRecordTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new MysqlHelper())->createConnection(); } public function testExplicitPkOnAutoIncrement(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customer = new Customer(); @@ -41,8 +41,6 @@ public function testExplicitPkOnAutoIncrement(): void */ public function testEagerLoadingUsingStringIdentifiers(): void { - $this->checkFixture($this->db(), 'beta'); - $betaQuery = new ActiveQuery(Beta::class); $betas = $betaQuery->with('alpha')->all(); diff --git a/tests/Driver/Mysql/RepositoryTraitTest.php b/tests/Driver/Mysql/RepositoryTraitTest.php index e6c9518fc..c47449e67 100644 --- a/tests/Driver/Mysql/RepositoryTraitTest.php +++ b/tests/Driver/Mysql/RepositoryTraitTest.php @@ -9,7 +9,7 @@ final class RepositoryTraitTest extends \Yiisoft\ActiveRecord\Tests\RepositoryTraitTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new MysqlHelper())->createConnection(); } diff --git a/tests/Driver/Oracle/ActiveQueryFindTest.php b/tests/Driver/Oracle/ActiveQueryFindTest.php index ff89f2501..60d98d10f 100644 --- a/tests/Driver/Oracle/ActiveQueryFindTest.php +++ b/tests/Driver/Oracle/ActiveQueryFindTest.php @@ -11,15 +11,13 @@ final class ActiveQueryFindTest extends \Yiisoft\ActiveRecord\Tests\ActiveQueryFindTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new OracleHelper())->createConnection(); } public function testFindLimit(): void { - $this->checkFixture($this->db(), 'customer', true); - /** one */ $customerQuery = new ActiveQuery(CustomerWithRownumid::class); $customer = $customerQuery->orderBy('id')->one(); diff --git a/tests/Driver/Oracle/ActiveQueryTest.php b/tests/Driver/Oracle/ActiveQueryTest.php index ce2d9415c..82aa7fa07 100644 --- a/tests/Driver/Oracle/ActiveQueryTest.php +++ b/tests/Driver/Oracle/ActiveQueryTest.php @@ -14,7 +14,7 @@ final class ActiveQueryTest extends \Yiisoft\ActiveRecord\Tests\ActiveQueryTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new OracleHelper())->createConnection(); } @@ -33,8 +33,6 @@ protected function createConnection(): ConnectionInterface public function testJoinWithAlias(string $aliasMethod): void { $orders = []; - $this->checkFixture($this->db(), 'order', true); - /** left join and eager loading */ $orderQuery = new ActiveQuery(Order::class); $query = $orderQuery->joinWith(['customer c']); @@ -270,8 +268,6 @@ public function testJoinWithAlias(string $aliasMethod): void */ public function testJoinWithSameTable(): void { - $this->checkFixture($this->db(), 'order'); - /** * join with the same table but different aliases alias is defined in the relation definition without eager * loading diff --git a/tests/Driver/Oracle/ActiveRecordTest.php b/tests/Driver/Oracle/ActiveRecordTest.php index 12c125cfe..2fb2ef618 100644 --- a/tests/Driver/Oracle/ActiveRecordTest.php +++ b/tests/Driver/Oracle/ActiveRecordTest.php @@ -13,7 +13,7 @@ final class ActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\ActiveRecordTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new OracleHelper())->createConnection(); } @@ -25,8 +25,6 @@ protected function createFactory(): Factory public function testDefaultValues(): void { - $this->checkFixture($this->db(), 'customer'); - $arClass = new Type(); $arClass->loadDefaultValues(); $this->assertSame(1, $arClass->int_col2); @@ -57,7 +55,7 @@ public function testDefaultValues(): void */ public function testBooleanProperty(): void { - $this->checkFixture($this->db(), 'customer', true); + $this->reloadFixtureAfterTest(); $customer = new Customer(); diff --git a/tests/Driver/Oracle/ArrayableTraitTest.php b/tests/Driver/Oracle/ArrayableTraitTest.php index 0d209c1f1..f6e6c1031 100644 --- a/tests/Driver/Oracle/ArrayableTraitTest.php +++ b/tests/Driver/Oracle/ArrayableTraitTest.php @@ -9,7 +9,7 @@ final class ArrayableTraitTest extends \Yiisoft\ActiveRecord\Tests\ArrayableTraitTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new OracleHelper())->createConnection(); } diff --git a/tests/Driver/Oracle/BatchQueryResultTest.php b/tests/Driver/Oracle/BatchQueryResultTest.php index c04d4afbf..46ef7eb7c 100644 --- a/tests/Driver/Oracle/BatchQueryResultTest.php +++ b/tests/Driver/Oracle/BatchQueryResultTest.php @@ -11,15 +11,13 @@ final class BatchQueryResultTest extends \Yiisoft\ActiveRecord\Tests\BatchQueryResultTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new OracleHelper())->createConnection(); } public function testBatchWithIndexBy(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $query = $customerQuery->orderBy('id')->limit(3)->indexBy('id'); diff --git a/tests/Driver/Oracle/ConnectionProviderTest.php b/tests/Driver/Oracle/ConnectionProviderTest.php index 2f3713237..7f222e29d 100644 --- a/tests/Driver/Oracle/ConnectionProviderTest.php +++ b/tests/Driver/Oracle/ConnectionProviderTest.php @@ -9,7 +9,7 @@ final class ConnectionProviderTest extends \Yiisoft\ActiveRecord\Tests\ConnectionProviderTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new OracleHelper())->createConnection(); } diff --git a/tests/Driver/Oracle/MagicActiveRecordTest.php b/tests/Driver/Oracle/MagicActiveRecordTest.php index 0b09e8885..bcd3466d9 100644 --- a/tests/Driver/Oracle/MagicActiveRecordTest.php +++ b/tests/Driver/Oracle/MagicActiveRecordTest.php @@ -12,15 +12,13 @@ final class MagicActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\MagicActiveRecordTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new OracleHelper())->createConnection(); } public function testDefaultValues(): void { - $this->checkFixture($this->db(), 'customer'); - $arClass = new Type(); $arClass->loadDefaultValues(); $this->assertSame(1, $arClass->int_col2); @@ -51,7 +49,7 @@ public function testDefaultValues(): void */ public function testBooleanProperty(): void { - $this->checkFixture($this->db(), 'customer', true); + $this->reloadFixtureAfterTest(); $customer = new Customer(); diff --git a/tests/Driver/Oracle/RepositoryTraitTest.php b/tests/Driver/Oracle/RepositoryTraitTest.php index ddbd6bd4a..ff7f5ca96 100644 --- a/tests/Driver/Oracle/RepositoryTraitTest.php +++ b/tests/Driver/Oracle/RepositoryTraitTest.php @@ -9,7 +9,7 @@ final class RepositoryTraitTest extends \Yiisoft\ActiveRecord\Tests\RepositoryTraitTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new OracleHelper())->createConnection(); } diff --git a/tests/Driver/Pgsql/ActiveQueryFindTest.php b/tests/Driver/Pgsql/ActiveQueryFindTest.php index 56be97535..0ba56a759 100644 --- a/tests/Driver/Pgsql/ActiveQueryFindTest.php +++ b/tests/Driver/Pgsql/ActiveQueryFindTest.php @@ -9,7 +9,7 @@ final class ActiveQueryFindTest extends \Yiisoft\ActiveRecord\Tests\ActiveQueryFindTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new PgsqlHelper())->createConnection(); } diff --git a/tests/Driver/Pgsql/ActiveQueryTest.php b/tests/Driver/Pgsql/ActiveQueryTest.php index 3aa6a1935..f9424746a 100644 --- a/tests/Driver/Pgsql/ActiveQueryTest.php +++ b/tests/Driver/Pgsql/ActiveQueryTest.php @@ -11,15 +11,13 @@ final class ActiveQueryTest extends \Yiisoft\ActiveRecord\Tests\ActiveQueryTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new PgsqlHelper())->createConnection(); } public function testBit(): void { - $this->checkFixture($this->db(), 'bit_values'); - $bitValueQuery = new ActiveQuery(BitValues::class); $falseBit = $bitValueQuery->findByPk(1); $this->assertSame(0, $falseBit->val); diff --git a/tests/Driver/Pgsql/ActiveRecordTest.php b/tests/Driver/Pgsql/ActiveRecordTest.php index 473cb495d..8fd4a55f0 100644 --- a/tests/Driver/Pgsql/ActiveRecordTest.php +++ b/tests/Driver/Pgsql/ActiveRecordTest.php @@ -25,7 +25,7 @@ final class ActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\ActiveRecordTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new PgsqlHelper())->createConnection(); } @@ -37,8 +37,6 @@ protected function createFactory(): Factory public function testDefaultValues(): void { - $this->checkFixture($this->db(), 'type'); - $arClass = new Type(); $arClass->loadDefaultValues(); @@ -66,7 +64,7 @@ public function testDefaultValues(): void public function testCastValues(): void { - $this->checkFixture($this->db(), 'type'); + $this->reloadFixtureAfterTest(); $arClass = new Type(); @@ -103,7 +101,7 @@ public function testCastValues(): void public function testExplicitPkOnAutoIncrement(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customer = new Customer(); $customer->setId(1337); @@ -122,8 +120,6 @@ public function testExplicitPkOnAutoIncrement(): void */ public function testEagerLoadingUsingStringIdentifiers(): void { - $this->checkFixture($this->db(), 'beta'); - $betaQuery = new ActiveQuery(Beta::class); $betas = $betaQuery->with('alpha')->all(); $this->assertNotEmpty($betas); @@ -142,8 +138,6 @@ public function testEagerLoadingUsingStringIdentifiers(): void public function testBooleanValues(): void { - $this->checkFixture($this->db(), 'bool_values'); - $command = $this->db()->createCommand(); $command->insertBatch('bool_values', [[true], [false]], ['bool_col'])->execute(); $boolARQuery = new ActiveQuery(BoolAR::class); @@ -168,7 +162,7 @@ public function testBooleanValues(): void */ public function testBooleanValues2(): void { - $this->checkFixture($this->db(), 'bool_user'); + $this->reloadFixtureAfterTest(); //$this->db()->setCharset('utf8'); $this->db()->createCommand('DROP TABLE IF EXISTS bool_user;')->execute(); @@ -207,7 +201,7 @@ public function testBooleanValues2(): void public function testBooleanDefaultValues(): void { - $this->checkFixture($this->db(), 'bool_values'); + $this->reloadFixtureAfterTest(); $arClass = new BoolAR(); @@ -225,7 +219,7 @@ public function testBooleanDefaultValues(): void public function testPrimaryKeyAfterSave(): void { - $this->checkFixture($this->db(), 'default_pk'); + $this->reloadFixtureAfterTest(); $record = new DefaultPk(); @@ -311,7 +305,7 @@ public static function arrayValuesProvider(): array */ public function testArrayValues($properties): void { - $this->checkFixture($this->db(), 'array_and_json_types', true); + $this->reloadFixtureAfterTest(); $type = new ArrayAndJsonTypes(); @@ -346,8 +340,6 @@ public function testArrayValues($properties): void public function testRelationViaArray(): void { - $this->checkFixture($this->db(), 'promotion'); - $promotionQuery = new ActiveQuery(Promotion::class); /** @var Promotion[] $promotions */ $promotions = $promotionQuery->with('itemsViaArray')->all(); @@ -375,8 +367,6 @@ public function testRelationViaArray(): void public function testLazzyRelationViaArray(): void { - $this->checkFixture($this->db(), 'item'); - $itemQuery = new ActiveQuery(Item::class); /** @var Item[] $items */ $items = $itemQuery->all(); diff --git a/tests/Driver/Pgsql/ArrayableTraitTest.php b/tests/Driver/Pgsql/ArrayableTraitTest.php index b2ebfbde2..b377412da 100644 --- a/tests/Driver/Pgsql/ArrayableTraitTest.php +++ b/tests/Driver/Pgsql/ArrayableTraitTest.php @@ -9,7 +9,7 @@ final class ArrayableTraitTest extends \Yiisoft\ActiveRecord\Tests\ArrayableTraitTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new PgsqlHelper())->createConnection(); } diff --git a/tests/Driver/Pgsql/BatchQueryResultTest.php b/tests/Driver/Pgsql/BatchQueryResultTest.php index 2af09578f..7837f2391 100644 --- a/tests/Driver/Pgsql/BatchQueryResultTest.php +++ b/tests/Driver/Pgsql/BatchQueryResultTest.php @@ -9,7 +9,7 @@ final class BatchQueryResultTest extends \Yiisoft\ActiveRecord\Tests\BatchQueryResultTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new PgsqlHelper())->createConnection(); } diff --git a/tests/Driver/Pgsql/ConnectionProviderTest.php b/tests/Driver/Pgsql/ConnectionProviderTest.php index 84b67503c..311a0f56d 100644 --- a/tests/Driver/Pgsql/ConnectionProviderTest.php +++ b/tests/Driver/Pgsql/ConnectionProviderTest.php @@ -9,7 +9,7 @@ final class ConnectionProviderTest extends \Yiisoft\ActiveRecord\Tests\ConnectionProviderTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new PgsqlHelper())->createConnection(); } diff --git a/tests/Driver/Pgsql/MagicActiveRecordTest.php b/tests/Driver/Pgsql/MagicActiveRecordTest.php index 90e3ac3f9..e1e20deb6 100644 --- a/tests/Driver/Pgsql/MagicActiveRecordTest.php +++ b/tests/Driver/Pgsql/MagicActiveRecordTest.php @@ -20,14 +20,14 @@ final class MagicActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\MagicActiveRecordTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new PgsqlHelper())->createConnection(); } public function testExplicitPkOnAutoIncrement(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customer = new Customer(); $customer->id = 1337; @@ -46,8 +46,6 @@ public function testExplicitPkOnAutoIncrement(): void */ public function testEagerLoadingUsingStringIdentifiers(): void { - $this->checkFixture($this->db(), 'beta'); - $betaQuery = new ActiveQuery(Beta::class); $betas = $betaQuery->with('alpha')->all(); $this->assertNotEmpty($betas); @@ -66,7 +64,7 @@ public function testEagerLoadingUsingStringIdentifiers(): void public function testBooleanProperty(): void { - $this->checkFixture($this->db(), 'customer', true); + $this->reloadFixtureAfterTest(); $customer = new Customer(); $customer->name = 'boolean customer'; @@ -93,8 +91,6 @@ public function testBooleanProperty(): void public function testBooleanValues(): void { - $this->checkFixture($this->db(), 'bool_values'); - $command = $this->db()->createCommand(); $command->batchInsert('bool_values', ['bool_col'], [[true], [false]])->execute(); $boolARQuery = new ActiveQuery(BoolAR::class); @@ -119,7 +115,7 @@ public function testBooleanValues(): void */ public function testBooleanValues2(): void { - $this->checkFixture($this->db(), 'bool_user'); + $this->reloadFixtureAfterTest(); //$this->db()->setCharset('utf8'); $this->db()->createCommand('DROP TABLE IF EXISTS bool_user;')->execute(); @@ -158,8 +154,6 @@ public function testBooleanValues2(): void public function testBooleanDefaultValues(): void { - $this->checkFixture($this->db(), 'bool_values'); - $arClass = new BoolAR(); $this->assertNull($arClass->bool_col); @@ -176,7 +170,7 @@ public function testBooleanDefaultValues(): void public function testPrimaryKeyAfterSave(): void { - $this->checkFixture($this->db(), 'default_pk'); + $this->reloadFixtureAfterTest(); $record = new DefaultPk(); @@ -262,7 +256,7 @@ public static function arrayValuesProvider(): array */ public function testArrayValues($properties): void { - $this->checkFixture($this->db(), 'array_and_json_types', true); + $this->reloadFixtureAfterTest(); $type = new ArrayAndJsonTypes(); diff --git a/tests/Driver/Pgsql/RepositoryTraitTest.php b/tests/Driver/Pgsql/RepositoryTraitTest.php index b06e7f75f..8a4a90477 100644 --- a/tests/Driver/Pgsql/RepositoryTraitTest.php +++ b/tests/Driver/Pgsql/RepositoryTraitTest.php @@ -9,7 +9,7 @@ final class RepositoryTraitTest extends \Yiisoft\ActiveRecord\Tests\RepositoryTraitTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new PgsqlHelper())->createConnection(); } diff --git a/tests/Driver/Sqlite/ActiveQueryFindTest.php b/tests/Driver/Sqlite/ActiveQueryFindTest.php index 9a3c68215..42f68bf71 100644 --- a/tests/Driver/Sqlite/ActiveQueryFindTest.php +++ b/tests/Driver/Sqlite/ActiveQueryFindTest.php @@ -9,7 +9,7 @@ final class ActiveQueryFindTest extends \Yiisoft\ActiveRecord\Tests\ActiveQueryFindTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new SqliteHelper())->createConnection(); } diff --git a/tests/Driver/Sqlite/ActiveQueryTest.php b/tests/Driver/Sqlite/ActiveQueryTest.php index 651b55946..39d12951a 100644 --- a/tests/Driver/Sqlite/ActiveQueryTest.php +++ b/tests/Driver/Sqlite/ActiveQueryTest.php @@ -9,7 +9,7 @@ final class ActiveQueryTest extends \Yiisoft\ActiveRecord\Tests\ActiveQueryTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new SqliteHelper())->createConnection(); } diff --git a/tests/Driver/Sqlite/ActiveRecordTest.php b/tests/Driver/Sqlite/ActiveRecordTest.php index d47fc396a..59200b6e7 100644 --- a/tests/Driver/Sqlite/ActiveRecordTest.php +++ b/tests/Driver/Sqlite/ActiveRecordTest.php @@ -13,7 +13,7 @@ final class ActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\ActiveRecordTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new SqliteHelper())->createConnection(); } @@ -25,7 +25,7 @@ protected function createFactory(): Factory public function testExplicitPkOnAutoIncrement(): void { - $this->checkFixture($this->db(), 'customer', true); + $this->reloadFixtureAfterTest(); $customer = new Customer(); @@ -46,8 +46,6 @@ public function testExplicitPkOnAutoIncrement(): void */ public function testEagerLoadingUsingStringIdentifiers(): void { - $this->checkFixture($this->db(), 'beta'); - $betaQuery = new ActiveQuery(Beta::class); $betas = $betaQuery->with('alpha')->all(); diff --git a/tests/Driver/Sqlite/ArrayableTraitTest.php b/tests/Driver/Sqlite/ArrayableTraitTest.php index 8f02e00a9..2f3fd25d1 100644 --- a/tests/Driver/Sqlite/ArrayableTraitTest.php +++ b/tests/Driver/Sqlite/ArrayableTraitTest.php @@ -9,7 +9,7 @@ final class ArrayableTraitTest extends \Yiisoft\ActiveRecord\Tests\ArrayableTraitTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new SqliteHelper())->createConnection(); } diff --git a/tests/Driver/Sqlite/BatchQueryResultTest.php b/tests/Driver/Sqlite/BatchQueryResultTest.php index b28642dfa..e4019ba61 100644 --- a/tests/Driver/Sqlite/BatchQueryResultTest.php +++ b/tests/Driver/Sqlite/BatchQueryResultTest.php @@ -9,7 +9,7 @@ final class BatchQueryResultTest extends \Yiisoft\ActiveRecord\Tests\BatchQueryResultTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new SqliteHelper())->createConnection(); } diff --git a/tests/Driver/Sqlite/ConnectionProviderTest.php b/tests/Driver/Sqlite/ConnectionProviderTest.php index 9803721cb..d950798c7 100644 --- a/tests/Driver/Sqlite/ConnectionProviderTest.php +++ b/tests/Driver/Sqlite/ConnectionProviderTest.php @@ -9,7 +9,7 @@ final class ConnectionProviderTest extends \Yiisoft\ActiveRecord\Tests\ConnectionProviderTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new SqliteHelper())->createConnection(); } diff --git a/tests/Driver/Sqlite/MagicActiveRecordTest.php b/tests/Driver/Sqlite/MagicActiveRecordTest.php index a198cda0c..34e3e3c4c 100644 --- a/tests/Driver/Sqlite/MagicActiveRecordTest.php +++ b/tests/Driver/Sqlite/MagicActiveRecordTest.php @@ -12,14 +12,14 @@ final class MagicActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\MagicActiveRecordTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new SqliteHelper())->createConnection(); } public function testExplicitPkOnAutoIncrement(): void { - $this->checkFixture($this->db(), 'customer', true); + $this->reloadFixtureAfterTest(); $customer = new Customer(); @@ -40,8 +40,6 @@ public function testExplicitPkOnAutoIncrement(): void */ public function testEagerLoadingUsingStringIdentifiers(): void { - $this->checkFixture($this->db(), 'beta'); - $betaQuery = new ActiveQuery(Beta::class); $betas = $betaQuery->with('alpha')->all(); diff --git a/tests/Driver/Sqlite/RepositoryTraitTest.php b/tests/Driver/Sqlite/RepositoryTraitTest.php index 63285edd1..fff41cd24 100644 --- a/tests/Driver/Sqlite/RepositoryTraitTest.php +++ b/tests/Driver/Sqlite/RepositoryTraitTest.php @@ -9,7 +9,7 @@ final class RepositoryTraitTest extends \Yiisoft\ActiveRecord\Tests\RepositoryTraitTest { - protected function createConnection(): ConnectionInterface + protected static function createConnection(): ConnectionInterface { return (new SqliteHelper())->createConnection(); } diff --git a/tests/MagicActiveRecordTest.php b/tests/MagicActiveRecordTest.php index 96550a728..55a82dfef 100644 --- a/tests/MagicActiveRecordTest.php +++ b/tests/MagicActiveRecordTest.php @@ -32,7 +32,7 @@ abstract class MagicActiveRecordTest extends TestCase { public function testStoreNull(): void { - $this->checkFixture($this->db(), 'null_values', true); + $this->reloadFixtureAfterTest(); $record = new NullValues(); @@ -80,7 +80,7 @@ public function testStoreNull(): void public function testStoreEmpty(): void { - $this->checkFixture($this->db(), 'null_values'); + $this->reloadFixtureAfterTest(); $record = new NullValues(); @@ -100,8 +100,6 @@ public function testStoreEmpty(): void public function testIsPrimaryKey(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new Customer(); $orderItem = new OrderItem(); @@ -122,8 +120,6 @@ public function testIsPrimaryKey(): void public function testOutdatedRelationsAreResetForNewRecords(): void { - $this->checkFixture($this->db(), 'order_item'); - $orderItem = new OrderItem(); $orderItem->order_id = 1; @@ -146,8 +142,6 @@ public function testOutdatedRelationsAreResetForNewRecords(): void public function testDefaultValues(): void { - $this->checkFixture($this->db(), 'type'); - $arClass = new Type(); $arClass->loadDefaultValues(); @@ -178,12 +172,10 @@ public function testDefaultValues(): void public function testCastValues(): void { - $this->checkFixture($this->db(), 'type'); + $this->reloadFixtureAfterTest(); $arClass = new Type(); - $arClass->deleteAll(); - $arClass->int_col = 123; $arClass->int_col2 = 456; $arClass->smallint_col = 42; @@ -217,7 +209,7 @@ public function testCastValues(): void public function testPopulateRecordCallWhenQueryingOnParentClass(): void { - $this->checkFixture($this->db(), 'cat'); + $this->reloadFixtureAfterTest(); $cat = new Cat(); $cat->save(); @@ -236,7 +228,7 @@ public function testPopulateRecordCallWhenQueryingOnParentClass(): void public function testSaveEmpty(): void { - $this->checkFixture($this->db(), 'null_values', true); + $this->reloadFixtureAfterTest(); $record = new NullValues(); @@ -249,7 +241,7 @@ public function testSaveEmpty(): void */ public function testNoTablenameReplacement(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customer = new Customer(); @@ -272,8 +264,6 @@ public function testNoTablenameReplacement(): void public function testRefreshQuerySetAliasFindRecord(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new CustomerWithAlias(); $customer->id = 1; @@ -284,7 +274,7 @@ public function testRefreshQuerySetAliasFindRecord(): void public function testResetNotSavedRelation(): void { - $this->checkFixture($this->db(), 'order'); + $this->reloadFixtureAfterTest(); $order = new Order(); @@ -305,8 +295,6 @@ public function testResetNotSavedRelation(): void public function testIssetException(): void { - $this->checkFixture($this->db(), 'cat'); - $cat = new Cat(); $this->expectException(Exception::class); @@ -315,8 +303,6 @@ public function testIssetException(): void public function testIssetThrowable(): void { - $this->checkFixture($this->db(), 'cat'); - $cat = new Cat(); $this->expectException(DivisionByZeroError::class); @@ -325,8 +311,6 @@ public function testIssetThrowable(): void public function testIssetNonExisting(): void { - $this->checkFixture($this->db(), 'cat'); - $cat = new Cat(); $this->assertFalse(isset($cat->non_existing)); @@ -335,7 +319,7 @@ public function testIssetNonExisting(): void public function testAssignProperties(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $properties = [ 'email' => 'samdark@mail.ru', @@ -359,8 +343,6 @@ public function testAssignProperties(): void public function testSetNoExistProperty(): void { - $this->checkFixture($this->db(), 'cat'); - $cat = new Cat(); $this->expectException(InvalidArgumentException::class); @@ -373,8 +355,6 @@ public function testSetNoExistProperty(): void public function testAssignOldValue(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new Customer(); $this->assertEmpty($customer->oldValue('name')); @@ -386,8 +366,6 @@ public function testAssignOldValue(): void public function testAssignOldValueException(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new Customer(); $this->assertEmpty($customer->oldValue('name')); @@ -401,8 +379,6 @@ public function testAssignOldValueException(): void public function testIsPropertyChangedNotChanged(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new Customer(); $this->assertEmpty($customer->get('name')); @@ -422,7 +398,7 @@ public function testTableSchemaException(): void public function testInsert(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customer = new Customer(); @@ -446,7 +422,7 @@ public function testInsert(): void */ public function testBooleanProperty(): void { - $this->checkFixture($this->db(), 'customer', true); + $this->reloadFixtureAfterTest(); $customer = new Customer(); @@ -475,8 +451,6 @@ public function testBooleanProperty(): void public function testPropertyAccess(): void { - $this->checkFixture($this->db(), 'customer'); - $arClass = new Customer(); $this->assertTrue($arClass->canSetProperty('name')); @@ -531,8 +505,6 @@ public function testPropertyAccess(): void public function testHasProperty(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new Customer(); $this->assertTrue($customer->hasProperty('id')); @@ -548,8 +520,6 @@ public function testHasProperty(): void public function testRefresh(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new Customer(); $this->assertFalse($customer->refresh()); @@ -564,8 +534,6 @@ public function testRefresh(): void public function testEquals(): void { - $this->checkFixture($this->db(), 'customer'); - $customerA = new Customer(); $customerB = new Customer(); $this->assertFalse($customerA->equals($customerB)); @@ -590,8 +558,7 @@ public static function providerForUnlinkDelete(): array */ public function testUnlinkWithViaOnCondition($delete, $count): void { - $this->checkFixture($this->db(), 'order', true); - $this->checkFixture($this->db(), 'order_item_with_null_fk', true); + $this->reloadFixtureAfterTest(); $orderQuery = new ActiveQuery(Order::class); $order = $orderQuery->findByPk(2); @@ -616,8 +583,6 @@ public function testUnlinkWithViaOnCondition($delete, $count): void public function testVirtualRelation(): void { - $this->checkFixture($this->db(), 'order', true); - $orderQuery = new ActiveQuery(Order::class); /** @var Order $order */ $order = $orderQuery->findByPk(2); @@ -633,8 +598,6 @@ public function testVirtualRelation(): void */ public function testJoinWithEager(): void { - $this->checkFixture($this->db(), 'customer', true); - $customerQuery = new ActiveQuery(Customer::class); $eagerCustomers = $customerQuery->joinWith(['items2'])->all(); $eagerItemsCount = 0; @@ -654,7 +617,7 @@ public function testJoinWithEager(): void public function testSaveWithoutChanges(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customerQuery = new ActiveQuery(Customer::class); @@ -665,8 +628,6 @@ public function testSaveWithoutChanges(): void public function testGetPrimaryKey(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->findByPk(1); @@ -677,8 +638,6 @@ public function testGetPrimaryKey(): void public function testGetOldPrimaryKey(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->findByPk(1); @@ -690,7 +649,7 @@ public function testGetOldPrimaryKey(): void public function testGetDirtyValuesOnNewRecord(): void { - $this->checkFixture($this->db(), 'customer'); + $this->reloadFixtureAfterTest(); $customer = new Customer(); @@ -719,8 +678,6 @@ public function testGetDirtyValuesOnNewRecord(): void public function testGetDirtyValuesAfterFind(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(Customer::class); $customer = $customerQuery->findByPk(1); @@ -742,8 +699,6 @@ public function testGetDirtyValuesAfterFind(): void public function testGetDirtyValuesWithProperties(): void { - $this->checkFixture($this->db(), 'customer'); - $customer = new CustomerWithProperties(); $this->assertSame([ 'name' => null, @@ -772,8 +727,6 @@ public function testGetDirtyValuesWithProperties(): void public function testRelationNames(): void { - $this->checkFixture($this->db(), 'animal'); - $animal = new Animal(); $this->assertEmpty($animal->relationNames()); @@ -802,8 +755,6 @@ public function testRelationNames(): void public function testGetSetMethodsPriority(): void { - $this->checkFixture($this->db(), 'order'); - $datetime = DateTimeImmutable::createFromFormat('U', '1325502201'); $order = new Order(); @@ -815,8 +766,6 @@ public function testGetSetMethodsPriority(): void public function testIsChanged(): void { - $this->checkFixture($this->db(), 'item'); - $itemQuery = new ActiveQuery(Item::class); $item = $itemQuery->findByPk(1); diff --git a/tests/RepositoryTraitTest.php b/tests/RepositoryTraitTest.php index bce4cf5a0..db1ed61d3 100644 --- a/tests/RepositoryTraitTest.php +++ b/tests/RepositoryTraitTest.php @@ -11,8 +11,6 @@ abstract class RepositoryTraitTest extends TestCase { public function testFind(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(new CustomerWithRepositoryTrait()); $this->assertEquals( @@ -23,8 +21,6 @@ public function testFind(): void public function testFindOne(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(new CustomerWithRepositoryTrait()); $this->assertEquals( @@ -35,8 +31,6 @@ public function testFindOne(): void public function testFindAll(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(new CustomerWithRepositoryTrait()); $this->assertEquals( @@ -52,8 +46,6 @@ public function testFindAll(): void public function testFindByPk(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(new CustomerWithRepositoryTrait()); $this->assertEquals( @@ -64,8 +56,6 @@ public function testFindByPk(): void public function testFindBySql(): void { - $this->checkFixture($this->db(), 'customer'); - $customerQuery = new ActiveQuery(new CustomerWithRepositoryTrait()); $this->assertEquals( diff --git a/tests/TestCase.php b/tests/TestCase.php index 0953f364f..2bf16195a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -10,38 +10,57 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { - abstract protected function createConnection(): ConnectionInterface; + private bool $shouldReloadFixture = false; - protected function checkFixture(ConnectionInterface $db, string $tablename, bool $reset = false): void + abstract protected static function createConnection(): ConnectionInterface; + + /** + * Call this method in tests which modifies the database state to reload the connection and fixture after the tests. + */ + protected function reloadFixtureAfterTest(): void + { + $this->shouldReloadFixture = true; + } + + protected static function reloadFixture(): void { - $schema = $db->getSchema(); - $tableSchema = $schema->getTableSchema($tablename, true); + ConnectionProvider::get()->close(); - if ($tableSchema === null || $reset) { - DbHelper::loadFixture($db); + $db = static::createConnection(); + ConnectionProvider::set($db); - $schema->refresh(); - } + DbHelper::loadFixture($db); } - protected function db(): ConnectionInterface + protected static function db(): ConnectionInterface { return ConnectionProvider::get(); } - protected function setUp(): void + public static function setUpBeforeClass(): void { - parent::setUp(); + parent::setUpBeforeClass(); - ConnectionProvider::set($this->createConnection()); + $db = static::createConnection(); + ConnectionProvider::set($db); + DbHelper::loadFixture($db); } protected function tearDown(): void { - parent::tearDown(); + if ($this->shouldReloadFixture) { + $this->reloadFixture(); + $this->shouldReloadFixture = false; + } - $this->db()->close(); + parent::tearDown(); + } + public static function tearDownAfterClass(): void + { + ConnectionProvider::get()->close(); ConnectionProvider::remove(); + + parent::tearDownAfterClass(); } }