horat1us / yii2-phpunit
Yii 2 PHPUnit compatibility layer and enhancements
0.1.0
2026-10-26 11:38 UTC
Requires
- php: >=8.4
- phpunit/phpunit: ^13
- vlucas/phpdotenv: ^5.6.1
- yiisoft/yii2: ^2.0.54
Requires (Dev)
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-26 12:18:08 UTC
README
Yii 2 PHPUnit compatibility layer and enhancements This package includes:
- TestLogger - will display all log messages to console
- TestMailer - will collect all sent mails in memory
- TestCase - base TestCase, extends PHPUnit TestCase.
It will create new
\yii\console\Applicationinstance before each test and apply Yii2 fixtures. After each test it restores the error and exception handlers registered by the application. - MigrateFixture - Yii2 fixture that will apply migration. Use case: your package contains migrations and you need to apply it before tests.
Note: this package supposed to support old packages, that depends on it
Compatibility: tested on PHP 8.4, PHP 8.5 (PHPUnit 13).
Projects on PHPUnit 9 stay on 0.0.x.
Usage
- Install package and horat1us/yii2-phpunit as dev dependencies
composer require --dev horat1us/yii2-phpunit:^0.1
- Configure your PHPUnit and create bootstrap file with alias to config:
<?php // bootstrap.php Yii::setAlias('@configFile', 'path-to-config.php');
- Create your test cases that extend Horat1us\Yii\PHPUnit\TestCase
Testing
The tests use an in-memory SQLite database (pdo_sqlite).
Set DB_DSN, DB_USERNAME and DB_PASSWORD to run them against another database.
composer test
License
Example
See horat1us/yii2-advanced-package for details.