Skip to content

Commit

Permalink
Add method doNotReceiveAnyMessage to mock asserter.
Browse files Browse the repository at this point in the history
  • Loading branch information
mageekguy committed Sep 29, 2020
1 parent c577d87 commit 9581490
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions classes/asserters/adapter/call.php
Expand Up @@ -38,6 +38,7 @@ public function __get($property)
case 'atleastonce':
case 'wascalled':
case 'wasnotcalled':
case 'notreceiveanymessage':
return $this->{$property}();

default:
Expand Down
5 changes: 5 additions & 0 deletions classes/asserters/mock.php
Expand Up @@ -25,6 +25,11 @@ public function receive($function)
return $this->call($function);
}

public function notReceiveAnyMessage($failMessage = null)
{
return $this->wasNotCalled($failMessage ?: $this->_('%s receive some messages', $this->adapterIsSet()->adapter->getMockClass()));
}

public function wasCalled($failMessage = null)
{
if ($this->adapterIsSet()->adapter->getCallsNumber() > 0) {
Expand Down
46 changes: 46 additions & 0 deletions tests/units/classes/asserters/mock.php
Expand Up @@ -265,6 +265,52 @@ public function testReceive()
;
}

public function testNotReceiveAnyMessage()
{
$this
->if($asserter = $this->newTestedInstance)
->then
->exception(function () use ($asserter) {
$asserter->notReceiveAnyMessage();
})
->isInstanceOf(atoum\exceptions\logic::class)
->hasMessage('Mock is undefined')
->if(
$asserter
->setWith($mock = new \mock\foo($controller = new \mock\atoum\mock\controller()))
->setLocale($locale = new \mock\atoum\locale()),
$this->calling($locale)->_ = $wasCalled = uniqid(),
$this->calling($controller)->getCallsNumber = rand(1, PHP_INT_MAX),
$this->calling($controller)->getMockClass = $mockClass = uniqid()
)
->then
->exception(function () use ($asserter) {
$asserter->notReceiveAnyMessage();
})
->isInstanceOf(atoum\asserter\exception::class)
->hasMessage($wasCalled)
->mock($locale)->call('_')->withArguments('%s receive some messages', $mockClass)->once

->exception(function () use ($asserter) {
$asserter->notReceiveAnyMessage();
})
->hasMessage($wasCalled)
->isInstanceOf(atoum\asserter\exception::class)
->mock($locale)->call('_')->withArguments('%s receive some messages', $mockClass)->twice

->exception(function () use ($asserter, & $failMessage) {
$asserter->notReceiveAnyMessage($failMessage = uniqid());
})
->isInstanceOf(atoum\asserter\exception::class)
->hasMessage($failMessage)

->if($this->calling($controller)->getCallsNumber = 0)
->then
->object($asserter->notReceiveAnyMessage())->isIdenticalTo($asserter)
->object($asserter->notReceiveAnyMessage)->isIdenticalTo($asserter)
;
}

public function testWithArguments()
{
$this
Expand Down

0 comments on commit 9581490

Please sign in to comment.