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/CHANGELOG.md b/CHANGELOG.md index a3ea2779f..f3d98ef43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - 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 #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 diff --git a/composer.json b/composer.json index 14ee2f66c..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", @@ -75,13 +76,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)); + }, +]; diff --git a/tests/Driver/Sqlite/ConfigTest.php b/tests/Driver/Sqlite/ConfigTest.php new file mode 100644 index 000000000..6ba7226d0 --- /dev/null +++ b/tests/Driver/Sqlite/ConfigTest.php @@ -0,0 +1,65 @@ +close(); + ConnectionProvider::remove(); + } + + parent::tearDown(); + } + + public function testBootstrap(): void + { + $container = $this->createContainer(); + $bootstrapList = $this->getBootstrapList(); + + $this->assertFalse(ConnectionProvider::has()); + + (new BootstrapRunner($container, $bootstrapList))->run(); + + $this->assertTrue(ConnectionProvider::has()); + $this->assertInstanceOf(SQLiteConnection::class, ConnectionProvider::get()); + } + + private function createContainer(): 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'; + } +}