Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Use PHPUnit_Framework_TestFailure::exceptionToString if invocation expectations fail #108

Merged
merged 2 commits into from Nov 24, 2012
Jump to file or symbol
Failed to load files and symbols.
+44 −3
Split
@@ -300,7 +300,7 @@ public function verify()
$this->methodNameMatcher->toString(),
$this->invocationMatcher->toString(),
- $e->getMessage()
+ PHPUnit_Framework_TestFailure::exceptionToString($e)
)
);
}
View
@@ -473,7 +473,7 @@ public function testVerificationOfMethodNameFailsWithoutParameters()
} catch (PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertSame(
"Expectation failed for method name is equal to <string:right> when invoked 1 time(s).\n"
- . 'Method was expected to be called 1 times, actually called 0 times.',
+ . "Method was expected to be called 1 times, actually called 0 times.\n",
$e->getMessage()
);
}
@@ -494,7 +494,48 @@ public function testVerificationOfMethodNameFailsWithParameters()
} catch (PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertSame(
"Expectation failed for method name is equal to <string:right> when invoked 1 time(s).\n"
- . 'Method was expected to be called 1 times, actually called 0 times.',
+ . "Method was expected to be called 1 times, actually called 0 times.\n",
+ $e->getMessage()
+ );
+ }
+
+ $this->resetMockObjects();
+ }
+
+ public function testVerificationOfMethodNameFailsWithWrongParameters()
+ {
+ $mock = $this->getMock('SomeClass', array('right', 'wrong'), array(), '', TRUE, TRUE, TRUE);
+ $mock->expects($this->once())
+ ->method('right')
+ ->with(array('first', 'second'));
+
+ try {
+ $mock->right(array('second'));
+ } catch (PHPUnit_Framework_ExpectationFailedException $e) {
+ $this->assertSame(
+ "Expectation failed for method name is equal to <string: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()
+ );
+ }
+
+ try {
+ $mock->__phpunit_verify();
+ $this->fail('Expected exception');
+ } catch (PHPUnit_Framework_ExpectationFailedException $e) {
+ $this->assertSame(
+ "Expectation failed for method name is equal to <string: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"
+ . "+++ Actual\n"
+ . "@@ @@\n"
+ . " Array (\n"
+ . "- 0 => 'first'\n"
+ . "- 1 => 'second'\n"
+ . "+ 0 => 'second'\n"
+ . " )\n",
$e->getMessage()
);
}