Skip to content

Commit

Permalink
Closes #3745
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 6, 2019
1 parent 424664d commit c17615c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
1 change: 1 addition & 0 deletions ChangeLog-8.3.md
Expand Up @@ -6,6 +6,7 @@ All notable changes of the PHPUnit 8.3 release series are documented in this fil

### Fixed

* Fixed [#3745](https://github.com/sebastianbergmann/phpunit/issues/3745): Performance degradation with test doubles
* Fixed [#3801](https://github.com/sebastianbergmann/phpunit/issues/3801): Class constant as default parameter is undefined
* Fixed [#3807](https://github.com/sebastianbergmann/phpunit/pull/3807): Fixed message of exception raised by `MockBuilder::addMethods()`

Expand Down
10 changes: 2 additions & 8 deletions src/Framework/MockObject/Matcher/MethodName.php
Expand Up @@ -10,8 +10,8 @@
namespace PHPUnit\Framework\MockObject\Matcher;

use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\IsEqual;
use PHPUnit\Framework\MockObject\Invocation as BaseInvocation;
use PHPUnit\Framework\MockObject\MethodNameConstraint;
use PHPUnit\Util\InvalidArgumentHelper;

/**
Expand All @@ -37,13 +37,7 @@ public function __construct($constraint)
throw InvalidArgumentHelper::factory(1, 'string');
}

$constraint = new IsEqual(
$constraint,
0,
10,
false,
true
);
$constraint = new MethodNameConstraint($constraint);
}

$this->constraint = $constraint;
Expand Down
45 changes: 45 additions & 0 deletions src/Framework/MockObject/MethodNameConstraint.php
@@ -0,0 +1,45 @@
<?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\MockObject;

use PHPUnit\Framework\Constraint\Constraint;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class MethodNameConstraint extends Constraint
{
/**
* @var string
*/
private $methodName;

public function __construct(string $methodName)
{
$this->methodName = \strtolower($methodName);
}

public function toString(): string
{
return \sprintf(
'is "%s"',
$this->methodName
);
}

protected function matches($other): bool
{
if (!\is_string($other)) {
return false;
}

return $this->methodName === \strtolower($other);
}
}
10 changes: 5 additions & 5 deletions tests/unit/Framework/MockObject/MockObjectTest.php
Expand Up @@ -670,7 +670,7 @@ public function testVerificationOfMethodNameFailsWithoutParameters(): void
$this->fail('Expected exception');
} catch (ExpectationFailedException $e) {
$this->assertSame(
"Expectation failed for method name is equal to 'right' when invoked 1 time(s).\n" .
"Expectation failed for method name is \"right\" when invoked 1 time(s).\n" .
'Method was expected to be called 1 times, actually called 0 times.' . "\n",
$e->getMessage()
);
Expand All @@ -695,7 +695,7 @@ public function testVerificationOfMethodNameFailsWithParameters(): void
$this->fail('Expected exception');
} catch (ExpectationFailedException $e) {
$this->assertSame(
"Expectation failed for method name is equal to 'right' when invoked 1 time(s).\n" .
"Expectation failed for method name is \"right\" when invoked 1 time(s).\n" .
'Method was expected to be called 1 times, actually called 0 times.' . "\n",
$e->getMessage()
);
Expand All @@ -718,7 +718,7 @@ public function testVerificationOfMethodNameFailsWithWrongParameters(): void
$mock->right(['second']);
} catch (ExpectationFailedException $e) {
$this->assertSame(
"Expectation failed for method name is equal to 'right' when invoked 1 time(s)\n" .
"Expectation failed for method name is \"right\" when invoked 1 time(s)\n" .
'Parameter 0 for invocation SomeClass::right(Array (...)) does not match expected value.' . "\n" .
'Failed asserting that two arrays are equal.',
$e->getMessage()
Expand All @@ -732,7 +732,7 @@ public function testVerificationOfMethodNameFailsWithWrongParameters(): void
// $this->fail('Expected exception');
} catch (ExpectationFailedException $e) {
$this->assertSame(
"Expectation failed for method name is equal to 'right' when invoked 1 time(s).\n" .
"Expectation failed for method name is \"right\" when invoked 1 time(s).\n" .
'Parameter 0 for invocation SomeClass::right(Array (...)) does not match expected value.' . "\n" .
'Failed asserting that two arrays are equal.' . "\n" .
'--- Expected' . "\n" .
Expand Down Expand Up @@ -811,7 +811,7 @@ public function testWithAnythingInsteadOfWithAnyParameters(): void
$this->fail('Expected exception');
} catch (ExpectationFailedException $e) {
$this->assertSame(
"Expectation failed for method name is equal to 'right' when invoked 1 time(s)\n" .
"Expectation failed for method name is \"right\" when invoked 1 time(s)\n" .
'Parameter count for invocation SomeClass::right() is too low.' . "\n" .
'To allow 0 or more parameters with any value, omit ->with() or use ->withAnyParameters() instead.',
$e->getMessage()
Expand Down

0 comments on commit c17615c

Please sign in to comment.