record('lit/a', 'page', '5', 'eins', 811)); self::assertSame(42, $log->record('lit/a', 'page', '6', 'zwei')); $log->assertRecorded( ['object_id' => '5', 'summary' => 'eins', 'revision_id' => 811, 'result' => 'ok'], ['object_id' => '6', 'revision_id' => null] ); self::assertSame(['eins', 'zwei'], $log->summaries()); } public function testAFailureIsThrownAfterTheCallIsNoted(): void { $log = new FakeChangeLog(1, new RuntimeException('db weg')); try { $log->record('lit/a', 'page', '5', 'x'); self::fail('RuntimeException expected'); } catch (RuntimeException $e) { self::assertSame('db weg', $e->getMessage()); } $log->assertRecorded(['ability' => 'lit/a']); } public function testAssertRecordedChecksTheNumberOfCalls(): void { $log = new FakeChangeLog(); $log->record('lit/a', 'page', '5', 'x'); $this->expectException(AssertionFailedError::class); $log->assertRecorded([], []); } public function testAssertPartialsChecksTheNamedArguments(): void { $log = FakeChangeLog::partialsOnly(); $log->recordPartial('lit/a', 'page', '5', 'teilweise', 811); $log->assertPartials(['ability' => 'lit/a', 'revision_id' => 811]); $this->expectException(AssertionFailedError::class); $log->assertPartials(['object_id' => '6']); } public function testACallTheFakeDoesNotAllowThrowsAndFailsTheTestEvenWhenSwallowed(): void { $log = FakeChangeLog::forbidden(); try { $log->record('lit/a', 'page', '5', 'x'); self::fail('LogicException expected'); } catch (LogicException $e) { self::assertStringContainsString('record(lit/a, page, 5)', $e->getMessage()); } try { FakeChangeLog::verify(); self::fail('verify() must fail'); } catch (AssertionFailedError $e) { self::assertStringContainsString('Unexpected change log calls', $e->getMessage()); } FakeChangeLog::verify(); } public function testRecordOnlyFakesRefusePartialsAndPartialsOnlyFakesRefuseRecords(): void { foreach ([[new FakeChangeLog(), 'recordPartial'], [FakeChangeLog::partialsOnly(), 'record']] as [$log, $method]) { try { $log->$method('lit/a', 'page', '5', 'x'); self::fail($method . ' must be refused'); } catch (LogicException $e) { self::assertStringContainsString($method, $e->getMessage()); } } $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Unexpected change log calls: recordPartial(lit/a, page, 5); record(lit/a, page, 5)'); FakeChangeLog::verify(); } public function testAnyAllowsBoth(): void { $log = FakeChangeLog::any(9); self::assertSame(9, $log->record('lit/a', 'page', '5', 'x')); $log->recordPartial('lit/a', 'page', '5', 'y'); $log->assertPartials(['summary' => 'y']); } }