2017 © Pedro Peláez
 

library mockery-extras

Extra matching tools for the Mockery framework.

image

synaq/mockery-extras

Extra matching tools for the Mockery framework.

  • Tuesday, April 25, 2017
  • by willemnviljoen
  • Repository
  • 3 Watchers
  • 0 Stars
  • 2,361 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 7 % Grown

The README.md

mockery-extras

Extra matching tools for the Mockery framework., (*1)

ArrayPath

Matches an array if an element identified by the specified array path contains the expected value., (*2)

The syntax for array paths is as defined by mathiasgrimm/arraypath., (*3)

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:, (*4)

$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., (*5)

JsonPath

Matches a JSON string if a child node identified by the given jsonpath expression contains the expected value., (*6)

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., (*7)

Please see documentation for the library package for more details on usage., (*8)

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:, (*9)

{
    "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., (*10)

The Versions

25/04 2017

dev-master

9999999-dev

Extra matching tools for the Mockery framework.

  Sources   Download

BSD Simplified License

The Requires

 

The Development Requires

by Willem Viljoen

30/06 2016

0.2

0.2.0.0

Extra matching tools for the Mockery framework.

  Sources   Download

BSD Simplified License

The Requires

 

The Development Requires

by Willem Viljoen

30/06 2016

dev-develop

dev-develop

Extra matching tools for the Mockery framework.

  Sources   Download

BSD Simplified License

The Requires

 

The Development Requires

by Willem Viljoen

28/06 2016

0.1

0.1.0.0

Extra matching tools for the Mockery framework.

  Sources   Download

BSD Simplified License

The Requires

 

The Development Requires

by Willem Viljoen