<#327 chore: Replace atLeastAndMostLike by constra...
# pact-php
g
#327 chore: Replace atLeastAndMostLike by constrainedArrayLike Pull request opened by tienvx Old description
atLeastAndMostLike
is my invention from #310, and I don't think it's useful. Instead, I replace it with
arrayLike
(which is also my invention).
arrayLike
do what
atLeastAndMostLike
do, which is checking both
min
and
max
, but it also: • Allow any array as example value (so example value doesn't need to be a value appear multiple times) • Allow min = 0 (in this case example value doesn't need to be empty array) • Min can be null • Max can be null • Min and max can be both null (now it become
$matcher->like()
) • Min and max are not null (
atLeastAndMostLike
above) for example (UPDATED):
Copy code
$fatherUuid = '67b06dc7-af63-41c7-b011-f9bbbe6f5d45';
$motherUuid = '73778b18-f6de-4193-9b5d-970b9a5aacb5';
$childUuid = '977e35b8-ded1-4380-b206-b64c0bc0a312';
$user = [
    'id' => $matcher->uuid($childUuid),
    'gender' => $matcher->regex('male', 'male|female|other'),
    'firstName' => $macher->like('Bettye'),
    'lastName' => $macher->like('Johnston'),
    'birthday' => $matcher->date('yyyy-MM-dd', '2022-11-21'),
    'relationships' => $matcher->like([
        'spouses' => $matcher->arrayLike([$matcher->uuid('b21536d9-b0e4-4475-b9bc-b6d1d0716ba0')], 0),
        'father' => $matcher->uuid($fatherUuid),
        'mother' => $matcher->uuid($motherUuid),
        'children' => $matcher->arrayLike([$matcher->uuid('fb08f967-830b-4c09-a9ea-716a37b8fd85')], 0),
    ]),
];
$father = [
    'id' => $fatherUuid,
    'gender' => 'male',
    'firstName' => 'Deonte',
    'lastName' => 'Zulauf',
    'birthday' =>  '1970-11-21',
    'relationships' => $matcher->like([
        'spouses' => [$motherId],
        'father' => null,
        'mother' => null,
        'children' => [$childUuid],
    ]),
];
$mother = [
    'id' => $motherUuid,
    'gender' => 'female',
    'firstName' => 'Delpha',
    'lastName' => 'Ryan',
    'birthday' =>  '1986-11-21',
    'relationships' => $matcher->like([
        'spouses' => [$fatherUuid],
        'father' => null,
        'mother' => null,
        'children' => [$childUuid],
    ]),
];
$users = $matcher->arrayLike([
    $user,
    $father,
    $mother
], 1)
Link to specifications: • https://github.com/pact-foundation/pact-specification/tree/version-4#supported-matching-ruleshttps://github.com/pact-foundation/pact-specification/tree/version-3#supported-matchershttps://github.com/pact-foundation/pact-specification/tree/version-2#supported-matchers Code taken from pact-js pact-foundation/pact-php All checks have passed 26/26 successful checks