From 9de9bce65d8b7a8038afa5799e18721b6ec1bbb4 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Wed, 13 May 2026 13:49:24 +0700 Subject: [PATCH 1/7] Add bootstrap config --- .github/workflows/composer-require-checker.yml | 8 ++------ .github/workflows/rector-cs.yml | 1 + .github/workflows/static.yml | 11 ++++------- composer.json | 9 ++++++++- config/bootstrap.php | 16 ++++++++++++++++ 5 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 config/bootstrap.php diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml index 2f8aece62..5455811ee 100644 --- a/.github/workflows/composer-require-checker.yml +++ b/.github/workflows/composer-require-checker.yml @@ -1,6 +1,6 @@ on: pull_request: - paths: + paths: &paths - 'src/**' - '.github/workflows/composer-require-checker.yml' - 'composer.json' @@ -8,11 +8,7 @@ on: push: branches: ['master'] - paths: - - 'src/**' - - '.github/workflows/composer-require-checker.yml' - - 'composer.json' - - 'composer-require-checker.json' + paths: *paths name: Composer require checker diff --git a/.github/workflows/rector-cs.yml b/.github/workflows/rector-cs.yml index f5b581b1a..1bff7b99d 100644 --- a/.github/workflows/rector-cs.yml +++ b/.github/workflows/rector-cs.yml @@ -4,6 +4,7 @@ on: pull_request: paths: - 'src/**' + - 'config/**' - 'tests/**' - '.github/workflows/rector-cs.yml' - 'composer.json' diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 287f4ac96..2041ed935 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -1,18 +1,15 @@ on: pull_request: - paths: + paths: &paths - 'src/**' + - 'config/**' - '.github/workflows/static.yml' - 'psalm*.xml' - 'composer.json' push: branches: ['master'] - paths: - - 'src/**' - - '.github/workflows/static.yml' - - 'psalm*.xml' - - 'composer.json' + paths: *paths name: Static analysis @@ -25,6 +22,6 @@ jobs: uses: yiisoft/actions/.github/workflows/psalm.yml@master with: php: >- - ['8.1', '8.2', '8.3', '8.4'] + ['8.1', '8.2', '8.3', '8.4', '8.5'] required-packages: >- ['db'] diff --git a/composer.json b/composer.json index 14ee2f66c..87002906a 100644 --- a/composer.json +++ b/composer.json @@ -75,13 +75,20 @@ "bin-links": true, "target-directory": "tools", "forward-command": true + }, + "config-plugin-options": { + "source-directory": "config" + }, + "config-plugin": { + "bootstrap": "bootstrap.php" } }, "config": { "sort-packages": true, "allow-plugins": { "bamarni/composer-bin-plugin": true, - "composer/package-versions-deprecated": true + "composer/package-versions-deprecated": true, + "yiisoft/config": false } }, "scripts": { diff --git a/config/bootstrap.php b/config/bootstrap.php new file mode 100644 index 000000000..b66d7068c --- /dev/null +++ b/config/bootstrap.php @@ -0,0 +1,16 @@ + + */ +return [ + static function (ContainerInterface $container): void { + ConnectionProvider::set($container->get(ConnectionInterface::class)); + }, +]; From 9bc1fda41a6599a7583aecf1798a12b8497a1027 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Wed, 13 May 2026 14:40:14 +0700 Subject: [PATCH 2/7] Add test + changelog --- CHANGELOG.md | 1 + composer.json | 3 +- tests/Driver/Sqlite/ConfigTest.php | 58 ++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/Driver/Sqlite/ConfigTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 036d4bc04..dc5096ee1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Bug #561: Fix `ActiveRecordInterface::upsert()` with `$updateProperties = false` (@Tigrov) - Bug #550: Relation query should be created by related class, not primary model class (@batyrmastyr) - Enh #571: Optimize performance of `ActiveRecord::get()` method (@Tigrov) +- Enh #576: Add default config for `yiisoft/config` plugin (@Tigrov) ## 1.0.2 March 11, 2026 diff --git a/composer.json b/composer.json index 87002906a..0c0766f7e 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,8 @@ "yiisoft/event-dispatcher": "^1.1", "yiisoft/factory": "^1.3", "yiisoft/psr-dummy-provider": "^1.0", - "yiisoft/test-support": "^3.0.2" + "yiisoft/test-support": "^3.0.2", + "yiisoft/yii-runner": "^2.2" }, "suggest": { "yiisoft/arrays": "For \\Yiisoft\\Arrays\\ArrayableInterface support", diff --git a/tests/Driver/Sqlite/ConfigTest.php b/tests/Driver/Sqlite/ConfigTest.php new file mode 100644 index 000000000..2e3f927bd --- /dev/null +++ b/tests/Driver/Sqlite/ConfigTest.php @@ -0,0 +1,58 @@ +createConsoleContainer(); + $bootstrapList = $this->getBootstrapList(); + + $this->assertFalse(ConnectionProvider::has()); + + (new BootstrapRunner($container, $bootstrapList))->run(); + + $this->assertTrue(ConnectionProvider::has()); + $this->assertInstanceOf(SQLiteConnection::class, ConnectionProvider::get()); + } + + private function createConsoleContainer(): Container + { + $config = ContainerConfig::create() + ->withDefinitions( + [ + CacheInterface::class => MemorySimpleCache::class, + + ConnectionInterface::class => [ + 'class' => SQLiteConnection::class, + '__construct()' => [ + 'driver' => new SQLiteDriver('sqlite::memory:'), + ], + ], + ], + ); + + return new Container($config); + } + + private function getBootstrapList(): array + { + return require dirname(__DIR__, 3) . '/config/bootstrap.php'; + } +} From d1eaea79f75f178d7f11ec75d7c10302643ab115 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Wed, 13 May 2026 14:48:58 +0700 Subject: [PATCH 3/7] Improve test --- tests/Driver/Sqlite/ConfigTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Driver/Sqlite/ConfigTest.php b/tests/Driver/Sqlite/ConfigTest.php index 2e3f927bd..3e85ed78f 100644 --- a/tests/Driver/Sqlite/ConfigTest.php +++ b/tests/Driver/Sqlite/ConfigTest.php @@ -19,6 +19,14 @@ final class ConfigTest extends TestCase { + protected function tearDown(): void + { + ConnectionProvider::get()->close(); + ConnectionProvider::remove(); + + parent::tearDown(); + } + public function testBootstrap(): void { $container = $this->createConsoleContainer(); From f6beb7ac6b13895f8e8820fd1e399ff232bf6d4b Mon Sep 17 00:00:00 2001 From: Tigrov Date: Wed, 13 May 2026 14:49:53 +0700 Subject: [PATCH 4/7] Improve test --- tests/Driver/Sqlite/ConfigTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Driver/Sqlite/ConfigTest.php b/tests/Driver/Sqlite/ConfigTest.php index 3e85ed78f..b70a569f3 100644 --- a/tests/Driver/Sqlite/ConfigTest.php +++ b/tests/Driver/Sqlite/ConfigTest.php @@ -21,8 +21,10 @@ final class ConfigTest extends TestCase { protected function tearDown(): void { - ConnectionProvider::get()->close(); - ConnectionProvider::remove(); + if (ConnectionProvider::has()) { + ConnectionProvider::get()?->close(); + ConnectionProvider::remove(); + } parent::tearDown(); } From 3c6453f349185c5f84893ca3ea7629e65f1c6fb5 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Wed, 13 May 2026 14:50:07 +0700 Subject: [PATCH 5/7] Improve test --- tests/Driver/Sqlite/ConfigTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Driver/Sqlite/ConfigTest.php b/tests/Driver/Sqlite/ConfigTest.php index b70a569f3..13839b7fa 100644 --- a/tests/Driver/Sqlite/ConfigTest.php +++ b/tests/Driver/Sqlite/ConfigTest.php @@ -22,7 +22,7 @@ final class ConfigTest extends TestCase protected function tearDown(): void { if (ConnectionProvider::has()) { - ConnectionProvider::get()?->close(); + ConnectionProvider::get()->close(); ConnectionProvider::remove(); } From 19ded0e310a1ecac2456cd5a4987678fe5d51483 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Wed, 13 May 2026 16:23:04 +0700 Subject: [PATCH 6/7] Fix merge --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4347ff503..f3d98ef43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,8 @@ - Bug #561: Fix `ActiveRecordInterface::upsert()` with `$updateProperties = false` (@Tigrov) - Bug #550: Relation query should be created by related class, not primary model class (@batyrmastyr) - Enh #571: Optimize performance of `ActiveRecord::get()` method (@Tigrov) -- Enh #576: Add default config for `yiisoft/config` plugin (@Tigrov) - Enh #575: Remove check for empty string in `AbstractActiveRecord::markPropertyChanged()` method (@Tigrov) +- Enh #576: Add default config for `yiisoft/config` plugin (@Tigrov) ## 1.0.2 March 11, 2026 From fb7881a441a2f8d8d13d24bfc01ea3bcdc0f7a98 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Wed, 13 May 2026 16:26:28 +0700 Subject: [PATCH 7/7] Fix test --- tests/Driver/Sqlite/ConfigTest.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/Driver/Sqlite/ConfigTest.php b/tests/Driver/Sqlite/ConfigTest.php index 13839b7fa..6ba7226d0 100644 --- a/tests/Driver/Sqlite/ConfigTest.php +++ b/tests/Driver/Sqlite/ConfigTest.php @@ -31,7 +31,7 @@ protected function tearDown(): void public function testBootstrap(): void { - $container = $this->createConsoleContainer(); + $container = $this->createContainer(); $bootstrapList = $this->getBootstrapList(); $this->assertFalse(ConnectionProvider::has()); @@ -42,21 +42,18 @@ public function testBootstrap(): void $this->assertInstanceOf(SQLiteConnection::class, ConnectionProvider::get()); } - private function createConsoleContainer(): Container + private function createContainer(): Container { $config = ContainerConfig::create() - ->withDefinitions( - [ - CacheInterface::class => MemorySimpleCache::class, - - ConnectionInterface::class => [ - 'class' => SQLiteConnection::class, - '__construct()' => [ - 'driver' => new SQLiteDriver('sqlite::memory:'), - ], + ->withDefinitions([ + CacheInterface::class => MemorySimpleCache::class, + ConnectionInterface::class => [ + 'class' => SQLiteConnection::class, + '__construct()' => [ + 'driver' => new SQLiteDriver('sqlite::memory:'), ], ], - ); + ]); return new Container($config); }