From 1d3671ad0aee0d4d1a1f5800c0fe552bca24dc2f Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 27 Sep 2023 07:48:37 -0300 Subject: [PATCH 1/9] Raise min version to `PHP 7.3`, check compatibility `PHP 8.3`. --- .github/workflows/build.yml | 26 ++++++++-- composer.json | 19 ++----- tests/ActiveDataProviderTest.php | 4 +- tests/ActiveFixtureTest.php | 6 +-- tests/ActiveRecordTest.php | 6 +-- tests/ActiveRelationTest.php | 4 +- tests/BatchQueryResultTest.php | 6 +-- tests/CacheTest.php | 2 +- tests/CollectionTest.php | 2 +- tests/CommandTest.php | 6 +-- tests/DatabaseTest.php | 2 +- tests/MigrationTest.php | 4 +- tests/QueryRunTest.php | 6 +-- tests/SessionTest.php | 2 +- tests/TestCase.php | 6 +-- tests/bootstrap.php | 2 - tests/compatibility.php | 50 ------------------- .../controllers/MigrateControllerTest.php | 28 +++++------ tests/file/ActiveRecordTest.php | 4 +- tests/file/ActiveRelationTest.php | 6 +-- tests/file/CollectionTest.php | 2 +- tests/file/DownloadTest.php | 4 +- tests/file/QueryTest.php | 4 +- tests/file/StreamWrapperTest.php | 14 +++--- tests/file/UploadTest.php | 4 +- tests/i18n/MongoDbMessageSourceTest.php | 6 +-- tests/log/MongoDbTargetTest.php | 4 +- tests/rbac/MongoDbManagerTest.php | 14 +++--- tests/validators/MongoDateValidatorTest.php | 4 +- tests/validators/MongoIdValidatorTest.php | 4 +- 30 files changed, 103 insertions(+), 148 deletions(-) delete mode 100644 tests/compatibility.php diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 33e1c867a..3c1d4c92d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,26 @@ -name: build +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' + + push: + branches: ['master'] + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' -on: [push, pull_request] +name: build env: DEFAULT_COMPOSER_FLAGS: "--prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi" @@ -18,7 +38,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] + php: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] mongo: ['3'] mongoext: ['1.8.2', '1.9.0'] diff --git a/composer.json b/composer.json index 58b45ebed..ca912e3a9 100644 --- a/composer.json +++ b/composer.json @@ -18,13 +18,12 @@ } ], "require": { - "yiisoft/yii2": "~2.0.39", + "php": ">=7.3", "ext-mongodb": ">=1.0.0", - "paragonie/random_compat": ">=1" + "yiisoft/yii2": "~2.0.39" }, "require-dev": { - "cweagans/composer-patches": "^1.7", - "phpunit/phpunit": "4.8.34" + "phpunit/phpunit": "^9.6" }, "repositories": [ { @@ -38,22 +37,10 @@ "extra": { "branch-alias": { "dev-master": "2.1.x-dev" - }, - "composer-exit-on-patch-failure": true, - "patches": { - "phpunit/phpunit-mock-objects": { - "Fix PHP 7 and 8 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_mock_objects.patch" - }, - "phpunit/phpunit": { - "Fix PHP 7 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php7.patch", - "Fix PHP 8 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php8.patch", - "Fix PHP 8.1 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php81.patch" - } } }, "config": { "allow-plugins": { - "cweagans/composer-patches": true, "yiisoft/yii2-composer": true } } diff --git a/tests/ActiveDataProviderTest.php b/tests/ActiveDataProviderTest.php index 4d4579641..d7f083a56 100644 --- a/tests/ActiveDataProviderTest.php +++ b/tests/ActiveDataProviderTest.php @@ -10,7 +10,7 @@ class ActiveDataProviderTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->mockApplication(); @@ -18,7 +18,7 @@ protected function setUp() $this->setUpTestRows(); } - protected function tearDown() + protected function tearDown(): void { $this->dropCollection(Customer::collectionName()); parent::tearDown(); diff --git a/tests/ActiveFixtureTest.php b/tests/ActiveFixtureTest.php index b7b58bd74..bbb48771b 100644 --- a/tests/ActiveFixtureTest.php +++ b/tests/ActiveFixtureTest.php @@ -10,13 +10,13 @@ class ActiveFixtureTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->mockApplication(); } - protected function tearDown() + protected function tearDown(): void { $this->dropCollection(Customer::collectionName()); FileHelper::removeDirectory(Yii::getAlias('@runtime/fixtures')); @@ -163,4 +163,4 @@ class {$className} extends \yii\mongodb\ActiveFixture $rows = $this->findAll($this->getConnection()->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..8a3376f33 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -19,14 +19,14 @@ class ActiveRecordTest extends TestCase */ protected $testRows = []; - protected function setUp() + protected function setUp(): void { parent::setUp(); ActiveRecord::$db = $this->getConnection(); $this->setUpTestRows(); } - protected function tearDown() + protected function tearDown(): void { $this->dropCollection(Customer::collectionName()); parent::tearDown(); @@ -518,4 +518,4 @@ public function testEmulateExecution() ->distinct('name'); $this->assertSame([], $values); } -} \ No newline at end of file +} diff --git a/tests/ActiveRelationTest.php b/tests/ActiveRelationTest.php index 0f2cd9748..446eba457 100644 --- a/tests/ActiveRelationTest.php +++ b/tests/ActiveRelationTest.php @@ -9,14 +9,14 @@ class ActiveRelationTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); ActiveRecord::$db = $this->getConnection(); $this->setUpTestRows(); } - protected function tearDown() + protected function tearDown(): void { $this->dropCollection(Customer::collectionName()); $this->dropCollection(CustomerOrder::collectionName()); diff --git a/tests/BatchQueryResultTest.php b/tests/BatchQueryResultTest.php index af04a3813..18545ba3f 100644 --- a/tests/BatchQueryResultTest.php +++ b/tests/BatchQueryResultTest.php @@ -10,14 +10,14 @@ class BatchQueryResultTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); ActiveRecord::$db = $this->getConnection(); $this->setUpTestRows(); } - protected function tearDown() + protected function tearDown(): void { $this->dropCollection(Customer::collectionName()); $this->dropCollection(CustomerOrder::collectionName()); @@ -177,4 +177,4 @@ public function testActiveQuery() $this->assertEquals(2, count($customers[1]->orders)); $this->assertEquals(2, count($customers[2]->orders)); } -} \ No newline at end of file +} diff --git a/tests/CacheTest.php b/tests/CacheTest.php index 16050d511..986d76cf3 100644 --- a/tests/CacheTest.php +++ b/tests/CacheTest.php @@ -12,7 +12,7 @@ class CacheTest extends TestCase */ protected static $cacheCollection = '_test_cache'; - protected function tearDown() + protected function tearDown(): void { $this->dropCollection(static::$cacheCollection); parent::tearDown(); diff --git a/tests/CollectionTest.php b/tests/CollectionTest.php index fd1df344d..e4437b2e7 100644 --- a/tests/CollectionTest.php +++ b/tests/CollectionTest.php @@ -7,7 +7,7 @@ class CollectionTest extends TestCase { - protected function tearDown() + protected function tearDown(): void { $this->dropCollection('customer'); $this->dropCollection('mapReduceOut'); diff --git a/tests/CommandTest.php b/tests/CommandTest.php index d7660d155..3706b5748 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -8,7 +8,7 @@ class CommandTest extends TestCase { - protected function tearDown() + protected function tearDown(): void { $this->dropCollection('customer'); parent::tearDown(); @@ -343,7 +343,7 @@ public function testListCollections() $collections = $connection->createCommand()->listCollections(); $collectionNames = ArrayHelper::getColumn($collections, 'name'); - $this->assertContains('customer', $collectionNames); + $this->assertStringContainsString('customer', $collectionNames); } /** @@ -372,4 +372,4 @@ public function testUpdateUpsert() $this->assertEquals(1, $result->getUpsertedCount()); $this->assertEquals(2, $connection->createCommand()->count('customer')); } -} \ No newline at end of file +} diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 35700bb29..e881ead9b 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -8,7 +8,7 @@ class DatabaseTest extends TestCase { - protected function tearDown() + protected function tearDown(): void { $this->dropCollection('customer'); $this->dropFileCollection('testfs'); diff --git a/tests/MigrationTest.php b/tests/MigrationTest.php index a14a8fb51..8f3e7a734 100644 --- a/tests/MigrationTest.php +++ b/tests/MigrationTest.php @@ -6,7 +6,7 @@ class MigrationTest extends TestCase { - protected function tearDown() + protected function tearDown(): void { $this->dropCollection('customer'); parent::tearDown(); @@ -132,4 +132,4 @@ protected function log($string) { $this->logs[] = $string; } -} \ No newline at end of file +} diff --git a/tests/QueryRunTest.php b/tests/QueryRunTest.php index c3a97616f..fe5321651 100644 --- a/tests/QueryRunTest.php +++ b/tests/QueryRunTest.php @@ -7,13 +7,13 @@ class QueryRunTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->setUpTestRows(); } - protected function tearDown() + protected function tearDown(): void { $this->dropCollection('customer'); parent::tearDown(); @@ -671,4 +671,4 @@ public function testAggregationShortcuts() ->average('status', $db); $this->assertEquals(6, $max); } -} \ No newline at end of file +} diff --git a/tests/SessionTest.php b/tests/SessionTest.php index 4f1baba0c..46849adda 100755 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -13,7 +13,7 @@ class SessionTest extends TestCase */ protected static $sessionCollection = '_test_session'; - protected function tearDown() + protected function tearDown(): void { $this->dropCollection(static::$sessionCollection); parent::tearDown(); diff --git a/tests/TestCase.php b/tests/TestCase.php index 7c876e453..1a164d181 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -24,7 +24,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase */ protected $mongodb; - protected function setUp() + protected function setUp(): void { parent::setUp(); if (!extension_loaded('mongodb')) { @@ -37,7 +37,7 @@ protected function setUp() //$this->mockApplication(); } - protected function tearDown() + protected function tearDown(): void { if ($this->mongodb) { $this->mongodb->close(); @@ -213,4 +213,4 @@ protected function invokeMethod($object, $method, $args = []) $method->setAccessible(true); return $method->invokeArgs($object, $args); } -} \ No newline at end of file +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index df1932c10..641cad685 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -14,5 +14,3 @@ Yii::setAlias('@yiiunit/extensions/mongodb', __DIR__); Yii::setAlias('@yii/mongodb', dirname(__DIR__) . '/src'); - -require_once(__DIR__ . '/compatibility.php'); \ No newline at end of file diff --git a/tests/compatibility.php b/tests/compatibility.php deleted file mode 100644 index 95e4cd1bc..000000000 --- a/tests/compatibility.php +++ /dev/null @@ -1,50 +0,0 @@ -setExpectedException($exception); - } - - /** - * @param string $message - */ - public function expectExceptionMessage($message) - { - $parentClassMethods = get_class_methods('PHPUnit_Framework_TestCase'); - if (in_array('expectExceptionMessage', $parentClassMethods)) { - parent::expectExceptionMessage($message); - return; - } - $this->setExpectedException($this->getExpectedException(), $message); - } - - /** - * @param string $messageRegExp - */ - public function expectExceptionMessageRegExp($messageRegExp) - { - $parentClassMethods = get_class_methods('PHPUnit_Framework_TestCase'); - if (in_array('expectExceptionMessageRegExp', $parentClassMethods)) { - parent::expectExceptionMessageRegExp($messageRegExp); - return; - } - $this->setExpectedExceptionRegExp($this->getExpectedException(), $messageRegExp); - } - } - } -} diff --git a/tests/console/controllers/MigrateControllerTest.php b/tests/console/controllers/MigrateControllerTest.php index 44b821c2e..bcbd92dbd 100644 --- a/tests/console/controllers/MigrateControllerTest.php +++ b/tests/console/controllers/MigrateControllerTest.php @@ -37,7 +37,7 @@ class MigrateControllerTest extends TestCase protected $migrationNamespace; - public function setUp() + public function setUp(): void { $this->migrateControllerClass = EchoMigrateController::className(); $this->migrationBaseClass = Migration::className(); @@ -232,7 +232,7 @@ public function testCreate() $this->runMigrateControllerAction('create', [$migrationName]); $files = FileHelper::findFiles($this->migrationPath); $this->assertCount(1, $files, 'Unable to create new migration!'); - $this->assertContains($migrationName, basename($files[0]), 'Wrong migration name!'); + $this->assertStringContainsString($migrationName, basename($files[0]), 'Wrong migration name!'); } public function testUp() @@ -292,15 +292,15 @@ public function testDownAll() public function testHistory() { $output = $this->runMigrateControllerAction('history'); - $this->assertContains('No migration', $output); + $this->assertStringContainsString('No migration', $output); $this->createMigration('test1'); $this->createMigration('test2'); $this->runMigrateControllerAction('up'); $output = $this->runMigrateControllerAction('history'); - $this->assertContains('_test1', $output); - $this->assertContains('_test2', $output); + $this->assertStringContainsString('_test1', $output); + $this->assertStringContainsString('_test2', $output); } /** @@ -311,12 +311,12 @@ public function testNew() $this->createMigration('test1'); $output = $this->runMigrateControllerAction('new'); - $this->assertContains('_test1', $output); + $this->assertStringContainsString('_test1', $output); $this->runMigrateControllerAction('up'); $output = $this->runMigrateControllerAction('new'); - $this->assertNotContains('_test1', $output); + $this->assertStringNotContainsString('_test1', $output); } public function testMark() @@ -367,7 +367,7 @@ public function testNamespaceCreate() ]); $files = FileHelper::findFiles($this->migrationPath); $fileContent = file_get_contents($files[0]); - $this->assertContains("namespace {$this->migrationNamespace};", $fileContent); + $this->assertStringContainsString("namespace {$this->migrationNamespace};", $fileContent); $this->assertRegExp('/class M[0-9]{12}' . ucfirst($migrationName) . '/s', $fileContent); unlink($files[0]); @@ -379,7 +379,7 @@ public function testNamespaceCreate() ]); $files = FileHelper::findFiles($this->migrationPath); $fileContent = file_get_contents($files[0]); - $this->assertContains("namespace {$this->migrationNamespace};", $fileContent); + $this->assertStringContainsString("namespace {$this->migrationNamespace};", $fileContent); unlink($files[0]); // no namespace: @@ -390,7 +390,7 @@ public function testNamespaceCreate() ]); $files = FileHelper::findFiles($this->migrationPath); $fileContent = file_get_contents($files[0]); - $this->assertNotContains("namespace {$this->migrationNamespace};", $fileContent); + $this->assertStringNotContainsString("namespace {$this->migrationNamespace};", $fileContent); } /** @@ -447,7 +447,7 @@ public function testNamespaceHistory() ]; $output = $this->runMigrateControllerAction('history', [], $controllerConfig); - $this->assertContains('No migration', $output); + $this->assertStringContainsString('No migration', $output); $this->createNamespaceMigration('history1'); $this->createNamespaceMigration('history2'); @@ -582,9 +582,9 @@ public function testRefreshMigration() $result = $this->runMigrateControllerAction('fresh'); - $this->assertContains('Collection hall_of_fame dropped.', $result); - $this->assertContains('No new migrations found. Your system is up-to-date.', $result); + $this->assertStringContainsString('Collection hall_of_fame dropped.', $result); + $this->assertStringContainsString('No new migrations found. Your system is up-to-date.', $result); $this->assertEmpty($connection->getDatabase()->listCollections(['name' => $collection->name])); } -} \ No newline at end of file +} diff --git a/tests/file/ActiveRecordTest.php b/tests/file/ActiveRecordTest.php index 1b9b6249e..f63445493 100644 --- a/tests/file/ActiveRecordTest.php +++ b/tests/file/ActiveRecordTest.php @@ -20,7 +20,7 @@ class ActiveRecordTest extends TestCase */ protected $testRows = []; - protected function setUp() + protected function setUp(): void { parent::setUp(); ActiveRecord::$db = $this->getConnection(); @@ -32,7 +32,7 @@ protected function setUp() } } - protected function tearDown() + protected function tearDown(): void { $filePath = $this->getTestFilePath(); if (file_exists($filePath)) { diff --git a/tests/file/ActiveRelationTest.php b/tests/file/ActiveRelationTest.php index 9c5eb47ed..be0ffe3ae 100644 --- a/tests/file/ActiveRelationTest.php +++ b/tests/file/ActiveRelationTest.php @@ -11,7 +11,7 @@ */ class ActiveRelationTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); \yiiunit\extensions\mongodb\data\ar\ActiveRecord::$db = $this->getConnection(); @@ -19,7 +19,7 @@ protected function setUp() $this->setUpTestRows(); } - protected function tearDown() + protected function tearDown(): void { $this->dropCollection(Customer::collectionName()); $this->dropCollection(CustomerFile::collectionName()); @@ -82,4 +82,4 @@ public function testFindEager() $this->assertTrue($customers[1]->file instanceof CustomerFile); $this->assertEquals((string) $customers[1]->file->_id, (string) $customers[1]->file_id); } -} \ No newline at end of file +} diff --git a/tests/file/CollectionTest.php b/tests/file/CollectionTest.php index 07c4350d2..baa8b8d3c 100644 --- a/tests/file/CollectionTest.php +++ b/tests/file/CollectionTest.php @@ -12,7 +12,7 @@ */ class CollectionTest extends TestCase { - protected function tearDown() + protected function tearDown(): void { $this->dropFileCollection('fs'); parent::tearDown(); diff --git a/tests/file/DownloadTest.php b/tests/file/DownloadTest.php index 0fb3dd037..3ae91b363 100644 --- a/tests/file/DownloadTest.php +++ b/tests/file/DownloadTest.php @@ -9,7 +9,7 @@ */ class DownloadTest extends TestCase { - protected function tearDown() + protected function tearDown(): void { $this->dropFileCollection('fs'); parent::tearDown(); @@ -67,4 +67,4 @@ public function testSubstr() $this->assertEquals('2345678', $download->substr(-8, 7), 'Unable to use negative start'); $this->assertEquals('234567', $download->substr(22, -2), 'Unable to use negative length'); } -} \ No newline at end of file +} diff --git a/tests/file/QueryTest.php b/tests/file/QueryTest.php index 46b2a564c..49d30694c 100644 --- a/tests/file/QueryTest.php +++ b/tests/file/QueryTest.php @@ -11,13 +11,13 @@ */ class QueryTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->setUpTestRows(); } - protected function tearDown() + protected function tearDown(): void { $this->dropFileCollection(); parent::tearDown(); diff --git a/tests/file/StreamWrapperTest.php b/tests/file/StreamWrapperTest.php index ac82c14dc..86a6f5eb3 100644 --- a/tests/file/StreamWrapperTest.php +++ b/tests/file/StreamWrapperTest.php @@ -6,7 +6,7 @@ class StreamWrapperTest extends TestCase { - protected function tearDown() + protected function tearDown(): void { $connection = $this->getConnection(); if (in_array($connection->fileStreamProtocol, stream_get_wrappers())) { @@ -80,7 +80,7 @@ public function testReadResource() $this->assertEquals('test content', stream_get_contents($resource)); } - + public function testSeek() { $connection = $this->getConnection(); @@ -97,21 +97,21 @@ public function testSeek() $resource = fopen($url, 'w'); fwrite($resource, 'begin end'); fclose($resource); - + $url = "gridfs://{$databaseName}.fs?filename=test.txt"; $resource = fopen($url, 'r'); $data = fgets($resource); - + fseek($resource, 0); $position = ftell($resource); $this->assertEquals(0, $position); - + fseek($resource, 2, SEEK_CUR); $position = ftell($resource); $this->assertEquals(2, $position); - + fseek($resource, 0, SEEK_END); $position = ftell($resource); $this->assertEquals(9, $position); } -} \ No newline at end of file +} diff --git a/tests/file/UploadTest.php b/tests/file/UploadTest.php index 95983d4e8..20f266c7f 100644 --- a/tests/file/UploadTest.php +++ b/tests/file/UploadTest.php @@ -10,7 +10,7 @@ */ class UploadTest extends TestCase { - protected function tearDown() + protected function tearDown(): void { $this->dropFileCollection('fs'); parent::tearDown(); @@ -114,4 +114,4 @@ public function testCustomId() $document = $upload->addContent('object ID')->complete(); $this->assertSame($id, $document['_id']); } -} \ No newline at end of file +} diff --git a/tests/i18n/MongoDbMessageSourceTest.php b/tests/i18n/MongoDbMessageSourceTest.php index d2f7273a9..7c49e9ee7 100644 --- a/tests/i18n/MongoDbMessageSourceTest.php +++ b/tests/i18n/MongoDbMessageSourceTest.php @@ -14,7 +14,7 @@ class MongoDbMessageSourceTest extends TestCase public $i18n; - protected function setUp() + protected function setUp(): void { $this->mockApplication(); parent::setUp(); @@ -22,7 +22,7 @@ protected function setUp() $this->setupI18N(); } - protected function tearDown() + protected function tearDown(): void { $this->dropCollection('message'); parent::tearDown(); @@ -138,4 +138,4 @@ public function testTranslatePriority() // Ensure fallback entry does not override main one: $this->assertEquals('Здравствуй Мир! (ru-RU)', $this->i18n->translate('test', 'Hello world!', [], 'ru-RU')); } -} \ No newline at end of file +} diff --git a/tests/log/MongoDbTargetTest.php b/tests/log/MongoDbTargetTest.php index 2c9847f19..a3717271b 100644 --- a/tests/log/MongoDbTargetTest.php +++ b/tests/log/MongoDbTargetTest.php @@ -8,7 +8,7 @@ class MongoDbTargetTest extends TestCase { - protected function tearDown() + protected function tearDown(): void { $this->dropCollection('log'); parent::tearDown(); @@ -60,4 +60,4 @@ public function testExport() $this->assertEquals($target->messages[1][2], $rows[1]['category']); $this->assertEquals($target->messages[1][3], $rows[1]['log_time']); } -} \ No newline at end of file +} diff --git a/tests/rbac/MongoDbManagerTest.php b/tests/rbac/MongoDbManagerTest.php index 5800aef55..c3b497456 100644 --- a/tests/rbac/MongoDbManagerTest.php +++ b/tests/rbac/MongoDbManagerTest.php @@ -20,13 +20,13 @@ class MongoDbManagerTest extends TestCase protected $auth; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->auth = $this->createManager(); } - protected function tearDown() + protected function tearDown(): void { $this->dropCollection('auth_item'); $this->dropCollection('auth_assignment'); @@ -160,8 +160,8 @@ public function testGetRules() $ruleNames[] = $rule->name; } - $this->assertContains('isReallyReallyAuthor', $ruleNames); - $this->assertContains('isAuthor', $ruleNames); + $this->assertStringContainsString('isReallyReallyAuthor', $ruleNames); + $this->assertStringContainsString('isAuthor', $ruleNames); } public function testRemoveRule() @@ -362,8 +362,8 @@ public function testAssignMultipleRoles() $roleNames[] = $role->name; } - $this->assertContains('reader', $roleNames, 'Roles should contain reader. Currently it has: ' . implode(', ', $roleNames)); - $this->assertContains('author', $roleNames, 'Roles should contain author. Currently it has: ' . implode(', ', $roleNames)); + $this->assertStringContainsString('reader', $roleNames, 'Roles should contain reader. Currently it has: ' . implode(', ', $roleNames)); + $this->assertStringContainsString('author', $roleNames, 'Roles should contain author. Currently it has: ' . implode(', ', $roleNames)); } public function testAssignmentsToIntegerId() @@ -521,4 +521,4 @@ public function testInvalidateCache() $this->assertFalse($auth->cache->exists($auth->cacheKey)); } -} \ No newline at end of file +} diff --git a/tests/validators/MongoDateValidatorTest.php b/tests/validators/MongoDateValidatorTest.php index 32faf0efe..a296cfda2 100644 --- a/tests/validators/MongoDateValidatorTest.php +++ b/tests/validators/MongoDateValidatorTest.php @@ -9,7 +9,7 @@ class MongoDateValidatorTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->mockApplication(); @@ -59,4 +59,4 @@ public function rules() ['date', MongoDateValidator::className(), 'format' => 'MM/dd/yyyy', 'mongoDateAttribute' => 'mongoDate'] ]; } -} \ No newline at end of file +} diff --git a/tests/validators/MongoIdValidatorTest.php b/tests/validators/MongoIdValidatorTest.php index 6c8208163..37fa946fb 100644 --- a/tests/validators/MongoIdValidatorTest.php +++ b/tests/validators/MongoIdValidatorTest.php @@ -9,7 +9,7 @@ class MongoIdValidatorTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->mockApplication(); @@ -69,4 +69,4 @@ public function testConvertValue() class MongoIdTestModel extends Model { public $id; -} \ No newline at end of file +} From a77d1b38ff09c89f4c5aa013ba088a30b1beed40 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 27 Sep 2023 07:53:24 -0300 Subject: [PATCH 2/9] Add type hint. --- tests/console/controllers/MigrateControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/console/controllers/MigrateControllerTest.php b/tests/console/controllers/MigrateControllerTest.php index bcbd92dbd..9466abb05 100644 --- a/tests/console/controllers/MigrateControllerTest.php +++ b/tests/console/controllers/MigrateControllerTest.php @@ -52,7 +52,7 @@ public function setUp(): void Yii::$app->setComponents(['mongodb' => $this->getConnection()]); } - public function tearDown() + protected function tearDown(): void { parent::tearDown(); if (extension_loaded('mongodb')) { From 5ef9184cbf625a1d752ef120a429759c8a43c84a Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 27 Sep 2023 07:58:57 -0300 Subject: [PATCH 3/9] Fix minor corrections. --- tests/CommandTest.php | 2 +- tests/console/controllers/MigrateControllerTest.php | 6 +++--- tests/rbac/MongoDbManagerTest.php | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 3706b5748..101c84e95 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -343,7 +343,7 @@ public function testListCollections() $collections = $connection->createCommand()->listCollections(); $collectionNames = ArrayHelper::getColumn($collections, 'name'); - $this->assertStringContainsString('customer', $collectionNames); + $this->assertContains('customer', $collectionNames); } /** diff --git a/tests/console/controllers/MigrateControllerTest.php b/tests/console/controllers/MigrateControllerTest.php index 9466abb05..f8e0b5c07 100644 --- a/tests/console/controllers/MigrateControllerTest.php +++ b/tests/console/controllers/MigrateControllerTest.php @@ -368,7 +368,7 @@ public function testNamespaceCreate() $files = FileHelper::findFiles($this->migrationPath); $fileContent = file_get_contents($files[0]); $this->assertStringContainsString("namespace {$this->migrationNamespace};", $fileContent); - $this->assertRegExp('/class M[0-9]{12}' . ucfirst($migrationName) . '/s', $fileContent); + $this->assertMatchesRegularExpression('/class M[0-9]{12}' . ucfirst($migrationName) . '/s', $fileContent); unlink($files[0]); // namespace specify : @@ -454,8 +454,8 @@ public function testNamespaceHistory() $this->runMigrateControllerAction('up', [], $controllerConfig); $output = $this->runMigrateControllerAction('history', [], $controllerConfig); - $this->assertRegExp('/' . preg_quote($this->migrationNamespace) . '.*History1/s', $output); - $this->assertRegExp('/' . preg_quote($this->migrationNamespace) . '.*History2/s', $output); + $this->assertMatchesRegularExpression('/' . preg_quote($this->migrationNamespace) . '.*History1/s', $output); + $this->assertMatchesRegularExpression('/' . preg_quote($this->migrationNamespace) . '.*History2/s', $output); } /** diff --git a/tests/rbac/MongoDbManagerTest.php b/tests/rbac/MongoDbManagerTest.php index c3b497456..f9ce2fc61 100644 --- a/tests/rbac/MongoDbManagerTest.php +++ b/tests/rbac/MongoDbManagerTest.php @@ -160,8 +160,8 @@ public function testGetRules() $ruleNames[] = $rule->name; } - $this->assertStringContainsString('isReallyReallyAuthor', $ruleNames); - $this->assertStringContainsString('isAuthor', $ruleNames); + $this->assertContains('isReallyReallyAuthor', $ruleNames); + $this->assertContains('isAuthor', $ruleNames); } public function testRemoveRule() @@ -362,8 +362,8 @@ public function testAssignMultipleRoles() $roleNames[] = $role->name; } - $this->assertStringContainsString('reader', $roleNames, 'Roles should contain reader. Currently it has: ' . implode(', ', $roleNames)); - $this->assertStringContainsString('author', $roleNames, 'Roles should contain author. Currently it has: ' . implode(', ', $roleNames)); + $this->assertContains('reader', $roleNames, 'Roles should contain reader. Currently it has: ' . implode(', ', $roleNames)); + $this->assertContains('author', $roleNames, 'Roles should contain author. Currently it has: ' . implode(', ', $roleNames)); } public function testAssignmentsToIntegerId() From ccb64d5df067ba5a1645ed3691bce5fb2bc5d96e Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 27 Sep 2023 08:34:18 -0300 Subject: [PATCH 4/9] Add `.scrutinizer.yml`. --- .scrutinizer.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .scrutinizer.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 000000000..cd35cd818 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,34 @@ +checks: + php: true + +filter: + paths: + - src/ + +build: + image: default-bionic + + environment: + php: + version: 8.0.18 + ini: + xdebug.mode: coverage + + nodes: + analysis: + tests: + override: + - php-scrutinizer-run + + phpunit: + services: + mongo: 3 + + dependencies: + override: + - composer self-update + - composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + tests: + override: + - command: ./vendor/bin/phpunit From 23ef55bb8ed17aaf3ff4bdeb4d4151460ef5a57c Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 27 Sep 2023 08:57:51 -0300 Subject: [PATCH 5/9] Fix service mongo-db. --- .scrutinizer.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index cd35cd818..d49beaa71 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -22,7 +22,8 @@ build: phpunit: services: - mongo: 3 + mongo-db: + image: mongo:3 dependencies: override: From cb82cb4bcb5cca6325b2df5a8b24f60a284802fe Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 27 Sep 2023 09:11:13 -0300 Subject: [PATCH 6/9] Install extension. --- .scrutinizer.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index d49beaa71..b0bbe45c5 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -27,6 +27,7 @@ build: dependencies: override: + - pecl install mongodb - composer self-update - composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi From 1f61fe447d52328637ff85196ae624b6bcd31fe8 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 27 Sep 2023 09:19:44 -0300 Subject: [PATCH 7/9] Add port for default. --- .scrutinizer.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index b0bbe45c5..b13f76aba 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -25,6 +25,9 @@ build: mongo-db: image: mongo:3 + ports: + - 27017 + dependencies: override: - pecl install mongodb From 108f7ce69455f5113f20067287a098c03e60d863 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Fri, 29 Sep 2023 13:15:46 -0300 Subject: [PATCH 8/9] Fix minor corrections. --- .editorconfig | 3 + .github/workflows/build.yml | 131 +++++++++++++++++------------------- phpunit.xml.dist | 36 +++++++--- 3 files changed, 90 insertions(+), 80 deletions(-) diff --git a/.editorconfig b/.editorconfig index 257221d23..5e9a93ea5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,6 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false + +[*.yml] +indent_size = 2 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3c1d4c92d..6285e999a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,77 +1,70 @@ on: - pull_request: - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'psalm.xml' + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' - push: - branches: ['master'] - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'psalm.xml' + push: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' name: build -env: - DEFAULT_COMPOSER_FLAGS: "--prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi" - jobs: - phpunit: - name: PHP ${{ matrix.php }} (mongodb ${{ matrix.mongoext }}) on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - services: - mongodb: - image: mongo:${{ matrix.mongo }} - ports: + phpunit: + name: PHP ${{ matrix.php }} (mongodb ${{ matrix.mongoext }}) on ${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + services: + mongodb: + image: mongo:${{ matrix.mongo }} + ports: - 27017:27017 - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - php: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] - mongo: ['3'] - mongoext: ['1.8.2', '1.9.0'] + strategy: + matrix: + os: [ubuntu-latest] + php: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] + mongo: ['3'] + mongoext: ['1.8.2', '1.9.0'] + + steps: + - name: Checkout. + uses: actions/checkout@v2 + + - name: Install PHP. + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: pecl + extensions: mongodb-${{ matrix.mongoext }} + ini-values: date.timezone='UTC' + + - name: Install dependencies with composer. + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run tests with phpunit. + if: matrix.php != '8.1' + run: vendor/bin/phpunit --colors=always + + - name: Run tests with phpunit and generate coverage. + if: matrix.php == '8.1' + run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - tools: pecl - extensions: mongodb-${{ matrix.mongoext }} - ini-values: date.timezone='UTC' - - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Cache composer dependencies - uses: actions/cache@v1 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- - - name: Install dependencies - run: composer update $DEFAULT_COMPOSER_FLAGS - - name: Run unit tests with coverage - run: vendor/bin/phpunit --verbose --coverage-clover=coverage.clover --colors=always - if: matrix.php == '7.1' - - name: Run unit tests without coverage - run: vendor/bin/phpunit --verbose --colors=always - if: matrix.php != '7.1' - - name: Upload code coverage - run: | - wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover coverage.clover - if: matrix.php == '7.1' - continue-on-error: true # if is fork + - name: Upload coverage to Codecov. + if: matrix.php == '8.1' + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.xml diff --git a/phpunit.xml.dist b/phpunit.xml.dist index fadd1bde6..1f53eacc4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,27 @@ - - - - ./tests - - + + + + + + + + + ./tests + + + + + + ./src + + From f8f19a635ffa2eb6b7608d372b08b6e46419bb2c Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Fri, 29 Sep 2023 13:18:37 -0300 Subject: [PATCH 9/9] Update `README.md`. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index e48ccdce7..c999aa57a 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,12 @@ Documentation is at [docs/guide/README.md](docs/guide/README.md). [![Latest Stable Version](https://poser.pugx.org/yiisoft/yii2-mongodb/v/stable.png)](https://packagist.org/packages/yiisoft/yii2-mongodb) [![Total Downloads](https://poser.pugx.org/yiisoft/yii2-mongodb/downloads.png)](https://packagist.org/packages/yiisoft/yii2-mongodb) [![Build Status](https://github.com/yiisoft/yii2-mongodb/workflows/build/badge.svg)](https://github.com/yiisoft/yii2-mongodb/actions) +[![codecov](https://codecov.io/gh/yiisoft/yii2-mongodb/graph/badge.svg?token=1Xo867R6He)](https://codecov.io/gh/yiisoft/yii2-mongodb) +Requirements +------------ + +- PHP 7.3 or higher. Installation ------------