Performance: Unit tests
Unit tests affect development speed and feedback loop but do not directly impact page load or rendering performance.
Jump into concepts and practice - no test required
<?php
public function testUserCreation() {
$user = User::factory()->make(['name' => 'Test']);
$this->assertEquals('Test', $user->name);
}
<?php
public function testUserCreation() {
$user = User::create(['name' => 'Test']);
$this->assertDatabaseHas('users', ['name' => 'Test']);
sleep(5); // artificial delay
}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Unit tests with database I/O and delays | 0 | 0 | 0 | [X] Bad |
| Unit tests using in-memory model factories | 0 | 0 | 0 | [OK] Good |
public function testSum() {
$a = 2;
$b = 3;
$this->assertEquals(5, $a + $b);
}public function testUserName() {
$user = new User();
$user->name = 'Alice';
$this->assertEquals('Alice', $user->username);
}