henrotaym / laravel-test-suite
为 Laravel 测试套件添加重复的功能。
v2.2.4
2023-01-15 22:15 UTC
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.5
README
安装
composer require henrotaym/laravel-test-suite
配置
您的测试用例应该使用此特性
Henrotaym\LaravelTestSuite\TestSuite
功能
模拟
/**
* Mocking given element.
*
* @param string $element Element to mock
* @return MockInterface
*/
protected function mockThis(string $element, bool $is_partial = false): MockInterface
获取私有属性
/**
* Getting private property value from given instance.
*
* @param string $property Property we're trying to access to.
* @param mixed $instance Instance where we access property.
* @return mixed Property value.
*/
protected function getPrivateProperty(string $property, $instance);
设置私有属性
/**
* Setting private property value in given instance.
*
* @param string $property Property we're trying to access to.
* @param mixed $value Value to set.
* @param mixed $instance Instance where we set value.
* @return mixed Instance in order to chain potential calls.
*/
protected function setPrivateProperty(string $property, $value, $instance);
调用私有方法
/**
* Calling private method from given instance.
*
* @param string $method Method we're trying to access to.
* @param mixed $instance Instance where we access method.
* @param mixed $parameters Arguments to give to method.
* @return mixed Method return value.
*/
protected function callPrivateMethod(string $method, $instance, ...$parameters);
模拟 Carbon 现在助手
/**
* Mocking Carbon now helper.
*
* @param Carbon $now Expected time returned when calling now().
* @return static
*/
public function mockCarbonNow(Carbon $now)