From 756825e4faa8733ec1b97717f9dd0f5bbd71c74c Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Fri, 17 Jul 2020 09:33:53 +0430 Subject: [PATCH 01/16] test case improving default db is `mongodb` component in across all application. so no need `getConnection` method in everywhere except in special cases --- tests/ActiveDataProviderTest.php | 6 +- tests/ActiveFixtureTest.php | 23 ++- tests/ActiveRecordTest.php | 22 +-- tests/ActiveRelationTest.php | 8 +- tests/BatchQueryResultTest.php | 26 ++- tests/CacheTest.php | 1 - tests/CollectionTest.php | 52 +++--- tests/CommandTest.php | 75 ++++---- tests/ConnectionTest.php | 33 ++-- tests/DatabaseTest.php | 8 +- tests/LogBuilderTest.php | 2 +- tests/MigrationTest.php | 16 +- tests/QueryRunTest.php | 162 ++++++++---------- tests/SessionTest.php | 1 - tests/TestCase.php | 1 + .../controllers/MigrateControllerTest.php | 14 +- tests/data/ar/ActiveRecord.php | 20 --- tests/data/ar/Animal.php | 2 + tests/data/ar/Customer.php | 1 + tests/data/ar/CustomerOrder.php | 2 + tests/data/ar/Dog.php | 2 + tests/data/ar/Item.php | 2 + tests/data/ar/file/ActiveRecord.php | 19 -- tests/data/ar/file/CustomerFile.php | 3 +- tests/file/ActiveRecordTest.php | 3 +- tests/file/ActiveRelationTest.php | 6 +- tests/file/CollectionTest.php | 18 +- tests/file/DownloadTest.php | 6 +- tests/file/QueryTest.php | 11 +- tests/file/StreamWrapperTest.php | 32 ++-- tests/file/UploadTest.php | 10 +- tests/i18n/MongoDbMessageSourceTest.php | 4 +- tests/log/MongoDbTargetTest.php | 12 +- tests/rbac/MongoDbManagerTest.php | 16 +- 34 files changed, 244 insertions(+), 375 deletions(-) delete mode 100644 tests/data/ar/ActiveRecord.php delete mode 100644 tests/data/ar/file/ActiveRecord.php diff --git a/tests/ActiveDataProviderTest.php b/tests/ActiveDataProviderTest.php index 4d4579641..9f60c4654 100644 --- a/tests/ActiveDataProviderTest.php +++ b/tests/ActiveDataProviderTest.php @@ -5,7 +5,6 @@ use MongoDB\BSON\ObjectID; use yii\data\ActiveDataProvider; use yii\mongodb\Query; -use yiiunit\extensions\mongodb\data\ar\ActiveRecord; use yiiunit\extensions\mongodb\data\ar\Customer; class ActiveDataProviderTest extends TestCase @@ -14,7 +13,6 @@ protected function setUp() { parent::setUp(); $this->mockApplication(); - ActiveRecord::$db = $this->getConnection(); $this->setUpTestRows(); } @@ -29,7 +27,7 @@ protected function tearDown() */ protected function setUpTestRows() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $rows = []; for ($i = 1; $i <= 10; $i++) { $rows[] = [ @@ -51,14 +49,12 @@ public function testQuery() $provider = new ActiveDataProvider([ 'query' => $query, - 'db' => $this->getConnection(), ]); $models = $provider->getModels(); $this->assertEquals(10, count($models)); $provider = new ActiveDataProvider([ 'query' => $query, - 'db' => $this->getConnection(), 'pagination' => [ 'pageSize' => 5, ] diff --git a/tests/ActiveFixtureTest.php b/tests/ActiveFixtureTest.php index b7b58bd74..54a50e999 100644 --- a/tests/ActiveFixtureTest.php +++ b/tests/ActiveFixtureTest.php @@ -32,7 +32,7 @@ public function testLoadCollection() $fixture = $this->getMockBuilder(ActiveFixture::className()) ->setConstructorArgs([ [ - 'db' => $this->getConnection(), + 'db' => yii::$app->mongodb, 'collectionName' => Customer::collectionName() ] ]) @@ -45,7 +45,7 @@ public function testLoadCollection() $fixture->load(); - $rows = $this->findAll($this->getConnection()->getCollection(Customer::collectionName())); + $rows = $this->findAll(yii::$app->mongodb->getCollection(Customer::collectionName())); $this->assertCount(2, $rows); } @@ -55,7 +55,7 @@ public function testLoadClass() $fixture = $this->getMockBuilder(ActiveFixture::className()) ->setConstructorArgs([ [ - 'db' => $this->getConnection(), + 'db' => yii::$app->mongodb, 'collectionName' => Customer::collectionName() ] ]) @@ -68,7 +68,7 @@ public function testLoadClass() $fixture->load(); - $rows = $this->findAll($this->getConnection()->getCollection(Customer::collectionName())); + $rows = $this->findAll(yii::$app->mongodb->getCollection(Customer::collectionName())); $this->assertCount(2, $rows); } @@ -83,7 +83,7 @@ public function testLoadEmptyData() $fixture = $this->getMockBuilder(ActiveFixture::className()) ->setConstructorArgs([ [ - 'db' => $this->getConnection(), + 'db' => yii::$app->mongodb, 'collectionName' => Customer::collectionName() ] ]) @@ -95,7 +95,7 @@ public function testLoadEmptyData() $fixture->load(); // should be no error - $rows = $this->findAll($this->getConnection()->getCollection(Customer::collectionName())); + $rows = $this->findAll(yii::$app->mongodb->getCollection(Customer::collectionName())); $this->assertEmpty($rows); } @@ -106,7 +106,6 @@ public function testLoadEmptyData() */ public function testDefaultDataFile() { - $db = $this->getConnection(); $fixturePath = Yii::getAlias('@runtime/fixtures'); $fixtureDataPath = $fixturePath . DIRECTORY_SEPARATOR . 'data'; @@ -138,29 +137,27 @@ class {$className} extends \yii\mongodb\ActiveFixture ['name' => 'name2'], ['name' => 'name3'], ]; - $fixtureDataFile = $fixtureDataPath . DIRECTORY_SEPARATOR . $db->getDefaultDatabaseName() . '.' . Customer::collectionName() . '.php'; + $fixtureDataFile = $fixtureDataPath . DIRECTORY_SEPARATOR . yii::$app->mongodb->getDefaultDatabaseName() . '.' . Customer::collectionName() . '.php'; $fixtureDataContent = ' $db, 'collectionName' => Customer::collectionName(), ]); $fixture->load(); - $rows = $this->findAll($this->getConnection()->getCollection(Customer::collectionName())); + $rows = $this->findAll(yii::$app->mongodb->getCollection(Customer::collectionName())); $this->assertCount(2, $rows); $fixture = new $className([ - 'db' => $db, 'collectionName' => [ - $db->getDefaultDatabaseName(), + yii::$app->mongodb->getDefaultDatabaseName(), Customer::collectionName() ], ]); $fixture->load(); - $rows = $this->findAll($this->getConnection()->getCollection(Customer::collectionName())); + $rows = $this->findAll(yii::$app->mongodb->getCollection(Customer::collectionName())); $this->assertCount(3, $rows); } } \ No newline at end of file diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php index 7c259d6ed..ecec403f3 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -6,7 +6,6 @@ use MongoDB\BSON\ObjectID; use MongoDB\BSON\Regex; use yii\mongodb\ActiveQuery; -use yiiunit\extensions\mongodb\data\ar\ActiveRecord; use yiiunit\extensions\mongodb\data\ar\Customer; use yiiunit\extensions\mongodb\data\ar\Animal; use yiiunit\extensions\mongodb\data\ar\Dog; @@ -22,7 +21,6 @@ class ActiveRecordTest extends TestCase protected function setUp() { parent::setUp(); - ActiveRecord::$db = $this->getConnection(); $this->setUpTestRows(); } @@ -37,7 +35,7 @@ protected function tearDown() */ protected function setUpTestRows() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $rows = []; for ($i = 1; $i <= 10; $i++) { $rows[] = [ @@ -282,44 +280,42 @@ public function testExists() public function testScalar() { - $connection = $this->getConnection(); $result = Customer::find() ->select(['name' => true, '_id' => false]) ->orderBy(['name' => SORT_ASC]) ->limit(1) - ->scalar($connection); + ->scalar(); $this->assertSame('name1', $result); $result = Customer::find() ->select(['name' => true, '_id' => false]) ->andWhere(['status' => -1]) - ->scalar($connection); + ->scalar(); $this->assertSame(false, $result); $result = Customer::find() ->select(['name']) ->orderBy(['name' => SORT_ASC]) ->limit(1) - ->scalar($connection); + ->scalar(); $this->assertSame('name1', $result); $result = Customer::find() ->select(['_id']) ->limit(1) - ->scalar($connection); + ->scalar(); $this->assertTrue($result instanceof ObjectID); } public function testColumn() { - $connection = $this->getConnection(); $result = Customer::find() ->select(['name' => true, '_id' => false]) ->orderBy(['name' => SORT_ASC]) ->limit(2) - ->column($connection); + ->column(); $this->assertEquals(['name1', 'name10'], $result); $result = Customer::find() @@ -327,21 +323,21 @@ public function testColumn() ->andWhere(['status' => -1]) ->orderBy(['name' => SORT_ASC]) ->limit(2) - ->column($connection); + ->column(); $this->assertEquals([], $result); $result = Customer::find() ->select(['name']) ->orderBy(['name' => SORT_ASC]) ->limit(2) - ->column($connection); + ->column(); $this->assertEquals(['name1', 'name10'], $result); $result = Customer::find() ->select(['_id']) ->orderBy(['name' => SORT_ASC]) ->limit(2) - ->column($connection); + ->column(); $this->assertTrue($result[0] instanceof ObjectID); $this->assertTrue($result[1] instanceof ObjectID); } diff --git a/tests/ActiveRelationTest.php b/tests/ActiveRelationTest.php index 0f2cd9748..45084cbf8 100644 --- a/tests/ActiveRelationTest.php +++ b/tests/ActiveRelationTest.php @@ -2,7 +2,6 @@ namespace yiiunit\extensions\mongodb; -use yiiunit\extensions\mongodb\data\ar\ActiveRecord; use yiiunit\extensions\mongodb\data\ar\Customer; use yiiunit\extensions\mongodb\data\ar\CustomerOrder; use yiiunit\extensions\mongodb\data\ar\Item; @@ -12,7 +11,6 @@ class ActiveRelationTest extends TestCase protected function setUp() { parent::setUp(); - ActiveRecord::$db = $this->getConnection(); $this->setUpTestRows(); } @@ -38,7 +36,7 @@ protected function setUpTestRows() 'status' => $i, ]; } - $customerCollection = $this->getConnection()->getCollection('customer'); + $customerCollection = yii::$app->mongodb->getCollection('customer'); $customers = $customerCollection->batchInsert($customers); $items = []; @@ -48,7 +46,7 @@ protected function setUpTestRows() 'price' => $i, ]; } - $itemCollection = $this->getConnection()->getCollection('item'); + $itemCollection = yii::$app->mongodb->getCollection('item'); $items = $itemCollection->batchInsert($items); $customerOrders = []; @@ -70,7 +68,7 @@ protected function setUpTestRows() ], ]; } - $customerOrderCollection = $this->getConnection()->getCollection('customer_order'); + $customerOrderCollection = yii::$app->mongodb->getCollection('customer_order'); $customerOrderCollection->batchInsert($customerOrders); } diff --git a/tests/BatchQueryResultTest.php b/tests/BatchQueryResultTest.php index af04a3813..e3d39affe 100644 --- a/tests/BatchQueryResultTest.php +++ b/tests/BatchQueryResultTest.php @@ -4,7 +4,6 @@ use yii\mongodb\BatchQueryResult; use yii\mongodb\Query; -use yiiunit\extensions\mongodb\data\ar\ActiveRecord; use yiiunit\extensions\mongodb\data\ar\Customer; use yiiunit\extensions\mongodb\data\ar\CustomerOrder; @@ -13,7 +12,6 @@ class BatchQueryResultTest extends TestCase protected function setUp() { parent::setUp(); - ActiveRecord::$db = $this->getConnection(); $this->setUpTestRows(); } @@ -38,7 +36,7 @@ protected function setUpTestRows() 'status' => $i, ]; } - $customerCollection = $this->getConnection()->getCollection('customer'); + $customerCollection = yii::$app->mongodb->getCollection('customer'); $customers = $customerCollection->batchInsert($customers); $customerOrders = []; @@ -52,7 +50,7 @@ protected function setUpTestRows() 'number' => $customer['status'] + 100, ]; } - $customerOrderCollection = $this->getConnection()->getCollection('customer_order'); + $customerOrderCollection = yii::$app->mongodb->getCollection('customer_order'); $customerOrderCollection->batchInsert($customerOrders); } @@ -60,12 +58,11 @@ protected function setUpTestRows() public function testQuery() { - $db = $this->getConnection(); // initialize property test $query = new Query(); $query->from('customer')->orderBy('id'); - $result = $query->batch(2, $db); + $result = $query->batch(2); $this->assertTrue($result instanceof BatchQueryResult); $this->assertEquals(2, $result->batchSize); $this->assertTrue($result->query === $query); @@ -74,7 +71,7 @@ public function testQuery() $query = new Query(); $query->from('customer'); $allRows = []; - $batch = $query->batch(2, $db); + $batch = $query->batch(2); foreach ($batch as $rows) { $allRows = array_merge($allRows, $rows); } @@ -84,7 +81,7 @@ public function testQuery() $query = new Query(); $query->from('customer')->orderBy('name'); $allRows = []; - $batch = $query->batch(2, $db); + $batch = $query->batch(2); foreach ($batch as $rows) { $allRows = array_merge($allRows, $rows); } @@ -106,7 +103,7 @@ public function testQuery() $query = new Query(); $query->from('customer')->where(['name' => 'unexistingName']); $allRows = []; - $batch = $query->batch(2, $db); + $batch = $query->batch(2); foreach ($batch as $rows) { $allRows = array_merge($allRows, $rows); } @@ -116,7 +113,7 @@ public function testQuery() $query = new Query(); $query->from('customer')->indexBy('name'); $allRows = []; - foreach ($query->batch(2, $db) as $rows) { + foreach ($query->batch(2) as $rows) { $allRows = array_merge($allRows, $rows); } $this->assertEquals(9, count($allRows)); @@ -128,7 +125,7 @@ public function testQuery() $query = new Query(); $query->from('customer')->orderBy('name'); $allRows = []; - foreach ($query->each(100, $db) as $rows) { + foreach ($query->each(100) as $rows) { $allRows[] = $rows; } $this->assertEquals(9, count($allRows)); @@ -140,7 +137,7 @@ public function testQuery() $query = new Query(); $query->from('customer')->orderBy('name')->indexBy('name'); $allRows = []; - foreach ($query->each(100, $db) as $key => $row) { + foreach ($query->each(100) as $key => $row) { $allRows[$key] = $row; } $this->assertEquals(9, count($allRows)); @@ -151,11 +148,10 @@ public function testQuery() public function testActiveQuery() { - $db = $this->getConnection(); $query = Customer::find()->orderBy('id'); $customers = []; - foreach ($query->batch(2, $db) as $models) { + foreach ($query->batch(2) as $models) { $customers = array_merge($customers, $models); } $this->assertEquals(9, count($customers)); @@ -166,7 +162,7 @@ public function testActiveQuery() // batch with eager loading $query = Customer::find()->with('orders')->orderBy('id'); $customers = []; - foreach ($query->batch(2, $db) as $models) { + foreach ($query->batch(2) as $models) { $customers = array_merge($customers, $models); foreach ($models as $model) { $this->assertTrue($model->isRelationPopulated('orders')); diff --git a/tests/CacheTest.php b/tests/CacheTest.php index 16050d511..4f3596172 100644 --- a/tests/CacheTest.php +++ b/tests/CacheTest.php @@ -26,7 +26,6 @@ protected function createCache() { return Yii::createObject([ 'class' => Cache::className(), - 'db' => $this->getConnection(), 'cacheCollection' => static::$cacheCollection, 'gcProbability' => 0, ]); diff --git a/tests/CollectionTest.php b/tests/CollectionTest.php index a18c5330d..f126d9f06 100644 --- a/tests/CollectionTest.php +++ b/tests/CollectionTest.php @@ -19,21 +19,21 @@ protected function tearDown() public function testGetName() { $collectionName = 'customer'; - $collection = $this->getConnection()->getCollection($collectionName); + $collection = yii::$app->mongodb->getCollection($collectionName); $this->assertEquals($collectionName, $collection->name); - $this->assertEquals($this->getConnection()->getDefaultDatabaseName() . '.' . $collectionName, $collection->getFullName()); + $this->assertEquals(yii::$app->mongodb->getDefaultDatabaseName() . '.' . $collectionName, $collection->getFullName()); } public function testFind() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $cursor = $collection->find(); $this->assertTrue($cursor instanceof Cursor); } public function testInsert() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $data = [ 'name' => 'customer 1', 'address' => 'customer 1 address', @@ -49,7 +49,7 @@ public function testInsert() */ public function testFindOne() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $data = [ 'name' => 'customer 1', 'address' => 'customer 1 address', @@ -69,7 +69,7 @@ public function testFindOne() */ public function testFindAll() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $data = [ 'name' => 'customer 1', 'address' => 'customer 1 address', @@ -90,7 +90,7 @@ public function testFindAll() */ public function testBatchInsert() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $rows = [ [ 'name' => 'customer 1', @@ -109,7 +109,7 @@ public function testBatchInsert() public function testSave() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $data = [ 'name' => 'customer 1', 'address' => 'customer 1 address', @@ -124,7 +124,7 @@ public function testSave() */ public function testUpdateBySave() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $data = [ 'name' => 'customer 1', 'address' => 'customer 1 address', @@ -145,7 +145,7 @@ public function testUpdateBySave() */ public function testRemove() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $data = [ 'name' => 'customer 1', 'address' => 'customer 1 address', @@ -165,7 +165,7 @@ public function testRemove() */ public function testRemoveComplexCondition() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $collection->batchInsert([ [ 'name' => 'customer 1', @@ -193,7 +193,7 @@ public function testRemoveComplexCondition() */ public function testUpdate() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $data = [ 'name' => 'customer 1', 'address' => 'customer 1 address', @@ -215,7 +215,7 @@ public function testUpdate() */ public function testGroup() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $rows = [ [ 'name' => 'customer 1', @@ -239,7 +239,7 @@ public function testGroup() public function testFindAndModify() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $rows = [ [ 'name' => 'customer 1', @@ -294,7 +294,7 @@ public function testFindAndModify() */ public function testMapReduce() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $rows = [ [ 'name' => 'customer 1', @@ -327,7 +327,7 @@ public function testMapReduce() ); $this->assertEquals('mapReduceOut', $result); - $outputCollection = $this->getConnection()->getCollection($result); + $outputCollection = yii::$app->mongodb->getCollection($result); $rows = $this->findAll($outputCollection); $expectedRows = [ [ @@ -347,7 +347,7 @@ public function testMapReduce() */ public function testMapReduceInline() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $rows = [ [ 'name' => 'customer 1', @@ -393,7 +393,7 @@ public function testMapReduceInline() public function testCreateIndex() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $columns = [ 'name', 'status' => SORT_DESC @@ -408,7 +408,7 @@ public function testCreateIndex() */ public function testDropIndex() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $collection->createIndex('name'); $this->assertTrue($collection->dropIndex('name')); @@ -425,7 +425,7 @@ public function testDropIndex() */ public function testDropIndexWithPlugin() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $columns = [ 'name' => 'text' @@ -442,7 +442,7 @@ public function testDropIndexWithPlugin() */ public function testDropAllIndexes() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $collection->createIndex('name'); $this->assertEquals(2, $collection->dropAllIndexes()); $indexInfo = $collection->listIndexes(); @@ -451,7 +451,7 @@ public function testDropAllIndexes() public function testCreateIndexes() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $columns = [ ['key' => ['name']], ['key' => ['status' => SORT_DESC]] @@ -466,7 +466,7 @@ public function testCreateIndexes() */ public function testDropIndexes() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $columns = [ [ 'key' => ['name'], @@ -491,7 +491,7 @@ public function testDropIndexes() */ public function testFindByNotObjectId() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $data = [ 'name' => 'customer 1', @@ -516,7 +516,7 @@ public function testFindByNotObjectId() */ public function testInsertMongoBin() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $fileName = __FILE__; $data = [ @@ -534,7 +534,7 @@ public function testInsertMongoBin() */ public function testDistinct() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $rows = [ [ diff --git a/tests/CommandTest.php b/tests/CommandTest.php index d7660d155..7db836a4c 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -16,7 +16,7 @@ protected function tearDown() public function testCreateCollection() { - $command = $this->getConnection()->createCommand(); + $command = yii::$app->mongodb->createCommand(); $this->assertTrue($command->createCollection('customer')); } @@ -25,20 +25,20 @@ public function testCreateCollection() */ public function testDropCollection() { - $command = $this->getConnection()->createCommand(); + $command = yii::$app->mongodb->createCommand(); $command->createCollection('customer'); $this->assertTrue($command->dropCollection('customer')); } public function testCount() { - $command = $this->getConnection()->createCommand(); + $command = yii::$app->mongodb->createCommand(); $this->assertEquals(0, $command->count('customer')); } public function testCreateIndexes() { - $command = $this->getConnection()->createCommand(); + $command = yii::$app->mongodb->createCommand(); $this->assertTrue($command->createIndexes('customer', [ [ 'key' => ['name' => +1], @@ -57,7 +57,7 @@ public function testCreateIndexes() */ public function testListIndexes() { - $command = $this->getConnection()->createCommand(); + $command = yii::$app->mongodb->createCommand(); $command->createIndexes('customer', [ [ 'key' => ['name' => +1], @@ -75,7 +75,7 @@ public function testListIndexes() */ public function testDropIndexes() { - $command = $this->getConnection()->createCommand(); + $command = yii::$app->mongodb->createCommand(); $command->createIndexes('customer', [ [ 'key' => ['name' => +1], @@ -100,7 +100,7 @@ public function testDropIndexes() public function testInsert() { - $command = $this->getConnection()->createCommand(); + $command = yii::$app->mongodb->createCommand(); $insertedId = $command->insert('customer', ['name' => 'John']); $this->assertTrue($insertedId instanceof ObjectID); } @@ -110,7 +110,7 @@ public function testInsert() */ public function testBatchInsert() { - $command = $this->getConnection()->createCommand(); + $command = yii::$app->mongodb->createCommand(); $insertedIds = $command->batchInsert('customer', [ ['name' => 'John'], ['name' => 'Sara'], @@ -124,11 +124,10 @@ public function testBatchInsert() */ public function testUpdate() { - $connection = $this->getConnection(); - $newRecordId = $connection->createCommand()->insert('customer', ['name' => 'John']); + $newRecordId = yii::$app->mongodb->createCommand()->insert('customer', ['name' => 'John']); - $result = $connection->createCommand()->update('customer', ['_id' => $newRecordId], ['name' => 'Mike']); + $result = yii::$app->mongodb->createCommand()->update('customer', ['_id' => $newRecordId], ['name' => 'Mike']); $this->assertEquals(1, $result->getModifiedCount()); } @@ -138,11 +137,10 @@ public function testUpdate() */ public function testDelete() { - $connection = $this->getConnection(); - $newRecordId = $connection->createCommand()->insert('customer', ['name' => 'John']); + $newRecordId = yii::$app->mongodb->createCommand()->insert('customer', ['name' => 'John']); - $result = $connection->createCommand()->delete('customer', ['_id' => $newRecordId]); + $result = yii::$app->mongodb->createCommand()->delete('customer', ['_id' => $newRecordId]); $this->assertEquals(1, $result->getDeletedCount()); } @@ -152,11 +150,10 @@ public function testDelete() */ public function testFind() { - $connection = $this->getConnection(); - $connection->createCommand()->insert('customer', ['name' => 'John']); + yii::$app->mongodb->createCommand()->insert('customer', ['name' => 'John']); - $cursor = $connection->createCommand()->find('customer', []); + $cursor = yii::$app->mongodb->createCommand()->find('customer', []); $rows = $cursor->toArray(); $this->assertCount(1, $rows); $this->assertEquals('John', $rows[0]['name']); @@ -167,7 +164,6 @@ public function testFind() */ public function testFindAndModify() { - $connection = $this->getConnection(); $rows = [ [ 'name' => 'customer 1', @@ -180,20 +176,20 @@ public function testFindAndModify() 'amount' => 200, ], ]; - $command = $connection->createCommand(); + $command = yii::$app->mongodb->createCommand(); $command->batchInsert('customer', $rows); // increment field - $result = $connection->createCommand()->findAndModify('customer', ['name' => 'customer 1'], ['$inc' => ['status' => 1]]); + $result = yii::$app->mongodb->createCommand()->findAndModify('customer', ['name' => 'customer 1'], ['$inc' => ['status' => 1]]); $this->assertEquals('customer 1', $result['name']); $this->assertEquals(1, $result['status']); - $cursor = $connection->createCommand()->find('customer', ['name' => 'customer 1']); + $cursor = yii::$app->mongodb->createCommand()->find('customer', ['name' => 'customer 1']); $newResult = current($cursor->toArray()); $this->assertEquals(2, $newResult['status']); // $set and return modified document - $result = $connection->createCommand()->findAndModify( + $result = yii::$app->mongodb->createCommand()->findAndModify( 'customer', ['name' => 'customer 2'], ['$set' => ['status' => 2]], @@ -207,7 +203,7 @@ public function testFindAndModify() 'name' => 'customer 3', 'city' => 'Minsk' ]; - $result = $connection->createCommand()->findAndModify( + $result = yii::$app->mongodb->createCommand()->findAndModify( 'customer', ['name' => 'customer 2'], $data, @@ -219,7 +215,7 @@ public function testFindAndModify() // Test exceptions $this->expectException('\yii\mongodb\Exception'); - $connection->createCommand()->findAndModify('customer',['name' => 'customer 1'], ['$wrongOperator' => ['status' => 1]]); + yii::$app->mongodb->createCommand()->findAndModify('customer',['name' => 'customer 1'], ['$wrongOperator' => ['status' => 1]]); } /** @@ -227,7 +223,6 @@ public function testFindAndModify() */ public function testAggregate() { - $connection = $this->getConnection(); $rows = [ [ 'name' => 'customer 1', @@ -240,7 +235,7 @@ public function testAggregate() 'amount' => 200, ], ]; - $command = $connection->createCommand(); + $command = yii::$app->mongodb->createCommand(); $command->batchInsert('customer', $rows); $pipelines = [ @@ -256,7 +251,7 @@ public function testAggregate() ] ] ]; - $result = $connection->createCommand()->aggregate('customer', $pipelines); + $result = yii::$app->mongodb->createCommand()->aggregate('customer', $pipelines); $this->assertEquals(['_id' => '1', 'total' => 300], $result[0]); } @@ -268,7 +263,6 @@ public function testAggregate() */ public function testAggregateCursor() { - $connection = $this->getConnection(); $rows = [ [ 'name' => 'customer 1', @@ -291,7 +285,7 @@ public function testAggregateCursor() 'amount' => 200, ], ]; - $command = $connection->createCommand(); + $command = yii::$app->mongodb->createCommand(); $command->batchInsert('customer', $rows); $pipelines = [ @@ -307,7 +301,7 @@ public function testAggregateCursor() ] ] ]; - $result = $connection->createCommand()->aggregate('customer', $pipelines, ['cursor' => ['batchSize' => 2]]); + $result = yii::$app->mongodb->createCommand()->aggregate('customer', $pipelines, ['cursor' => ['batchSize' => 2]]); $this->assertTrue($result instanceof Cursor); $this->assertEquals(['_id' => '1', 'total' => 600], $result->toArray()[0]); @@ -318,11 +312,10 @@ public function testAggregateCursor() */ public function testExplain() { - $connection = $this->getConnection(); - $connection->createCommand()->insert('customer', ['name' => 'John']); + yii::$app->mongodb->createCommand()->insert('customer', ['name' => 'John']); - $result = $connection->createCommand()->explain('customer', [ + $result = yii::$app->mongodb->createCommand()->explain('customer', [ 'filter' => [ 'name' => 'John' ], @@ -337,11 +330,10 @@ public function testExplain() */ public function testListCollections() { - $connection = $this->getConnection(); - $connection->createCommand()->createCollection('customer'); + yii::$app->mongodb->createCommand()->createCollection('customer'); - $collections = $connection->createCommand()->listCollections(); + $collections = yii::$app->mongodb->createCommand()->listCollections(); $collectionNames = ArrayHelper::getColumn($collections, 'name'); $this->assertContains('customer', $collectionNames); } @@ -354,22 +346,21 @@ public function testListCollections() */ public function testUpdateUpsert() { - $connection = $this->getConnection(); - $connection->createCommand()->insert('customer', ['name' => 'John']); + yii::$app->mongodb->createCommand()->insert('customer', ['name' => 'John']); - $result = $connection->createCommand() + $result = yii::$app->mongodb->createCommand() ->update('customer', ['name' => 'Mike'], ['name' => 'Jack']); $this->assertEquals(0, $result->getModifiedCount()); $this->assertEquals(0, $result->getUpsertedCount()); - $this->assertEquals(1, $connection->createCommand()->count('customer')); + $this->assertEquals(1, yii::$app->mongodb->createCommand()->count('customer')); - $result = $connection->createCommand() + $result = yii::$app->mongodb->createCommand() ->update('customer', ['name' => 'Mike'], ['name' => 'Jack'], ['upsert' => true]); $this->assertEquals(0, $result->getModifiedCount()); $this->assertEquals(1, $result->getUpsertedCount()); - $this->assertEquals(2, $connection->createCommand()->count('customer')); + $this->assertEquals(2, yii::$app->mongodb->createCommand()->count('customer')); } } \ No newline at end of file diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index a3665a662..c5bfa054b 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -46,17 +46,16 @@ public function testOpenClose() public function testGetDatabase() { - $connection = $this->getConnection(); - $database = $connection->getDatabase($connection->defaultDatabaseName); + $database = yii::$app->mongodb->getDatabase(yii::$app->mongodb->defaultDatabaseName); $this->assertTrue($database instanceof Database); - $this->assertSame($connection, $database->connection); - $this->assertSame($connection->defaultDatabaseName, $database->name); + $this->assertSame(yii::$app->mongodb, $database->connection); + $this->assertSame(yii::$app->mongodb->defaultDatabaseName, $database->name); - $database2 = $connection->getDatabase($connection->defaultDatabaseName); + $database2 = yii::$app->mongodb->getDatabase(yii::$app->mongodb->defaultDatabaseName); $this->assertTrue($database === $database2); - $databaseRefreshed = $connection->getDatabase($connection->defaultDatabaseName, true); + $databaseRefreshed = yii::$app->mongodb->getDatabase(yii::$app->mongodb->defaultDatabaseName, true); $this->assertFalse($database === $databaseRefreshed); } @@ -110,15 +109,14 @@ public function testGetDefaultDatabase() */ public function testGetCollection() { - $connection = $this->getConnection(); - $collection = $connection->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $this->assertTrue($collection instanceof Collection); - $collection2 = $connection->getCollection('customer'); + $collection2 = yii::$app->mongodb->getCollection('customer'); $this->assertTrue($collection === $collection2); - $collection2 = $connection->getCollection('customer', true); + $collection2 = yii::$app->mongodb->getCollection('customer', true); $this->assertFalse($collection === $collection2); } @@ -127,31 +125,28 @@ public function testGetCollection() */ public function testGetFileCollection() { - $connection = $this->getConnection(); - $collection = $connection->getFileCollection('testfs'); + $collection = yii::$app->mongodb->getFileCollection('testfs'); $this->assertTrue($collection instanceof FileCollection); - $collection2 = $connection->getFileCollection('testfs'); + $collection2 = yii::$app->mongodb->getFileCollection('testfs'); $this->assertTrue($collection === $collection2); - $collection2 = $connection->getFileCollection('testfs', true); + $collection2 = yii::$app->mongodb->getFileCollection('testfs', true); $this->assertFalse($collection === $collection2); } public function testGetQueryBuilder() { - $connection = $this->getConnection(); - $this->assertTrue($connection->getQueryBuilder() instanceof QueryBuilder); + $this->assertTrue(yii::$app->mongodb->getQueryBuilder() instanceof QueryBuilder); } public function testCreateCommand() { - $connection = $this->getConnection(); - $command = $connection->createCommand(); + $command = yii::$app->mongodb->createCommand(); $this->assertTrue($command instanceof Command); - $this->assertSame($connection, $command->db); + $this->assertSame(yii::$app->mongodb, $command->db); } } diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 35700bb29..8674dd815 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -19,7 +19,7 @@ protected function tearDown() public function testGetCollection() { - $database = $this->getConnection()->getDatabase(); + $database = yii::$app->mongodb->getDatabase(); $collection = $database->getCollection('customer'); $this->assertTrue($collection instanceof Collection); @@ -34,7 +34,7 @@ public function testGetCollection() public function testGetFileCollection() { - $database = $this->getConnection()->getDatabase(); + $database = yii::$app->mongodb->getDatabase(); $collection = $database->getFileCollection('testfs'); $this->assertTrue($collection instanceof FileCollection); @@ -49,7 +49,7 @@ public function testGetFileCollection() public function testCreateCommand() { - $database = $this->getConnection()->getDatabase(); + $database = yii::$app->mongodb->getDatabase(); $command = $database->createCommand(); $this->assertTrue($command instanceof Command); @@ -58,7 +58,7 @@ public function testCreateCommand() public function testCreateCollection() { - $database = $this->getConnection()->getDatabase(); + $database = yii::$app->mongodb->getDatabase(); $this->assertTrue($database->createCollection('customer')); } } diff --git a/tests/LogBuilderTest.php b/tests/LogBuilderTest.php index 08b9c9b29..540d478bd 100644 --- a/tests/LogBuilderTest.php +++ b/tests/LogBuilderTest.php @@ -37,7 +37,7 @@ public function dataProviderEncodeData() */ public function testEncodeData($data, $expectedResult) { - $logBuilder = $this->getConnection()->getLogBuilder(); + $logBuilder = yii::$app->mongodb->getLogBuilder(); $this->assertTrue(strcasecmp($expectedResult, $logBuilder->encodeData($data)) === 0); } } \ No newline at end of file diff --git a/tests/MigrationTest.php b/tests/MigrationTest.php index a14a8fb51..f7438bb34 100644 --- a/tests/MigrationTest.php +++ b/tests/MigrationTest.php @@ -12,19 +12,11 @@ protected function tearDown() parent::tearDown(); } - /** - * @return Migration migration instance. - */ - protected function createMigration() - { - return new Migration(['db' => $this->getConnection()]); - } - // Tests : public function testCollectionOperations() { - $migration = $this->createMigration(); + $migration = new Migration; $migration->createCollection('customer'); $this->assertNotEmpty($migration->db->getDatabase()->listCollections(['name' => 'customer'])); @@ -35,7 +27,7 @@ public function testCollectionOperations() public function testIndexOperations() { - $migration = $this->createMigration(); + $migration = new Migration; $migration->createIndexes('customer', [ ['key' => 'name'] @@ -58,7 +50,7 @@ public function testIndexOperations() public function testDataOperations() { - $migration = $this->createMigration(); + $migration = new Migration; $id = $migration->insert('customer', ['name' => 'John Doe']); $this->assertTrue($id instanceof ObjectID); @@ -85,7 +77,7 @@ public function testDataOperations() */ public function testCommandOutput() { - $migration = $this->createMigration(); + $migration = new Migration; $migration->compact = false; $migration->createCollection('customer'); diff --git a/tests/QueryRunTest.php b/tests/QueryRunTest.php index c3a97616f..770c2fdb1 100644 --- a/tests/QueryRunTest.php +++ b/tests/QueryRunTest.php @@ -24,7 +24,7 @@ protected function tearDown() */ protected function setUpTestRows() { - $collection = $this->getConnection()->getCollection('customer'); + $collection = yii::$app->mongodb->getCollection('customer'); $rows = []; for ($i = 1; $i <= 10; $i++) { $rows[] = [ @@ -46,43 +46,39 @@ protected function setUpTestRows() public function testAll() { - $connection = $this->getConnection(); $query = new Query(); - $rows = $query->from('customer')->all($connection); + $rows = $query->from('customer')->all(); $this->assertEquals(10, count($rows)); } public function testDirectMatch() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->where(['name' => 'name1']) - ->all($connection); + ->all(); $this->assertEquals(1, count($rows)); $this->assertEquals('name1', $rows[0]['name']); } public function testIndexBy() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->indexBy('name') - ->all($connection); + ->all(); $this->assertEquals(10, count($rows)); $this->assertNotEmpty($rows['name1']); } public function testInCondition() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->where([ 'name' => ['name1', 'name5'] ]) - ->all($connection); + ->all(); $this->assertEquals(2, count($rows)); $this->assertEquals('name1', $rows[0]['name']); $this->assertEquals('name5', $rows[1]['name']); @@ -90,18 +86,17 @@ public function testInCondition() public function testNotInCondition() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->where(['not in', 'name', ['name1', 'name5']]) - ->all($connection); + ->all(); $this->assertEquals(8, count($rows)); $query = new Query(); $rows = $query->from('customer') ->where(['not in', 'name', ['name1']]) - ->all($connection); + ->all(); $this->assertEquals(9, count($rows)); } @@ -110,7 +105,6 @@ public function testNotInCondition() */ public function testCompositeInCondition() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->where([ @@ -122,7 +116,7 @@ public function testCompositeInCondition() ['status' => 5, 'name' => 'name7'], ] ]) - ->all($connection); + ->all(); $this->assertEquals(2, count($rows)); $this->assertEquals('name1', $rows[0]['name']); $this->assertEquals('name3', $rows[1]['name']); @@ -130,12 +124,11 @@ public function testCompositeInCondition() public function testOrCondition() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->where(['name' => 'name1']) ->orWhere(['address' => 'address5']) - ->all($connection); + ->all(); $this->assertEquals(2, count($rows)); $this->assertEquals('name1', $rows[0]['name']); $this->assertEquals('address5', $rows[1]['address']); @@ -143,21 +136,19 @@ public function testOrCondition() public function testCombinedInAndCondition() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->where([ 'name' => ['name1', 'name5'] ]) ->andWhere(['name' => 'name1']) - ->all($connection); + ->all(); $this->assertEquals(1, count($rows)); $this->assertEquals('name1', $rows[0]['name']); } public function testCombinedInLikeAndCondition() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->where([ @@ -165,14 +156,13 @@ public function testCombinedInLikeAndCondition() ]) ->andWhere(['LIKE', 'name', 'me1']) ->andWhere(['name' => 'name10']) - ->all($connection); + ->all(); $this->assertEquals(1, count($rows)); $this->assertEquals('name10', $rows[0]['name']); } public function testNestedCombinedInAndCondition() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->where([ @@ -185,7 +175,7 @@ public function testNestedCombinedInAndCondition() ['name' => ['name4', 'name5', 'name6']], ['name' => 'name6'] ]) - ->all($connection); + ->all(); $this->assertEquals(2, count($rows)); $this->assertEquals('name1', $rows[0]['name']); $this->assertEquals('name6', $rows[1]['name']); @@ -193,40 +183,37 @@ public function testNestedCombinedInAndCondition() public function testOrder() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->orderBy(['name' => SORT_DESC]) - ->all($connection); + ->all(); $this->assertEquals('name9', $rows[0]['name']); $query = new Query(); $rows = $query->from('customer') ->orderBy(['avatar.height' => SORT_DESC]) - ->all($connection); + ->all(); $this->assertEquals('name10', $rows[0]['name']); } public function testMatchPlainId() { - $connection = $this->getConnection(); $query = new Query(); - $row = $query->from('customer')->one($connection); + $row = $query->from('customer')->one(); $query = new Query(); $rows = $query->from('customer') ->where(['_id' => $row['_id']->__toString()]) - ->all($connection); + ->all(); $this->assertEquals(1, count($rows)); } public function testRegex() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->where(['REGEX', 'name', '/me1/']) - ->all($connection); + ->all(); $this->assertEquals(2, count($rows)); $this->assertEquals('name1', $rows[0]['name']); $this->assertEquals('name10', $rows[1]['name']); @@ -234,12 +221,11 @@ public function testRegex() public function testLike() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->where(['LIKE', 'name', 'me1']) - ->all($connection); + ->all(); $this->assertEquals(2, count($rows)); $this->assertEquals('name1', $rows[0]['name']); $this->assertEquals('name10', $rows[1]['name']); @@ -247,76 +233,72 @@ public function testLike() $query = new Query(); $rowsUppercase = $query->from('customer') ->where(['LIKE', 'name', 'ME1']) - ->all($connection); + ->all(); $this->assertEquals($rows, $rowsUppercase); } public function testCompare() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->where(['$gt', 'status', 8]) - ->all($connection); + ->all(); $this->assertEquals(2, count($rows)); $query = new Query(); $rows = $query->from('customer') ->where(['>', 'status', 8]) - ->all($connection); + ->all(); $this->assertEquals(2, count($rows)); $query = new Query(); $rows = $query->from('customer') ->where(['<=', 'status', 3]) - ->all($connection); + ->all(); $this->assertEquals(3, count($rows)); } public function testNot() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->where(['not', 'status', ['$gte' => 10]]) - ->all($connection); + ->all(); $this->assertEquals(9, count($rows)); $query = new Query(); $rows = $query->from('customer') ->where(['not', 'name', 'name1']) - ->all($connection); + ->all(); $this->assertEquals(9, count($rows)); $query = new Query(); $rows = $query->from('customer') ->where(['not', 'name', null]) - ->all($connection); + ->all(); $this->assertEquals(10, count($rows)); } public function testExists() { - $connection = $this->getConnection(); $query = new Query(); $exists = $query->from('customer') ->where(['name' => 'name1']) - ->exists($connection); + ->exists(); $this->assertTrue($exists); $query = new Query(); $exists = $query->from('customer') ->where(['name' => 'un-existing-name']) - ->exists($connection); + ->exists(); $this->assertFalse($exists); } public function testModify() { - $connection = $this->getConnection(); $query = new Query(); @@ -324,19 +306,19 @@ public function testModify() $newName = 'new name'; $row = $query->from('customer') ->where(['name' => $searchName]) - ->modify(['$set' => ['name' => $newName]], ['new' => false], $connection); + ->modify(['$set' => ['name' => $newName]], ['new' => false]); $this->assertEquals($searchName, $row['name']); $searchName = 'name7'; $newName = 'new name'; $row = $query->from('customer') ->where(['name' => $searchName]) - ->modify(['$set' => ['name' => $newName]], ['new' => true], $connection); + ->modify(['$set' => ['name' => $newName]], ['new' => true]); $this->assertEquals($newName, $row['name']); $row = $query->from('customer') ->where(['name' => 'not existing name']) - ->modify(['$set' => ['name' => 'new name']], ['new' => false], $connection); + ->modify(['$set' => ['name' => 'new name']], ['new' => false]); $this->assertNull($row); } @@ -348,7 +330,6 @@ public function testModify() */ public function testInConditionIgnoreKeys() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') /*->where([ @@ -361,7 +342,7 @@ public function testInConditionIgnoreKeys() 10 => 'name1', 15 => 'name5' ]]) - ->all($connection); + ->all(); $this->assertEquals(2, count($rows)); $this->assertEquals('name1', $rows[0]['name']); $this->assertEquals('name5', $rows[1]['name']); @@ -373,7 +354,7 @@ public function testInConditionIgnoreKeys() 10 => $rows[0]['_id'], 15 => $rows[1]['_id'] ]]) - ->all($connection); + ->all(); $this->assertEquals(2, count($rows)); } @@ -382,12 +363,11 @@ public function testInConditionIgnoreKeys() */ public function testSelect() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('customer') ->select(['name' => true, '_id' => false]) ->limit(1) - ->all($connection); + ->all(); $row = array_pop($rows); $this->assertArrayHasKey('name', $row); $this->assertArrayNotHasKey('address', $row); @@ -396,21 +376,20 @@ public function testSelect() public function testScalar() { - $connection = $this->getConnection(); $result = (new Query()) ->select(['name' => true, '_id' => false]) ->from('customer') ->orderBy(['name' => SORT_ASC]) ->limit(1) - ->scalar($connection); + ->scalar(); $this->assertSame('name1', $result); $result = (new Query()) ->select(['name' => true, '_id' => false]) ->from('customer') ->andWhere(['status' => -1]) - ->scalar($connection); + ->scalar(); $this->assertSame(false, $result); $result = (new Query()) @@ -418,26 +397,25 @@ public function testScalar() ->from('customer') ->orderBy(['name' => SORT_ASC]) ->limit(1) - ->scalar($connection); + ->scalar(); $this->assertSame('name1', $result); $result = (new Query()) ->select(['_id']) ->from('customer') ->limit(1) - ->scalar($connection); + ->scalar(); $this->assertTrue($result instanceof ObjectID); } public function testColumn() { - $connection = $this->getConnection(); $result = (new Query())->from('customer') ->select(['name' => true, '_id' => false]) ->orderBy(['name' => SORT_ASC]) ->limit(2) - ->column($connection); + ->column(); $this->assertEquals(['name1', 'name10'], $result); $result = (new Query())->from('customer') @@ -445,21 +423,21 @@ public function testColumn() ->andWhere(['status' => -1]) ->orderBy(['name' => SORT_ASC]) ->limit(2) - ->column($connection); + ->column(); $this->assertEquals([], $result); $result = (new Query())->from('customer') ->select(['name']) ->orderBy(['name' => SORT_ASC]) ->limit(2) - ->column($connection); + ->column(); $this->assertEquals(['name1', 'name10'], $result); $result = (new Query())->from('customer') ->select(['_id']) ->orderBy(['name' => SORT_ASC]) ->limit(2) - ->column($connection); + ->column(); $this->assertTrue($result[0] instanceof ObjectID); $this->assertTrue($result[1] instanceof ObjectID); } @@ -469,14 +447,13 @@ public function testColumn() */ public function testColumnIndexBy() { - $connection = $this->getConnection(); $result = (new Query())->from('customer') ->select(['name']) ->orderBy(['name' => SORT_ASC]) ->limit(2) ->indexBy('status') - ->column($connection); + ->column(); $this->assertEquals([1 => 'name1', 10 => 'name10'], $result); $result = (new Query())->from('customer') @@ -486,7 +463,7 @@ public function testColumnIndexBy() ->indexBy(function ($row) { return $row['status'] * 2; }) - ->column($connection); + ->column(); $this->assertEquals([2 => 'name1', 20 => 'name10'], $result); $result = (new Query())->from('customer') @@ -494,7 +471,7 @@ public function testColumnIndexBy() ->orderBy(['name' => SORT_ASC]) ->limit(2) ->indexBy('name') - ->column($connection); + ->column(); $this->assertEquals(['name1' => 'name1', 'name10' => 'name10'], $result); } @@ -505,84 +482,82 @@ public function testEmulateExecution() $this->markTestSkipped('"yii2" version 2.0.11 or higher required'); } - $db = $this->getConnection(); - - $this->assertGreaterThan(0, $query->from('customer')->count('*', $db)); + $this->assertGreaterThan(0, $query->from('customer')->count()); $rows = (new Query()) ->from('customer') ->emulateExecution() - ->all($db); + ->all(); $this->assertSame([], $rows); $row = (new Query()) ->from('customer') ->emulateExecution() - ->one($db); + ->one(); $this->assertSame(false, $row); $exists = (new Query()) ->from('customer') ->emulateExecution() - ->exists($db); + ->exists(); $this->assertSame(false, $exists); $count = (new Query()) ->from('customer') ->emulateExecution() - ->count('*', $db); + ->count(); $this->assertSame(0, $count); $sum = (new Query()) ->from('customer') ->emulateExecution() - ->sum('id', $db); + ->sum('id'); $this->assertSame(0, $sum); $sum = (new Query()) ->from('customer') ->emulateExecution() - ->average('id', $db); + ->average('id'); $this->assertSame(0, $sum); $max = (new Query()) ->from('customer') ->emulateExecution() - ->max('id', $db); + ->max('id'); $this->assertSame(null, $max); $min = (new Query()) ->from('customer') ->emulateExecution() - ->min('id', $db); + ->min('id'); $this->assertSame(null, $min); $scalar = (new Query()) ->select(['id']) ->from('customer') ->emulateExecution() - ->scalar($db); + ->scalar(); $this->assertSame(null, $scalar); $column = (new Query()) ->select(['id']) ->from('customer') ->emulateExecution() - ->column($db); + ->column(); $this->assertSame([], $column); $row = (new Query()) ->select(['id']) ->from('customer') ->emulateExecution() - ->modify(['name' => 'new name'], [], $db); + ->modify(['name' => 'new name']); $this->assertSame(null, $row); $values = (new Query()) ->select(['id']) ->from('customer') ->emulateExecution() - ->distinct('name', $db); + ->distinct('name'); $this->assertSame([], $values); } @@ -593,18 +568,17 @@ public function testEmulateExecution() */ public function testOffsetLimit() { - $db = $this->getConnection(); $rows = (new Query()) ->from('customer') ->limit(2) - ->all($db); + ->all(); $this->assertCount(2, $rows); $rows = (new Query()) ->from('customer') ->limit(-1) - ->all($db); + ->all(); $this->assertCount(10, $rows); $rows = (new Query()) @@ -612,7 +586,7 @@ public function testOffsetLimit() ->orderBy(['name' => SORT_ASC]) ->offset(2) ->limit(1) - ->all($db); + ->all(); $this->assertCount(1, $rows); $this->assertEquals('name2', $rows[0]['name']); @@ -621,54 +595,52 @@ public function testOffsetLimit() ->orderBy(['name' => SORT_ASC]) ->offset(-1) ->limit(1) - ->all($db); + ->all(); $this->assertCount(1, $rows); $this->assertEquals('name1', $rows[0]['name']); } public function testDistinct() { - $db = $this->getConnection(); $rows = (new Query()) ->from('customer') - ->distinct('group', $db); + ->distinct('group'); $this->assertSame(['odd', 'even'], $rows); } public function testAggregationShortcuts() { - $db = $this->getConnection(); $max = (new Query()) ->from('customer') ->where(['group' => 'odd']) - ->count('*', $db); + ->count(); $this->assertSame(5, $max); $max = (new Query()) ->from('customer') ->where(['group' => 'even']) - ->max('status', $db); + ->max('status'); $this->assertSame(10, $max); $max = (new Query()) ->from('customer') ->where(['group' => 'even']) - ->min('status', $db); + ->min('status'); $this->assertSame(2, $max); $max = (new Query()) ->from('customer') ->where(['group' => 'even']) - ->sum('status', $db); + ->sum('status'); $this->assertSame(30, $max); $max = (new Query()) ->from('customer') ->where(['group' => 'even']) - ->average('status', $db); + ->average('status'); $this->assertEquals(6, $max); } } \ No newline at end of file diff --git a/tests/SessionTest.php b/tests/SessionTest.php index b1f8e5173..77c4c68e5 100755 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -26,7 +26,6 @@ protected function createSession() { return Yii::createObject([ 'class' => Session::className(), - 'db' => $this->getConnection(), 'sessionCollection' => static::$sessionCollection, ]); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 7c876e453..b3ffea853 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -34,6 +34,7 @@ protected function setUp() if (!empty($config)) { $this->mongoDbConfig = $config; } + Yii::$app->setComponents(['mongodb' => $this->getConnection()]); //$this->mockApplication(); } diff --git a/tests/console/controllers/MigrateControllerTest.php b/tests/console/controllers/MigrateControllerTest.php index 44b821c2e..6af87285a 100644 --- a/tests/console/controllers/MigrateControllerTest.php +++ b/tests/console/controllers/MigrateControllerTest.php @@ -49,7 +49,6 @@ public function setUp() $this->setUpMigrationPath(); $this->mockApplication(); - Yii::$app->setComponents(['mongodb' => $this->getConnection()]); } public function tearDown() @@ -57,7 +56,7 @@ public function tearDown() parent::tearDown(); if (extension_loaded('mongodb')) { try { - $this->getConnection()->getCollection('migration')->drop(); + yii::$app->mongodb->getCollection('migration')->drop(); } catch (Exception $e) { // shutdown exception } @@ -501,7 +500,6 @@ public function testNamespaceTo() */ public function testGetMigrationHistory() { - $connection = $this->getConnection(); $controllerConfig = [ 'migrationPath' => null, @@ -509,9 +507,9 @@ public function testGetMigrationHistory() ]; $controller = $this->createMigrateController($controllerConfig); - $controller->db = $this->getConnection(); + $controller->db = yii::$app->mongodb; - $connection->createCommand()->batchInsert('migration', [ + yii::$app->mongodb->createCommand()->batchInsert('migration', [ [ 'version' => 'app\migrations\M140506102106One', 'apply_time' => 10, @@ -574,9 +572,7 @@ public function testRefreshMigration() $this->markTestSkipped('Method "yii\console\controllers\BaseMigrateController::actionFresh()" does not exist in this Yii framework version.'); } - $connection = $this->getConnection(); - - $collection = $connection->getCollection('hall_of_fame'); + $collection = yii::$app->mongodb->getCollection('hall_of_fame'); $collection->insert(['name' => 'Qiang Xue']); $collection->insert(['name' => 'Alexander Makarov']); @@ -585,6 +581,6 @@ public function testRefreshMigration() $this->assertContains('Collection hall_of_fame dropped.', $result); $this->assertContains('No new migrations found. Your system is up-to-date.', $result); - $this->assertEmpty($connection->getDatabase()->listCollections(['name' => $collection->name])); + $this->assertEmpty(yii::$app->mongodb->getDatabase()->listCollections(['name' => $collection->name])); } } \ No newline at end of file diff --git a/tests/data/ar/ActiveRecord.php b/tests/data/ar/ActiveRecord.php deleted file mode 100644 index 7229ea957..000000000 --- a/tests/data/ar/ActiveRecord.php +++ /dev/null @@ -1,20 +0,0 @@ -getConnection(); $this->dropFileCollection(CustomerFile::collectionName()); $this->setUpTestRows(); $filePath = $this->getTestFilePath(); @@ -55,7 +54,7 @@ protected function getTestFilePath() */ protected function setUpTestRows() { - $collection = $this->getConnection()->getFileCollection(CustomerFile::collectionName()); + $collection = yii::$app->mongodb->getFileCollection(CustomerFile::collectionName()); $rows = []; for ($i = 1; $i <= 10; $i++) { $record = [ diff --git a/tests/file/ActiveRelationTest.php b/tests/file/ActiveRelationTest.php index 9c5eb47ed..dcb9d74d1 100644 --- a/tests/file/ActiveRelationTest.php +++ b/tests/file/ActiveRelationTest.php @@ -14,8 +14,6 @@ class ActiveRelationTest extends TestCase protected function setUp() { parent::setUp(); - \yiiunit\extensions\mongodb\data\ar\ActiveRecord::$db = $this->getConnection(); - \yiiunit\extensions\mongodb\data\ar\file\ActiveRecord::$db = $this->getConnection(); $this->setUpTestRows(); } @@ -31,7 +29,7 @@ protected function tearDown() */ protected function setUpTestRows() { - $fileCollection = $this->getConnection()->getFileCollection(CustomerFile::collectionName()); + $fileCollection = yii::$app->mongodb->getFileCollection(CustomerFile::collectionName()); $customers = []; $files = []; for ($i = 1; $i <= 5; $i++) { @@ -52,7 +50,7 @@ protected function setUpTestRows() 'file_id' => $file['_id'], ]; } - $customerCollection = $this->getConnection()->getCollection(Customer::collectionName()); + $customerCollection = yii::$app->mongodb->getCollection(Customer::collectionName()); $customers = $customerCollection->batchInsert($customers); } diff --git a/tests/file/CollectionTest.php b/tests/file/CollectionTest.php index 07c4350d2..af14528af 100644 --- a/tests/file/CollectionTest.php +++ b/tests/file/CollectionTest.php @@ -22,7 +22,7 @@ protected function tearDown() public function testGetChunkCollection() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $chunkCollection = $collection->getChunkCollection(); $this->assertTrue($chunkCollection instanceof \yii\mongodb\Collection); $this->assertTrue($chunkCollection->database instanceof \yii\mongodb\Database); @@ -30,7 +30,7 @@ public function testGetChunkCollection() public function testGetFileCollection() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $fileCollection = $collection->getFileCollection(); $this->assertTrue($fileCollection instanceof \yii\mongodb\Collection); $this->assertTrue($fileCollection->database instanceof \yii\mongodb\Database); @@ -38,7 +38,7 @@ public function testGetFileCollection() public function testEnsureIndexes() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $collection->ensureIndexes(); $this->assertCount(2, $collection->listIndexes()); @@ -54,14 +54,14 @@ public function testEnsureIndexes() public function testFind() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $cursor = $collection->find(); $this->assertTrue($cursor instanceof Cursor); } public function testInsertFile() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $filename = __FILE__; $id = $collection->insertFile($filename); @@ -77,7 +77,7 @@ public function testInsertFile() public function testInsertFileContent() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $bytes = 'Test file content'; $id = $collection->insertFileContent($bytes); @@ -97,7 +97,7 @@ public function testInsertFileContent() */ public function testGet() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $bytes = 'Test file content'; $id = $collection->insertFileContent($bytes); @@ -112,7 +112,7 @@ public function testGet() */ public function testDeleteFile() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $bytes = 'Test file content'; $id = $collection->insertFileContent($bytes); @@ -128,7 +128,7 @@ public function testDeleteFile() */ public function testRemove() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); for ($i = 1; $i <=10; $i++) { $bytes = 'Test file content ' . $i; diff --git a/tests/file/DownloadTest.php b/tests/file/DownloadTest.php index 0fb3dd037..2ba37482c 100644 --- a/tests/file/DownloadTest.php +++ b/tests/file/DownloadTest.php @@ -19,7 +19,7 @@ protected function tearDown() public function testToStream() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $upload = $collection->createUpload(); $document = $upload->addContent('test content')->complete(); @@ -34,7 +34,7 @@ public function testToStream() public function testToFile() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $upload = $collection->createUpload(); $document = $upload->addContent('test content')->complete(); @@ -49,7 +49,7 @@ public function testToFile() public function testSubstr() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $upload = $collection->createUpload(); $upload->chunkSize = 10; diff --git a/tests/file/QueryTest.php b/tests/file/QueryTest.php index 46b2a564c..60219d147 100644 --- a/tests/file/QueryTest.php +++ b/tests/file/QueryTest.php @@ -28,7 +28,7 @@ protected function tearDown() */ protected function setUpTestRows() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); for ($i = 1; $i <= 10; $i++) { $collection->insertFileContent('content' . $i, [ 'filename' => 'name' . $i, @@ -41,28 +41,25 @@ protected function setUpTestRows() public function testAll() { - $connection = $this->getConnection(); $query = new Query(); - $rows = $query->from('fs')->all($connection); + $rows = $query->from('fs')->all(); $this->assertEquals(10, count($rows)); } public function testOne() { - $connection = $this->getConnection(); $query = new Query(); - $row = $query->from('fs')->one($connection); + $row = $query->from('fs')->one(); $this->assertTrue(is_array($row)); $this->assertTrue($row['file'] instanceof Download); } public function testDirectMatch() { - $connection = $this->getConnection(); $query = new Query(); $rows = $query->from('fs') ->where(['file_index' => 5]) - ->all($connection); + ->all(); $this->assertEquals(1, count($rows)); $file = $rows[0]; diff --git a/tests/file/StreamWrapperTest.php b/tests/file/StreamWrapperTest.php index ac82c14dc..afa64797a 100644 --- a/tests/file/StreamWrapperTest.php +++ b/tests/file/StreamWrapperTest.php @@ -8,9 +8,8 @@ class StreamWrapperTest extends TestCase { protected function tearDown() { - $connection = $this->getConnection(); - if (in_array($connection->fileStreamProtocol, stream_get_wrappers())) { - stream_wrapper_unregister($connection->fileStreamProtocol); + if (in_array(yii::$app->mongodb->fileStreamProtocol, stream_get_wrappers())) { + stream_wrapper_unregister(yii::$app->mongodb->fileStreamProtocol); } $this->dropFileCollection('fs'); @@ -22,7 +21,7 @@ protected function tearDown() public function testCreateFromDownload() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $upload = $collection->createUpload(); $document = $upload->addContent('test content')->complete(); @@ -36,15 +35,14 @@ public function testCreateFromDownload() public function testWriteResource() { - $connection = $this->getConnection(); $this->mockApplication([ 'components' => [ - 'mongodb' => $connection + 'mongodb' => yii::$app->mongodb ], ]); - $connection->registerFileStreamWrapper(true); - $databaseName = $connection->getDefaultDatabaseName(); + yii::$app->mongodb->registerFileStreamWrapper(true); + $databaseName = yii::$app->mongodb->getDefaultDatabaseName(); $url = "gridfs://{$databaseName}.fs?filename=test.txt"; $resource = fopen($url, 'w'); @@ -52,7 +50,7 @@ public function testWriteResource() fwrite($resource, 'end'); fclose($resource); - $collection = $connection->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $document = $collection->findOne(['filename' => 'test.txt']); $this->assertNotEmpty($document); @@ -61,19 +59,18 @@ public function testWriteResource() public function testReadResource() { - $connection = $this->getConnection(); $this->mockApplication([ 'components' => [ - 'mongodb' => $connection + 'mongodb' => yii::$app->mongodb ], ]); - $collection = $connection->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $upload = $collection->createUpload(); $document = $upload->addContent('test content')->complete(); - $connection->registerFileStreamWrapper(true); - $databaseName = $connection->getDefaultDatabaseName(); + yii::$app->mongodb->registerFileStreamWrapper(true); + $databaseName = yii::$app->mongodb->getDefaultDatabaseName(); $url = "gridfs://{$databaseName}.fs?_id=" . $document['_id']; $resource = fopen($url, 'r'); @@ -83,15 +80,14 @@ public function testReadResource() public function testSeek() { - $connection = $this->getConnection(); $this->mockApplication([ 'components' => [ - 'mongodb' => $connection + 'mongodb' => yii::$app->mongodb ], ]); - $connection->registerFileStreamWrapper(true); - $databaseName = $connection->getDefaultDatabaseName(); + yii::$app->mongodb->registerFileStreamWrapper(true); + $databaseName = yii::$app->mongodb->getDefaultDatabaseName(); $url = "gridfs://{$databaseName}.fs?filename=test.txt"; $resource = fopen($url, 'w'); diff --git a/tests/file/UploadTest.php b/tests/file/UploadTest.php index 95983d4e8..18077a1b4 100644 --- a/tests/file/UploadTest.php +++ b/tests/file/UploadTest.php @@ -20,7 +20,7 @@ protected function tearDown() public function testAddContent() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $upload = $collection->createUpload(); $document = $upload->addContent('content line 1') @@ -37,7 +37,7 @@ public function testAddContent() */ public function testAddContentChunk() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $upload = $collection->createUpload(); $upload->chunkSize = 10; @@ -50,7 +50,7 @@ public function testAddContentChunk() public function testAddStream() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $upload = $collection->createUpload(); @@ -68,7 +68,7 @@ public function testAddStream() */ public function testCancel() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $upload = $collection->createUpload(); $document = $upload->addContent('content line 1'); @@ -85,7 +85,7 @@ public function testCancel() */ public function testCustomId() { - $collection = $this->getConnection()->getFileCollection(); + $collection = yii::$app->mongodb->getFileCollection(); $id = new ObjectID(); $upload = $collection->createUpload([ diff --git a/tests/i18n/MongoDbMessageSourceTest.php b/tests/i18n/MongoDbMessageSourceTest.php index d2f7273a9..a6d99c2cb 100644 --- a/tests/i18n/MongoDbMessageSourceTest.php +++ b/tests/i18n/MongoDbMessageSourceTest.php @@ -33,8 +33,7 @@ protected function tearDown() */ protected function setupTestRows() { - $db = $this->getConnection(); - $collection = $db->getCollection('message'); + $collection = yii::$app->mongodb->getCollection('message'); $collection->batchInsert([ [ 'language' => 'de', @@ -104,7 +103,6 @@ protected function setupI18N() $this->i18n = new I18N([ 'translations' => [ '*' => new MongoDbMessageSource([ - 'db' => $this->getConnection(), 'sourceLanguage' => 'en-US', ]) ] diff --git a/tests/log/MongoDbTargetTest.php b/tests/log/MongoDbTargetTest.php index 2c9847f19..7335bcffa 100644 --- a/tests/log/MongoDbTargetTest.php +++ b/tests/log/MongoDbTargetTest.php @@ -14,21 +14,11 @@ protected function tearDown() parent::tearDown(); } - /** - * @return MongoDbTarget test log target - */ - protected function createLogTarget() - { - return new MongoDbTarget([ - 'db' => $this->getConnection(), - ]); - } - // Tests : public function testExport() { - $target = $this->createLogTarget(); + $target = new MongoDbTarget(); $target->messages = [ [ diff --git a/tests/rbac/MongoDbManagerTest.php b/tests/rbac/MongoDbManagerTest.php index 5800aef55..16510ab70 100644 --- a/tests/rbac/MongoDbManagerTest.php +++ b/tests/rbac/MongoDbManagerTest.php @@ -23,7 +23,7 @@ class MongoDbManagerTest extends TestCase protected function setUp() { parent::setUp(); - $this->auth = $this->createManager(); + $this->auth = new MongoDbManager(); } protected function tearDown() @@ -34,14 +34,6 @@ protected function tearDown() parent::tearDown(); } - /** - * @return MongoDbManager - */ - protected function createManager() - { - return new MongoDbManager(['db' => $this->getConnection()]); - } - // Tests : public function testCreateRole() @@ -354,7 +346,7 @@ public function testAssignMultipleRoles() $this->auth->assign($reader, 'readingAuthor'); $this->auth->assign($author, 'readingAuthor'); - $this->auth = $this->createManager(); + $this->auth = new MongoDbManager(); $roles = $this->auth->getRolesByUser('readingAuthor'); $roleNames = []; @@ -376,7 +368,7 @@ public function testAssignmentsToIntegerId() $this->auth->assign($author, 1337); $this->auth->assign($reader, 1337); - $this->auth = $this->createManager(); + $this->auth = new MongoDbManager(); $this->assertEquals(0, count($this->auth->getAssignments(0))); $this->assertEquals(1, count($this->auth->getAssignments(42))); @@ -389,7 +381,7 @@ public function testGetAssignmentsByRole() $reader = $this->auth->getRole('reader'); $this->auth->assign($reader, 123); - $this->auth = $this->createManager(); + $this->auth = new MongoDbManager(); $this->assertEquals([], $this->auth->getUserIdsByRole('nonexisting')); $this->assertEquals(['reader A', '123'], $this->auth->getUserIdsByRole('reader'), '', 0.0, 10, true); From cb9e12843f5da37aaceb7ee987c049d64a3bb2f0 Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Sun, 11 Oct 2020 13:27:19 +0330 Subject: [PATCH 02/16] fix bugs --- tests/ActiveDataProviderTest.php | 1 - tests/ActiveFixtureTest.php | 5 ----- tests/TestCase.php | 6 ++++-- .../controllers/MigrateControllerTest.php | 2 -- tests/file/StreamWrapperTest.php | 18 ------------------ tests/validators/MongoDateValidatorTest.php | 1 - tests/validators/MongoIdValidatorTest.php | 6 ------ 7 files changed, 4 insertions(+), 35 deletions(-) diff --git a/tests/ActiveDataProviderTest.php b/tests/ActiveDataProviderTest.php index 9f60c4654..3f506aa79 100644 --- a/tests/ActiveDataProviderTest.php +++ b/tests/ActiveDataProviderTest.php @@ -12,7 +12,6 @@ class ActiveDataProviderTest extends TestCase protected function setUp() { parent::setUp(); - $this->mockApplication(); $this->setUpTestRows(); } diff --git a/tests/ActiveFixtureTest.php b/tests/ActiveFixtureTest.php index 54a50e999..d48819815 100644 --- a/tests/ActiveFixtureTest.php +++ b/tests/ActiveFixtureTest.php @@ -10,11 +10,6 @@ class ActiveFixtureTest extends TestCase { - protected function setUp() - { - parent::setUp(); - $this->mockApplication(); - } protected function tearDown() { diff --git a/tests/TestCase.php b/tests/TestCase.php index b3ffea853..df91a00a6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -34,8 +34,7 @@ protected function setUp() if (!empty($config)) { $this->mongoDbConfig = $config; } - Yii::$app->setComponents(['mongodb' => $this->getConnection()]); - //$this->mockApplication(); + $this->mockApplication(); } protected function tearDown() @@ -75,6 +74,9 @@ protected function mockApplication($config = [], $appClass = '\yii\console\Appli 'basePath' => __DIR__, 'vendorPath' => $this->getVendorPath(), 'runtimePath' => dirname(__DIR__) . '/runtime', + 'components' => [ + 'mongodb' => $this->getConnection(), + ], ], $config)); } diff --git a/tests/console/controllers/MigrateControllerTest.php b/tests/console/controllers/MigrateControllerTest.php index 6af87285a..175825a93 100644 --- a/tests/console/controllers/MigrateControllerTest.php +++ b/tests/console/controllers/MigrateControllerTest.php @@ -47,8 +47,6 @@ public function setUp() $this->migrationNamespace = 'yiiunit\extensions\mongodb\runtime\test_migrations'; $this->setUpMigrationPath(); - - $this->mockApplication(); } public function tearDown() diff --git a/tests/file/StreamWrapperTest.php b/tests/file/StreamWrapperTest.php index afa64797a..c4c48cfb6 100644 --- a/tests/file/StreamWrapperTest.php +++ b/tests/file/StreamWrapperTest.php @@ -35,12 +35,6 @@ public function testCreateFromDownload() public function testWriteResource() { - $this->mockApplication([ - 'components' => [ - 'mongodb' => yii::$app->mongodb - ], - ]); - yii::$app->mongodb->registerFileStreamWrapper(true); $databaseName = yii::$app->mongodb->getDefaultDatabaseName(); @@ -59,12 +53,6 @@ public function testWriteResource() public function testReadResource() { - $this->mockApplication([ - 'components' => [ - 'mongodb' => yii::$app->mongodb - ], - ]); - $collection = yii::$app->mongodb->getFileCollection(); $upload = $collection->createUpload(); $document = $upload->addContent('test content')->complete(); @@ -80,12 +68,6 @@ public function testReadResource() public function testSeek() { - $this->mockApplication([ - 'components' => [ - 'mongodb' => yii::$app->mongodb - ], - ]); - yii::$app->mongodb->registerFileStreamWrapper(true); $databaseName = yii::$app->mongodb->getDefaultDatabaseName(); diff --git a/tests/validators/MongoDateValidatorTest.php b/tests/validators/MongoDateValidatorTest.php index 32faf0efe..bb89195a8 100644 --- a/tests/validators/MongoDateValidatorTest.php +++ b/tests/validators/MongoDateValidatorTest.php @@ -12,7 +12,6 @@ class MongoDateValidatorTest extends TestCase protected function setUp() { parent::setUp(); - $this->mockApplication(); date_default_timezone_set('UTC'); } diff --git a/tests/validators/MongoIdValidatorTest.php b/tests/validators/MongoIdValidatorTest.php index 6c8208163..e066fb2f6 100644 --- a/tests/validators/MongoIdValidatorTest.php +++ b/tests/validators/MongoIdValidatorTest.php @@ -9,12 +9,6 @@ class MongoIdValidatorTest extends TestCase { - protected function setUp() - { - parent::setUp(); - $this->mockApplication(); - } - public function testValidateValue() { $validator = new MongoIdValidator(); From cd59f1c0a860257df16ecec617e04e059dac13e2 Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Sun, 11 Oct 2020 13:37:11 +0330 Subject: [PATCH 03/16] fix yii namespace bug --- tests/ActiveDataProviderTest.php | 1 + tests/ActiveRecordTest.php | 1 + tests/ActiveRelationTest.php | 1 + tests/BatchQueryResultTest.php | 1 + tests/CollectionTest.php | 1 + tests/CommandTest.php | 1 + tests/ConnectionTest.php | 1 + tests/DatabaseTest.php | 1 + tests/LogBuilderTest.php | 1 + tests/QueryRunTest.php | 1 + tests/file/ActiveRelationTest.php | 1 + tests/file/CollectionTest.php | 1 + tests/file/DownloadTest.php | 2 +- tests/file/QueryTest.php | 1 + tests/file/StreamWrapperTest.php | 1 + tests/file/UploadTest.php | 1 + tests/i18n/MongoDbMessageSourceTest.php | 1 + 17 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/ActiveDataProviderTest.php b/tests/ActiveDataProviderTest.php index 3f506aa79..e7eead35e 100644 --- a/tests/ActiveDataProviderTest.php +++ b/tests/ActiveDataProviderTest.php @@ -3,6 +3,7 @@ namespace yiiunit\extensions\mongodb; use MongoDB\BSON\ObjectID; +use yii; use yii\data\ActiveDataProvider; use yii\mongodb\Query; use yiiunit\extensions\mongodb\data\ar\Customer; diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php index ecec403f3..d99d551cb 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -5,6 +5,7 @@ use MongoDB\BSON\Binary; use MongoDB\BSON\ObjectID; use MongoDB\BSON\Regex; +use yii; use yii\mongodb\ActiveQuery; use yiiunit\extensions\mongodb\data\ar\Customer; use yiiunit\extensions\mongodb\data\ar\Animal; diff --git a/tests/ActiveRelationTest.php b/tests/ActiveRelationTest.php index 45084cbf8..b0ebe9c5e 100644 --- a/tests/ActiveRelationTest.php +++ b/tests/ActiveRelationTest.php @@ -2,6 +2,7 @@ namespace yiiunit\extensions\mongodb; +use yii; use yiiunit\extensions\mongodb\data\ar\Customer; use yiiunit\extensions\mongodb\data\ar\CustomerOrder; use yiiunit\extensions\mongodb\data\ar\Item; diff --git a/tests/BatchQueryResultTest.php b/tests/BatchQueryResultTest.php index e3d39affe..d47134eba 100644 --- a/tests/BatchQueryResultTest.php +++ b/tests/BatchQueryResultTest.php @@ -2,6 +2,7 @@ namespace yiiunit\extensions\mongodb; +use yii; use yii\mongodb\BatchQueryResult; use yii\mongodb\Query; use yiiunit\extensions\mongodb\data\ar\Customer; diff --git a/tests/CollectionTest.php b/tests/CollectionTest.php index f126d9f06..7a9c3e25c 100644 --- a/tests/CollectionTest.php +++ b/tests/CollectionTest.php @@ -4,6 +4,7 @@ use MongoDB\BSON\ObjectID; use MongoDB\Driver\Cursor; +use yii; class CollectionTest extends TestCase { diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 7db836a4c..2b3a41c77 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -4,6 +4,7 @@ use MongoDB\BSON\ObjectID; use MongoDB\Driver\Cursor; +use yii; use yii\helpers\ArrayHelper; class CommandTest extends TestCase diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index c5bfa054b..730c5af03 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -2,6 +2,7 @@ namespace yiiunit\extensions\mongodb; +use yii; use yii\mongodb\Collection; use yii\mongodb\Command; use yii\mongodb\file\Collection as FileCollection; diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 8674dd815..5999d8378 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -2,6 +2,7 @@ namespace yiiunit\extensions\mongodb; +use yii; use yii\mongodb\Collection; use yii\mongodb\Command; use yii\mongodb\file\Collection as FileCollection; diff --git a/tests/LogBuilderTest.php b/tests/LogBuilderTest.php index 540d478bd..83bc5c4c0 100644 --- a/tests/LogBuilderTest.php +++ b/tests/LogBuilderTest.php @@ -4,6 +4,7 @@ use MongoDB\BSON\Javascript; use MongoDB\BSON\ObjectID; +use yii; class LogBuilderTest extends TestCase { diff --git a/tests/QueryRunTest.php b/tests/QueryRunTest.php index 770c2fdb1..a36166def 100644 --- a/tests/QueryRunTest.php +++ b/tests/QueryRunTest.php @@ -3,6 +3,7 @@ namespace yiiunit\extensions\mongodb; use MongoDB\BSON\ObjectID; +use yii; use yii\mongodb\Query; class QueryRunTest extends TestCase diff --git a/tests/file/ActiveRelationTest.php b/tests/file/ActiveRelationTest.php index dcb9d74d1..4a2a279ca 100644 --- a/tests/file/ActiveRelationTest.php +++ b/tests/file/ActiveRelationTest.php @@ -5,6 +5,7 @@ use yiiunit\extensions\mongodb\data\ar\Customer; use yiiunit\extensions\mongodb\data\ar\file\CustomerFile; use yiiunit\extensions\mongodb\TestCase; +use yii; /** * @group file diff --git a/tests/file/CollectionTest.php b/tests/file/CollectionTest.php index af14528af..3fb263cff 100644 --- a/tests/file/CollectionTest.php +++ b/tests/file/CollectionTest.php @@ -3,6 +3,7 @@ namespace yiiunit\extensions\mongodb\file; use MongoDB\BSON\ObjectID; +use yii; use yii\mongodb\file\Cursor; use yii\mongodb\file\Download; use yiiunit\extensions\mongodb\TestCase; diff --git a/tests/file/DownloadTest.php b/tests/file/DownloadTest.php index 2ba37482c..512743e02 100644 --- a/tests/file/DownloadTest.php +++ b/tests/file/DownloadTest.php @@ -3,7 +3,7 @@ namespace yiiunit\extensions\mongodb\file; use yiiunit\extensions\mongodb\TestCase; - +use yii; /** * @group file */ diff --git a/tests/file/QueryTest.php b/tests/file/QueryTest.php index 60219d147..b622cde4a 100644 --- a/tests/file/QueryTest.php +++ b/tests/file/QueryTest.php @@ -2,6 +2,7 @@ namespace yiiunit\extensions\mongodb\file; +use yii; use yii\mongodb\file\Download; use yii\mongodb\file\Query; use yiiunit\extensions\mongodb\TestCase; diff --git a/tests/file/StreamWrapperTest.php b/tests/file/StreamWrapperTest.php index c4c48cfb6..8269079cf 100644 --- a/tests/file/StreamWrapperTest.php +++ b/tests/file/StreamWrapperTest.php @@ -2,6 +2,7 @@ namespace yiiunit\extensions\mongodb\file; +use yii; use yiiunit\extensions\mongodb\TestCase; class StreamWrapperTest extends TestCase diff --git a/tests/file/UploadTest.php b/tests/file/UploadTest.php index 18077a1b4..56c76bad9 100644 --- a/tests/file/UploadTest.php +++ b/tests/file/UploadTest.php @@ -3,6 +3,7 @@ namespace yiiunit\extensions\mongodb\file; use MongoDB\BSON\ObjectID; +use yii; use yiiunit\extensions\mongodb\TestCase; /** diff --git a/tests/i18n/MongoDbMessageSourceTest.php b/tests/i18n/MongoDbMessageSourceTest.php index a6d99c2cb..33667745b 100644 --- a/tests/i18n/MongoDbMessageSourceTest.php +++ b/tests/i18n/MongoDbMessageSourceTest.php @@ -2,6 +2,7 @@ namespace yiiunit\extensions\mongodb\i18n; +use yii; use yii\i18n\I18N; use yii\mongodb\i18n\MongoDbMessageSource; use yiiunit\extensions\mongodb\TestCase; From 3c90695e36e662966ba7983fecdc3763db0f0963 Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Sun, 11 Oct 2020 13:55:36 +0330 Subject: [PATCH 04/16] Update MigrateControllerTest.php --- tests/console/controllers/MigrateControllerTest.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/console/controllers/MigrateControllerTest.php b/tests/console/controllers/MigrateControllerTest.php index 175825a93..abd384ca3 100644 --- a/tests/console/controllers/MigrateControllerTest.php +++ b/tests/console/controllers/MigrateControllerTest.php @@ -51,15 +51,9 @@ public function setUp() public function tearDown() { - parent::tearDown(); - if (extension_loaded('mongodb')) { - try { - yii::$app->mongodb->getCollection('migration')->drop(); - } catch (Exception $e) { - // shutdown exception - } - } + yii::$app->mongodb->getCollection('migration')->drop(); $this->tearDownMigrationPath(); + parent::tearDown(); } public function setUpMigrationPath() From fda59d8706372fd2ab8f282210f357c2cd5e785c Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Sun, 11 Oct 2020 14:09:11 +0330 Subject: [PATCH 05/16] Update MigrateControllerTest.php --- tests/console/controllers/MigrateControllerTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/console/controllers/MigrateControllerTest.php b/tests/console/controllers/MigrateControllerTest.php index abd384ca3..593860532 100644 --- a/tests/console/controllers/MigrateControllerTest.php +++ b/tests/console/controllers/MigrateControllerTest.php @@ -51,7 +51,11 @@ public function setUp() public function tearDown() { - yii::$app->mongodb->getCollection('migration')->drop(); + try { + yii::$app->mongodb->getCollection('migration')->drop(); + } catch (Exception $e) { + // shutdown exception + } $this->tearDownMigrationPath(); parent::tearDown(); } From 6c0ef361e379e954fc2522379be79d5381c66d4a Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Sun, 11 Oct 2020 14:18:08 +0330 Subject: [PATCH 06/16] Update ConnectionTest.php --- tests/ConnectionTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 730c5af03..123ff4a53 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -14,7 +14,7 @@ class ConnectionTest extends TestCase { public function testConstruct() { - $connection = $this->getConnection(false); + $connection = $this->getConnection(true,false); $params = $this->mongoDbConfig; $connection->open(); @@ -26,7 +26,7 @@ public function testConstruct() public function testOpenClose() { - $connection = $this->getConnection(false, false); + $connection = $this->getConnection(true, false); $this->assertFalse($connection->isActive); $this->assertEquals(null, $connection->manager); From 7e579a48f084e3a81968e6206e7dd2f1ce45d816 Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Sun, 11 Oct 2020 17:00:28 +0330 Subject: [PATCH 07/16] Update QueryRunTest.php --- tests/QueryRunTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/QueryRunTest.php b/tests/QueryRunTest.php index a36166def..318da4080 100644 --- a/tests/QueryRunTest.php +++ b/tests/QueryRunTest.php @@ -608,7 +608,10 @@ public function testDistinct() ->from('customer') ->distinct('group'); - $this->assertSame(['odd', 'even'], $rows); + #difference order after php 7 + sort($rows); + + $this->assertSame(['even', 'odd'], $rows); } public function testAggregationShortcuts() From 85e0c79fceae5f5cde0c414d910e3a9f52ae4822 Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Sun, 11 Oct 2020 19:21:22 +0330 Subject: [PATCH 08/16] Update mongodb-setup.sh --- tests/data/travis/mongodb-setup.sh | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/data/travis/mongodb-setup.sh b/tests/data/travis/mongodb-setup.sh index c709dd832..2abc39e46 100755 --- a/tests/data/travis/mongodb-setup.sh +++ b/tests/data/travis/mongodb-setup.sh @@ -12,12 +12,26 @@ mongo yii2test --eval 'db.createUser({user: "travis", pwd: "test", roles: ["read # PHP Extension : if (php --version | grep -i HipHop > /dev/null); then - echo "skip PHP extension installation on HHVM" + echo "skip PHP extension installation on HHVM" else - pecl install -f mongodb - echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - echo "MongoDB PHP Extension version:" - php -i |grep mongodb -4 |grep -2 version + + #https://docs.mongodb.com/drivers/php#language-compatibility + if [ $(php -r "echo version_compare(phpversion(),'5.5','<') ? 1 : 0;") == 1 ] + then + pecl install -f mongodb-1.3.4 + elif [ $(php -r "echo version_compare(phpversion(),'5.5','>=') && version_compare(phpversion(),'7.2','<=') ? 1 : 0;") == 1 ] + then + pecl install -f mongodb-1.4.4 + elif [ $(php -r "echo version_compare(phpversion(),'7.3','>=') && version_compare(phpversion(),'7.4','<') ? 1 : 0;") == 1 ] + then + pecl install -f mongodb-1.5.5 + elif [ $(php -r "echo version_compare(phpversion(),'7.4','>=') ? 1 : 0;") == 1 ] + then + pecl install -f mongodb + fi + echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + echo "MongoDB PHP Extension version:" + php -i |grep mongodb -4 |grep -2 version fi #cat /etc/mongodb.conf From d869e02c03f1b58775bcf42f00158365dcd45b94 Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Sat, 31 Oct 2020 08:27:11 +0330 Subject: [PATCH 09/16] Update tests/ActiveDataProviderTest.php Co-authored-by: Alexander Makarov --- tests/ActiveDataProviderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ActiveDataProviderTest.php b/tests/ActiveDataProviderTest.php index e7eead35e..44efed6e7 100644 --- a/tests/ActiveDataProviderTest.php +++ b/tests/ActiveDataProviderTest.php @@ -27,7 +27,7 @@ protected function tearDown() */ protected function setUpTestRows() { - $collection = yii::$app->mongodb->getCollection('customer'); + $collection = Yii::$app->mongodb->getCollection('customer'); $rows = []; for ($i = 1; $i <= 10; $i++) { $rows[] = [ From f5971b1f2b0e752a6ac822ab00a736b33123a0de Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Sat, 31 Oct 2020 08:27:21 +0330 Subject: [PATCH 10/16] Update tests/ActiveFixtureTest.php Co-authored-by: Alexander Makarov --- tests/ActiveFixtureTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ActiveFixtureTest.php b/tests/ActiveFixtureTest.php index d48819815..d1f290e0c 100644 --- a/tests/ActiveFixtureTest.php +++ b/tests/ActiveFixtureTest.php @@ -27,7 +27,7 @@ public function testLoadCollection() $fixture = $this->getMockBuilder(ActiveFixture::className()) ->setConstructorArgs([ [ - 'db' => yii::$app->mongodb, + 'db' => Yii::$app->mongodb, 'collectionName' => Customer::collectionName() ] ]) @@ -155,4 +155,4 @@ class {$className} extends \yii\mongodb\ActiveFixture $rows = $this->findAll(yii::$app->mongodb->getCollection(Customer::collectionName())); $this->assertCount(3, $rows); } -} \ No newline at end of file +} From 302c4ad940e21642b1e9fa4d31fa6c207a9ca835 Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Sat, 31 Oct 2020 08:27:29 +0330 Subject: [PATCH 11/16] Update tests/ActiveFixtureTest.php Co-authored-by: Alexander Makarov --- tests/ActiveFixtureTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ActiveFixtureTest.php b/tests/ActiveFixtureTest.php index d1f290e0c..8a62a11b7 100644 --- a/tests/ActiveFixtureTest.php +++ b/tests/ActiveFixtureTest.php @@ -40,7 +40,7 @@ public function testLoadCollection() $fixture->load(); - $rows = $this->findAll(yii::$app->mongodb->getCollection(Customer::collectionName())); + $rows = $this->findAll(Yii::$app->mongodb->getCollection(Customer::collectionName())); $this->assertCount(2, $rows); } From 0af116ff708ac2ba7096441cecaa4eb124fe09a8 Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Sat, 31 Oct 2020 08:27:44 +0330 Subject: [PATCH 12/16] Update tests/ActiveFixtureTest.php Co-authored-by: Alexander Makarov --- tests/ActiveFixtureTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ActiveFixtureTest.php b/tests/ActiveFixtureTest.php index 8a62a11b7..b77116d3b 100644 --- a/tests/ActiveFixtureTest.php +++ b/tests/ActiveFixtureTest.php @@ -78,7 +78,7 @@ public function testLoadEmptyData() $fixture = $this->getMockBuilder(ActiveFixture::className()) ->setConstructorArgs([ [ - 'db' => yii::$app->mongodb, + 'db' => Yii::$app->mongodb, 'collectionName' => Customer::collectionName() ] ]) From e7f861e84731d0e05cd990139eed23587bda5482 Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Sat, 31 Oct 2020 08:27:54 +0330 Subject: [PATCH 13/16] Update tests/ActiveFixtureTest.php Co-authored-by: Alexander Makarov --- tests/ActiveFixtureTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ActiveFixtureTest.php b/tests/ActiveFixtureTest.php index b77116d3b..c6fdc9ee5 100644 --- a/tests/ActiveFixtureTest.php +++ b/tests/ActiveFixtureTest.php @@ -90,7 +90,7 @@ public function testLoadEmptyData() $fixture->load(); // should be no error - $rows = $this->findAll(yii::$app->mongodb->getCollection(Customer::collectionName())); + $rows = $this->findAll(Yii::$app->mongodb->getCollection(Customer::collectionName())); $this->assertEmpty($rows); } From f0e809b87f14489a9c975290313677718d5bf84e Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Sat, 31 Oct 2020 08:28:03 +0330 Subject: [PATCH 14/16] Update tests/ActiveFixtureTest.php Co-authored-by: Alexander Makarov --- tests/ActiveFixtureTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ActiveFixtureTest.php b/tests/ActiveFixtureTest.php index c6fdc9ee5..339504138 100644 --- a/tests/ActiveFixtureTest.php +++ b/tests/ActiveFixtureTest.php @@ -132,7 +132,7 @@ class {$className} extends \yii\mongodb\ActiveFixture ['name' => 'name2'], ['name' => 'name3'], ]; - $fixtureDataFile = $fixtureDataPath . DIRECTORY_SEPARATOR . yii::$app->mongodb->getDefaultDatabaseName() . '.' . Customer::collectionName() . '.php'; + $fixtureDataFile = $fixtureDataPath . DIRECTORY_SEPARATOR . Yii::$app->mongodb->getDefaultDatabaseName() . '.' . Customer::collectionName() . '.php'; $fixtureDataContent = ' Date: Sat, 31 Oct 2020 08:28:10 +0330 Subject: [PATCH 15/16] Update tests/ActiveFixtureTest.php Co-authored-by: Alexander Makarov --- tests/ActiveFixtureTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ActiveFixtureTest.php b/tests/ActiveFixtureTest.php index 339504138..58e34a108 100644 --- a/tests/ActiveFixtureTest.php +++ b/tests/ActiveFixtureTest.php @@ -142,7 +142,7 @@ class {$className} extends \yii\mongodb\ActiveFixture 'collectionName' => Customer::collectionName(), ]); $fixture->load(); - $rows = $this->findAll(yii::$app->mongodb->getCollection(Customer::collectionName())); + $rows = $this->findAll(Yii::$app->mongodb->getCollection(Customer::collectionName())); $this->assertCount(2, $rows); $fixture = new $className([ From 9a3ea1f2063a51dbf1fd7386f05945089b7dfd18 Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Sat, 31 Oct 2020 08:28:16 +0330 Subject: [PATCH 16/16] Update tests/ActiveFixtureTest.php Co-authored-by: Alexander Makarov --- tests/ActiveFixtureTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ActiveFixtureTest.php b/tests/ActiveFixtureTest.php index 58e34a108..19d9a0dee 100644 --- a/tests/ActiveFixtureTest.php +++ b/tests/ActiveFixtureTest.php @@ -147,7 +147,7 @@ class {$className} extends \yii\mongodb\ActiveFixture $fixture = new $className([ 'collectionName' => [ - yii::$app->mongodb->getDefaultDatabaseName(), + Yii::$app->mongodb->getDefaultDatabaseName(), Customer::collectionName() ], ]);