Skip to content

Commit

Permalink
Merge branch '8.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 7, 2019
2 parents 3ac7df2 + 04a02e7 commit 6489ce9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Framework/InvalidParameterGroupException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Framework;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class InvalidParameterGroupException extends Exception
{
}
11 changes: 11 additions & 0 deletions src/Framework/MockObject/Matcher/ConsecutiveParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\IsEqual;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\InvalidParameterGroupException;
use PHPUnit\Framework\MockObject\Invocation as BaseInvocation;

/**
Expand All @@ -35,6 +36,16 @@ final class ConsecutiveParameters extends StatelessInvocation
public function __construct(array $parameterGroups)
{
foreach ($parameterGroups as $index => $parameters) {
if (!\is_iterable($parameters)) {
throw new InvalidParameterGroupException(
\sprintf(
'Parameter group #%d must be an array or Traversable, got %s',
$index,
\gettype($parameters)
)
);
}

foreach ($parameters as $parameter) {
if (!$parameter instanceof Constraint) {
$parameter = new IsEqual($parameter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\InvalidParameterGroupException;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -68,4 +69,21 @@ public function testIntegrationExpectingException(): void

$mock->foo('invalid');
}

public function testIntegrationFailsWithNonIterableParameterGroup(): void
{
$mock = $this->getMockBuilder(stdClass::class)
->setMethods(['foo'])
->getMock();

$this->expectException(InvalidParameterGroupException::class);
$this->expectExceptionMessage('Parameter group #1 must be an array or Traversable, got object');

$mock->expects($this->any())
->method('foo')
->withConsecutive(
['bar'],
$this->identicalTo([21, 42]) // this is not an array
);
}
}

0 comments on commit 6489ce9

Please sign in to comment.