fasano/phpunit-oop
最新稳定版本:v1.0.0
Composer 安装命令:
composer require fasano/phpunit-oop
包简介
Object-oriented test case design for PHPUnit
README 文档
README
Object-oriented test case design for PHPUnit.
This library doesn't add features. It adds constraints that encourage clarity.
The goal: bring the same design principles to your tests that you bring to your production code: encapsulation, polymorphism, and meaningful names. Read more
Installation
composer require --dev fasano/phpunit-oop
Core Concepts
TestSuite
Your test classes now extend TestSuite (which extends PHPUnit's TestCase):
use Fasano\PhpUnitOop\TestSuite; class SomeFeatureTest extends TestSuite { public static function cases(): array { return [ 'Case name' => new MyCaseObject(...), 'Another case' => new AnotherCaseObject(...), ]; } }
TestCase
Individual test scenarios extend TestCase:
use Fasano\PhpUnitOop\TestCase; class SuccessCase extends TestCase { public function __construct( public readonly MyClass $object, public readonly MyInput $input, public readonly MyResult $result, ) {} public function verify(): void { Assert::equals($this->result, $this->object->process($this->input)); } }
The verify() method contains your assertions. It is automatically called by the test runner.
Assert
A thin wrapper around PHPUnit's assertions to avoid naming collisions and unify the API:
use Fasano\PhpUnitOop\Assert; Assert::true($condition); Assert::false($condition); Assert::equals($expected, $actual); Assert::throws($exception, fn() => $this->dangerousOperation());
Requirements
- PHP 8.4 (other versions untested)
- PHPUnit 12.4 (other versions untested)
License
MIT
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-08