<?php
use PHPUnit\Framework\TestCase;
class FixedOrderTest extends TestCase
{
public function testDoWork() : void
{
$manufacturer = new ToyManufacturer();
$toyProcess = $this->createMock(ToyProcess::CLASS);
$toyProcess->expects($this->at(0))
->method('buildToy')
->willReturn('ElePHPant');
$toyProcess->expects($this->at(1))
->method('paintToy')
->willReturn('BlueElePHPant');
$toyProcess->expects($this->at(2))
->method('wrapToy')
->willReturn('WrappedBlueElePHPant');
$qualityCheck = $this->createMock(ToyQualityControl::CLASS);
$qualityCheck->expects($this->atLeastOnce())
->method('isOkay')
->willReturn(true);
$present = $manufacturer->doWork($toyProcess, $qualityCheck);
$this->assertEquals('WrappedBlueElePHPant', $present);
}
}
class ToyManufacturer
{
public function doWork(ToyProcess $toyProcess, ToyQualityControl $qualityCheck)
{
$toy = $toyProcess->buildToy();
$coloredToy = $toyProcess->paintToy($toy);
if (!$qualityCheck->isOkay($coloredToy)) {
throw new Exception('Bad quality Toy');
}
return $toyProcess->wrapToy($coloredToy);
}
}
interface ToyProcess
{
public function buildToy();
public function paintToy($toy);
public function wrapToy($toy);
}
interface ToyQualityControl
{
public function isOkay($toy);
}
Result
Time: 00:00.019, Memory: 18.00 MB
There was 1 warning:
1) FixedOrderTest::testDoWork
The at() matcher has been deprecated. It will be removed in PHPUnit 10. Please refactor your test to not rely on the order in which methods are invoked.
PhpunitExec.php:21
WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.