Skip to content

Instantly share code, notes, and snippets.

@lstrojny
Created March 25, 2021 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lstrojny/78582e82eb6ba950241a89922fe4e6ef to your computer and use it in GitHub Desktop.
Save lstrojny/78582e82eb6ba950241a89922fe4e6ef to your computer and use it in GitHub Desktop.
<?php
namespace Test;
use PHPUnit\Framework\TestCase;
interface SystemUnderTest {
public function first(int $arg): int;
public function second(string $arg): string;
}
final class CallOrderTest extends TestCase
{
private $sut;
protected function setUp(): void
{
parent::setUp();
$this->sut = $this->createMock(SystemUnderTest::class);
$this->sut
->expects(self::once())
->method('first')
->id('first')
->with(1)
->willReturn(2);
$this->sut
->expects(self::once())
->after('first')
->method('second')
->with('foo')
->willReturn('bar');
}
public function testCorrectOrder(): void
{
self::assertSame(2, $this->sut->first(1));
self::assertSame('bar', $this->sut->second('foo'));
}
public function testWrongOrder(): void
{
self::assertSame('bar', $this->sut->second('foo'));
self::assertSame(2, $this->sut->first(1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment