cekurte / tdd
PHPUnit 测试用例
v1.0.2
2016-04-29 19:19 UTC
Requires
- php: >=5.3
Requires (Dev)
- fabpot/php-cs-fixer: ^1.10
- phpunit/phpunit: ^4.8
This package is auto-updated.
Last update: 2024-09-16 01:59:40 UTC
README
- 这是一个对PHPUnit库的简单扩展。
- 目前此包仅包含对一种测试用例场景的支持 ReflectionTestCase 为这个项目做出贡献!
安装
composer require cekurte/tdd
如果你喜欢这个库,给我一个星标 =)。
文档
此库的创建是为了允许开发者使用一个公共基类编写PHP单元测试,最初包括以下任务
- 设置私有、受保护或公开属性的值;
- 获取私有、受保护或公开属性的值;
- 调用私有、受保护或公开的方法。
设置属性值
要设置属性值(无论可见性如何),可以使用如下示例中的ReflectionTestCase::propertySetValue
方法
<?php namespace Your\Namespace; use Cekurte\Tdd\ReflectionTestCase; class YourClassTest extends ReflectionTestCase { public function testAnything() { // Instance of a class that has one // private property named "yourPrivateProperty". $instance = new YourClass(); // Set the value "newValue" to the property // "yourPrivateProperty". $this->propertySetValue( $instance, 'yourPrivateProperty', 'newValue' ); // ... } }
获取属性值
要获取属性值(无论可见性如何),可以使用如下示例中的ReflectionTestCase::propertyGetValue
方法
<?php namespace Your\Namespace; use Cekurte\Tdd\ReflectionTestCase; class YourClassTest extends ReflectionTestCase { public function testAnything() { // Instance of a class that has one // private property named "yourPrivateProperty". $instance = new YourClass(); // Get the value of the property // "yourPrivateProperty". $currentValue = $this->propertyGetValue( $instance, 'yourPrivateProperty' ); // ... } }
调用方法
要调用方法(无论可见性如何),可以使用如下示例中的ReflectionTestCase::invokeMethod
方法
<?php namespace Your\Namespace; use Cekurte\Tdd\ReflectionTestCase; class YourClassTest extends ReflectionTestCase { public function testAnything() { // Instance of a class that has one // private property named "yourPrivateMethod". $instance = new YourClass(); // Call the method // "yourPrivateMethod". $valueReturned = $this->invokeMethod( $instance, 'yourPrivateMethod', ['param1', 'param2', 'paramN'] ); // ... } }
贡献
- 给我一个星标 =)
- 分支它
- 创建你的功能分支(
git checkout -b my-new-feature
) - 进行更改
- 运行测试,如果需要添加新测试则添加(
vendor/bin/phpunit
) - 提交更改(
git commit -am 'Added some feature'
) - 推送到分支(
git push origin my-new-feature
) - 创建新的Pull Request