From d2d4a3088b14e0ef12e0b181c27d1cf20521b2ea Mon Sep 17 00:00:00 2001 From: Ciaran McNulty Date: Sat, 21 Dec 2019 07:13:23 +0000 Subject: [PATCH 1/2] Reproduce issue #446 with a failing test --- spec/Prophecy/Comparator/ClosureComparatorSpec.php | 6 +++--- tests/Argument/Token/ExactValueTokenTest.php | 13 +++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/spec/Prophecy/Comparator/ClosureComparatorSpec.php b/spec/Prophecy/Comparator/ClosureComparatorSpec.php index c174e73c0..b329ee24f 100644 --- a/spec/Prophecy/Comparator/ClosureComparatorSpec.php +++ b/spec/Prophecy/Comparator/ClosureComparatorSpec.php @@ -25,15 +25,15 @@ function it_accepts_only_closures() $this->accepts(function(){}, function(){})->shouldReturn(true); } - function it_asserts_that_all_closures_are_different() + function it_asserts_that_different_closures_are_different() { $this->shouldThrow()->duringAssertEquals(function(){}, function(){}); } - function it_asserts_that_all_closures_are_different_even_if_its_the_same_closure() + function it_asserts_that_closures_are_equal_if_its_the_same_closure() { $closure = function(){}; - $this->shouldThrow()->duringAssertEquals($closure, $closure); + $this->shouldNotThrow()->duringAssertEquals($closure, $closure); } } diff --git a/tests/Argument/Token/ExactValueTokenTest.php b/tests/Argument/Token/ExactValueTokenTest.php index eccda89cc..f53764e3b 100644 --- a/tests/Argument/Token/ExactValueTokenTest.php +++ b/tests/Argument/Token/ExactValueTokenTest.php @@ -30,6 +30,16 @@ public function scores_10_for_objects_with_same_fields() { self::assertEquals(10, $exactValueToken->scoreArgument($child2)); } + /** + * @test + */ + public function scores_10_for_matching_callables() { + $callable = function() {}; + + $exactValueToken = new ExactValueToken($callable); + self::assertEquals(10, $exactValueToken->scoreArgument($callable)); + } + /** * @test */ @@ -69,7 +79,6 @@ public function scores_false_for_object_and_null() { $exactValueToken = new ExactValueToken($child1); self::assertEquals(false, $exactValueToken->scoreArgument(null)); } - } @@ -93,4 +102,4 @@ public function __construct($name, $parent) { $this->parent->addChild($this); } -} \ No newline at end of file +} From 6bfa26f54711dd9076bbc784da05b3fd0e9e3bbb Mon Sep 17 00:00:00 2001 From: Ciaran McNulty Date: Sat, 21 Dec 2019 07:26:53 +0000 Subject: [PATCH 2/2] Compare identical closures as being the same --- src/Prophecy/Comparator/ClosureComparator.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Prophecy/Comparator/ClosureComparator.php b/src/Prophecy/Comparator/ClosureComparator.php index a80076c09..fa4f578ee 100644 --- a/src/Prophecy/Comparator/ClosureComparator.php +++ b/src/Prophecy/Comparator/ClosureComparator.php @@ -29,14 +29,16 @@ public function accepts($expected, $actual) public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false, array &$processed = array()) { - throw new ComparisonFailure( - $expected, - $actual, - // we don't need a diff - '', - '', - false, - 'all closures are born different' - ); + if ($expected !== $actual) { + throw new ComparisonFailure( + $expected, + $actual, + // we don't need a diff + '', + '', + false, + 'all closures are different if not identical' + ); + } } }