symplify/easy-testing
最新稳定版本:11.1.26
Composer 安装命令:
composer require symplify/easy-testing
包简介
Testing made easy
README 文档
README
Install
composer require symplify/easy-testing --dev
Usage
Easier working with Fixtures
Do you use unit fixture file format?
echo 'content before'; ?> ----- <?php echo 'content after'; ?>
Or in case of no change at all:
echo 'just this content';
The code is separated by -----. Top half of the file is input, the 2nd half is expected output.
It is common to organize test fixture in the test directory:
/tests/SomeTest/Fixture/added_comma.php.inc /tests/SomeTest/Fixture/skip_alreay_added_comma.php.inc
How this package makes it easy to work with them? 2 classes:
Symplify\EasyTesting\DataProvider\StaticFixtureFinderSymplify\EasyTesting\StaticFixtureSplitter
// tests/SomeTest/SomeTest.php namespace App\Tests\SomeTest; use Iterator; use PHPUnit\Framework\TestCase; use Symplify\EasyTesting\DataProvider\StaticFixtureFinder; use Symplify\EasyTesting\StaticFixtureSplitter; use Symplify\SmartFileSystem\SmartFileInfo; final class SomeTest extends TestCase { /** * @dataProvider provideData() */ public function test(SmartFileInfo $fileInfo): void { $inputAndExpected = StaticFixtureSplitter::splitFileInfoToInputAndExpected($fileInfo); // test before content $someService = new SomeService(); $changedContent = $someService->process($inputAndExpected->getInput()); $this->assertSame($inputAndExpected->getExpected(), $changedContent); } public function provideData(): Iterator { return StaticFixtureFinder::yieldDirectory(__DIR__ . '/Fixture'); } }
Features
Do you need the input code to be in separated files? E.g. to test the file was moved?
Instead of splitFileInfoToInputAndExpected() use splitFileInfoToLocalInputAndExpectedFileInfos():
-$inputAndExpected = StaticFixtureSplitter::splitFileInfoToInputAndExpected( +$inputFileInfoAndExpectedFileInfo = StaticFixtureSplitter::splitFileInfoToLocalInputAndExpectedFileInfos( $fileInfo );
Compared to formated method, splitFileInfoToLocalInputAndExpectedFileInfos() will:
- separate fixture to input and expected content
- save them both as separated files to temporary path
- optionally autoload the first one, e.g. if you need it for Reflection
use Symplify\EasyTesting\StaticFixtureSplitter; $inputFileInfoAndExpectedFileInfo = StaticFixtureSplitter::splitFileInfoToLocalInputAndExpectedFileInfos( $fileInfo, true );
By default, the StaticFixtureFinder finds only *.php.inc files.
use Symplify\EasyTesting\DataProvider\StaticFixtureFinder; return StaticFixtureFinder::yieldDirectory(__DIR__ . '/Fixture');
In case you use different files, e.g. *.twig or *.md, change it in 2nd argument:
use Symplify\EasyTesting\DataProvider\StaticFixtureFinder; return StaticFixtureFinder::yieldDirectory(__DIR__ . '/Fixture', '*.md');
Updating Fixture
How to Update Hundreds of Test Fixtures with Single PHPUnit run?
If you change an output of your software on purpose, you might want to update your fixture. Manually? No, from command line:
UPDATE_TESTS=1 vendor/bin/phpunit UT=1 vendor/bin/phpunit
To make this work, we have to add StaticFixtureUpdater::updateFixtureContent() call to our test case:
use PHPUnit\Framework\TestCase; use Symplify\EasyTesting\DataProvider\StaticFixtureUpdater; use Symplify\EasyTesting\StaticFixtureSplitter; use Symplify\SmartFileSystem\SmartFileInfo; final class SomeTestCase extends TestCase { /** * @dataProvider provideData() */ public function test(SmartFileInfo $fixtureFileInfo): void { $inputFileInfoAndExpectedFileInfo = StaticFixtureSplitter::splitFileInfoToLocalInputAndExpectedFileInfos( $fixtureFileInfo ); // process content $currentContent = '...'; // here we update test fixture if the content changed StaticFixtureUpdater::updateFixtureContent( $inputFileInfoAndExpectedFileInfo->getInputFileInfo(), $currentContent, $fixtureFileInfo ); } // data provider... }
Assert 2 Directories by Files and Content
Do you generate large portion of files? Do you want to skip nitpicking tests file by file?
Use assertDirectoryEquals() method to validate the files and their content is as expected.
use PHPUnit\Framework\TestCase; use Symplify\EasyTesting\PHPUnit\Behavior\DirectoryAssertableTrait; final class DirectoryAssertableTraitTest extends TestCase { use DirectoryAssertableTrait; public function testSuccess(): void { $this->assertDirectoryEquals(__DIR__ . '/Fixture/first_directory', __DIR__ . '/Fixture/second_directory'); } }
Report Issues
In case you are experiencing a bug or want to request a new feature head over to the Symplify monorepo issue tracker
Contribute
The sources of this package are contained in the Symplify monorepo. We welcome contributions for this package on symplify/symplify.
symplify/easy-testing 适用场景与选型建议
symplify/easy-testing 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.66M 次下载、GitHub Stars 达 42, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 symplify/easy-testing 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 symplify/easy-testing 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 7.66M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 42
- 点击次数: 9
- 依赖项目数: 16
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04