A test case extends PHPUnit 79,198 \Framework\TestCase in a file ending in Test.php. Each public method named test... or marked #[Test] is one test, run on a fresh instance of the class.
<?php
use PHPUnit\Framework\Attributes\{CoversClass, Test};
use PHPUnit\Framework\TestCase;
use Shop\Money;
#[CoversClass(Money::class)]
final class MoneyTest extends TestCase {
#[Test]
public function adding_returns_a_new_money(): void {
$price = new Money(1999);
$sum = $price->plus(new Money(500));
$this->assertSame(2499, $sum->cents);
$this->assertSame(1999, $price->cents); // the original is unchanged
}
public function testFormatPadsTheCents(): void {
$this->assertSame('USD 5.07', new Money(507)->format());
}
}Output
PHPUnit 13.3.4 by Sebastian Bergmann and contributors. ... .. 2 / 2 (100%) ... OK (2 tests, 3 assertions)
Each dot is a pass (F failure, E error, D deprecation); the exit code is 0 only when all passed. Metadata is written as attributes: PHPUnit 10 (February 2023) introduced them, 11 deprecated doc-comment annotations (@test, @dataProvider, @covers), and 12 removed them, so an old /** @test */ method is now silently skipped.