synaq/mockery-extras
Composer 安装命令:
composer require synaq/mockery-extras
包简介
Extra matching tools for the Mockery framework.
README 文档
README
Extra matching tools for the Mockery framework.
ArrayPath
Matches an array if an element identified by the specified array path contains the expected value.
The syntax for array paths is as defined by mathiasgrimm/arraypath.
Example
use Synaq\MockeryMatcher\ExtraMatchers;
$expectedValue = 'baz';
$arrayPath = 'foo/bar';
$dependency = Mockery::mock('DependencyOfObjectClassUnderTest');
$testSubject = new ObjectClassUnderTest($dependency);
$testSubject->performSomeAction();
$dependency->shouldHaveReceived('someMethodCallThatAcceptsAnArrayAsParameter')
->with(ExtraMatchers::arrayPath($expectedValue, $arrayPath))
->once;
The above invocation would match an array defined thus:
$array = [
'foo' => [
'bar' => 'baz'
]
];
These need not be the only elements in the array, nor does bar need to be the
only child element of foo. This allows tests to be crafted with very discrete
assertions regarding the structure of an array passed to a dependency of the
object class under test.
JsonPath
Matches a JSON string if a child node identified by the given jsonpath
expression contains the expected value.
The syntax and behaviour are derived from the skyscanner/jsonpath library. The
matcher uses the library's SmartGet behaviour by default, meaning that if a given
path does not branch, the value will be returned directly, rather than a single
element array containing the value, as is the usual jsonpath behaviour.
Please see documentation for the library package for more details on usage.
Example
use Synaq\MockeryMatcher\ExtraMatchers;
$expectedValue = 'baz';
$jsonPath = '$.foo.bar';
$dependency = Mockery::mock('DependencyOfObjectClassUnderTest');
$testSubject = new ObjectClassUnderTest($dependency);
$testSubject->performSomeAction();
$dependency->shouldHaveReceived('someMethodCallThatAcceptsAJsonStringAsParameter')
->with(ExtraMatchers::jsonPath($expectedValue, $jsonPath))
->once;
The above invocation would match the following JSON string:
{
"foo": {
"bar": "baz"
}
}
As with the ArrayPath matcher, the JSON string may encode any other
arbitrary data. The string will always be matched as long as the given
jsonpath expression leads to the expected value.
统计信息
- 总下载量: 2.87k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD
- 更新时间: 2016-06-28