Snippets > PHPUnit


#command-line#composer#php

  • CLI to working directory
  • Install PHPUnit:
    composer require --dev phpunit/phpunit
  • Create a "tests" directory in the project root
  • Create test class "EqualsTest.php":
  • use PHPUnit\Framework\TestCase;
    
    class EqualsTest extends TestCase
    {
    	public function testEquals()
    	{
    		$this->assertEquals('string1', 'string1');
    	}
    }
  • Run all tests in the "tests" directory:
    vendor\bin\phpunit tests
    Result:
    PHPUnit 9.6.16 by Sebastian Bergmann and contributors.
    
    .                                                                   1 / 1 (100%)
    
    Time: 00:00.011, Memory: 4.00 MB
    
    OK (1 test, 1 assertion)