Skip to content
Permalink
Browse files

Reject non-iterable parameter groups

  • Loading branch information...
ShiraNai7 authored and sebastianbergmann committed Aug 28, 2019
1 parent 2d1e399 commit 72098d80f0cfc06c7e0652d331602685ce5b4b51
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* 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
{
}
@@ -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;
/**
@@ -42,6 +43,16 @@ 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);
@@ -9,6 +9,7 @@
*/
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\InvalidParameterGroupException;
use PHPUnit\Framework\TestCase;
class ConsecutiveParametersTest extends TestCase
@@ -65,4 +66,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
);
}
}

1 comment on commit 72098d8

@TomasVotruba

This comment has been minimized.

Copy link
Contributor

TomasVotruba commented on 72098d8 Oct 10, 2019

This BC breaked our tests.
How did this worked before?

Please sign in to comment.
You can’t perform that action at this time.