Skip to content

Commit

Permalink
Made some general improvements to exception message so they include m…
Browse files Browse the repository at this point in the history
…ock name/class where relevant
  • Loading branch information
Padraic Brady committed May 27, 2010
1 parent e8f736d commit 70a3952
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
4 changes: 3 additions & 1 deletion library/Mockery/CountValidator/AtLeast.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function validate($n)
{
if ($this->_limit > $n) {
throw new Exception(
'Method should be called'
'Method ' . (string) $this->_expectation
. ' from ' . $this->_expectation->getMock()->mockery_getName()
. ' should be called' . PHP_EOL
. ' at least ' . $this->_limit . ' times but called ' . $n
. ' times.'
);
Expand Down
4 changes: 3 additions & 1 deletion library/Mockery/CountValidator/AtMost.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public function validate($n)
{
if ($this->_limit < $n) {
throw new Exception(
'Method should be called'
'Method ' . (string) $this->_expectation
. ' from ' . $this->_expectation->getMock()->mockery_getName()
. ' should be called' . PHP_EOL
. ' at most ' . $this->_limit . ' times but called ' . $n
. ' times.'
);
Expand Down
4 changes: 3 additions & 1 deletion library/Mockery/CountValidator/Exact.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public function validate($n)
{
if ($this->_limit !== $n) {
throw new Exception(
'Method should be called'
'Method ' . (string) $this->_expectation
. ' from ' . $this->_expectation->getMock()->mockery_getName()
. ' should be called' . PHP_EOL
. ' exactly ' . $this->_limit . ' times but called ' . $n
. ' times.'
);
Expand Down
5 changes: 3 additions & 2 deletions library/Mockery/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function __call(\$method, array \$args)
return \$return;
}
throw new \BadMethodCallException(
'Method ' . \$this->_mockery_name . '::' . \$method . ' does not exist on this mock object'
'Method ' . \$this->_mockery_name . '::' . \$method . '() does not exist on this mock object'
);
}
Expand Down Expand Up @@ -359,7 +359,8 @@ public function mockery_validateOrder(\$method, \$order)
{
if (\$order < \$this->_mockery_currentOrder) {
throw new \Mockery\Exception(
'Method ' . \$method . ' called out of order: expected order '
'Method ' . \$this->_mockery_name . '::' . \$method . '()'
. ' called out of order: expected order '
. \$order . ', was ' . \$this->_mockery_currentOrder
);
}
Expand Down
5 changes: 3 additions & 2 deletions library/Mockery/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function __call($method, array $args)
return $return;
}
throw new \BadMethodCallException(
'Method ' . $this->_mockery_name . '::' . $method . ' does not exist on this mock object'
'Method ' . $this->_mockery_name . '::' . $method . '() does not exist on this mock object'
);
}

Expand Down Expand Up @@ -306,7 +306,8 @@ public function mockery_validateOrder($method, $order)
{
if ($order < $this->_mockery_currentOrder) {
throw new \Mockery\Exception(
'Method ' . $method . ' called out of order: expected order '
'Method ' . $this->_mockery_name . '::' . $method . '()'
. ' called out of order: expected order '
. $order . ', was ' . $this->_mockery_currentOrder
);
}
Expand Down
26 changes: 26 additions & 0 deletions tests/Mockery/ExpectationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,32 @@ public function testAnExampleWithSomeExpectationAmendsOnCallCounts()
$this->container->mockery_verify();
}

public function testAnExampleWithSomeExpectationAmendsOnCallCounts_PHPUnitTest()
{
$service = $this->getMock('MyService2');
$service->expects($this->once())->method('login')->with('user', 'pass')->will($this->returnValue(true));
$service->expects($this->exactly(3))->method('hasBookmarksTagged')->with('php')
->will($this->onConsecutiveCalls(false, true, true));
$service->expects($this->exactly(3))->method('addBookmark')
->with($this->matchesRegularExpression('/^http:/'), $this->isType('string'))
->will($this->returnValue(true));

$this->assertTrue($service->login('user', 'pass'));
$this->assertFalse($service->hasBookmarksTagged('php'));
$this->assertTrue($service->addBookmark('http://example.com/1', 'some_tag1'));
$this->assertTrue($service->addBookmark('http://example.com/2', 'some_tag2'));
$this->assertTrue($service->addBookmark('http://example.com/3', 'some_tag3'));
$this->assertTrue($service->hasBookmarksTagged('php'));
$this->assertTrue($service->hasBookmarksTagged('php'));
}

}

class MyService2
{
public function login($user, $pass){}
public function hasBookmarksTagged($tag){}
public function addBookmark($uri, $tag){}
}

class Mockery_Duck {
Expand Down

0 comments on commit 70a3952

Please sign in to comment.