Skip to content

Instantly share code, notes, and snippets.

@guiled
Created August 16, 2012 09:34
Show Gist options
  • Save guiled/3368798 to your computer and use it in GitHub Desktop.
Save guiled/3368798 to your computer and use it in GitHub Desktop.
Atoum, test if a mocked method is called only once
$this->assert
->if($mock = new \mock\MyClassToMock())
->if($test = myTestedClass($mock))
->and($myCounter = 0)
->and($mock->getMockController()->mockedMethod = function () use(&$myCounter) {doWhatever();$myCounter++;})
->and($test->myMethodThatUsesMockedMethod())
->number($myCounter)
->isEqualTo(1);
@jubianchi
Copy link

<?php
$this
    ->if($mock = new \mock\MyClassToMock())
    ->if($test = myTestedClass($mock))
    ->and($mock->getMockController()->mockedMethod = function () use() { doWhatever(); })
    ->then
        ->mock($mock)
            ->call('mockedMethod')->once()

@jubianchi
Copy link

<?php
//...
    ->then
        ->mock($mock)
            ->call('mockedMethod')->once()
            ->call('mockedMethod')->exactly(2)
            ->call('mockedMethod')->withArguments('foo', 'bar')->once()
            //...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment