synaq/mockery-extras 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD
  • 更新时间: 2016-06-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固