avinash403 / phpunit-testing-kit
提供所有您测试PHP应用所需的辅助特性和类。
v1.0.0
2018-05-30 18:50 UTC
Requires (Dev)
- phpunit/phpunit: ^7.1
This package is not auto-updated.
Last update: 2024-09-23 13:52:54 UTC
README
PHP应用测试时可能用到的有用特性和类的集合。
通过Composer安装
$ composer require avinash403/phpunit-testing-kit
可用的特性和类
断言
包含一些常用的断言,但PHPunit没有提供。
使用方法
use TestingKit\Assertions;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
use Assertions;
public function test_exampleTest()
{
$this->assertAlpha('a');
}
}
可用的断言
* assertAlpha * assertNotAlpha * assertNumber * assertNotNumber * assertArrayHasKeys * assertStringContainsSubstring * assertStringNotContainsSubstring
PrivateAccess
允许测试类中的私有和受保护的方法和属性。
使用方法
use TestingKit\PrivateAccess;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
use PrivateAccess;
public function test_exampleTest_forGettingPrivateMethod()
{
$classObject = new Class();
//getting private method
$methodResponse = $this->getPrivateMethod($classObject, 'exampleMethod', ['some text']);
$this->assertEquals($methodResponse, 'some text');
}
}
class ExampleClass
{
private exampleMethod($someArgument)
{
return $someArgument;
}
}
可用的功能
* getPrivateMethod * setPrivateProperty * getPrivateProperty
测试
只需从本包的根目录简单地输入composer test
即可运行测试。
在github上贡献
克隆此仓库(https://github.com/avinash403/laravel-dynamic-observer.git),进行更改,并向开发分支提出pull请求