0Pricing
PHP Academy · Lesson

Assertions and Test Methods

Use assertEquals, assertSame, assertNull, and other assertions.

What are Assertions?

Assertions verify that the actual output of code matches the expected value. PHPUnit provides a rich library of assertion methods.

assertEquals vs assertSame

assertEquals uses loose comparison (==). assertSame uses strict comparison (===) — checks type AND value.

<?php
$this->assertEquals(0, false);      // passes (0 == false)
$this->assertSame(0, false);        // FAILS  (0 !== false)

All lessons in this course

  1. PHPUnit Setup and First Test
  2. Assertions and Test Methods
  3. Data Providers for Parameterized Tests
  4. Mocking Dependencies with PHPUnit
← Back to PHP Academy