Skip to content

Instantly share code, notes, and snippets.

@ajitirto
Created June 20, 2024 01:53
Show Gist options
  • Save ajitirto/27e94d8f0c21b245c31d3df9c8598af3 to your computer and use it in GitHub Desktop.
Save ajitirto/27e94d8f0c21b245c31d3df9c8598af3 to your computer and use it in GitHub Desktop.
testing in php
at  08:49:47 ─╮
╰─❯ tree . -I "vendor|composer.lock" ─╯
.
├── composer.json
└── src
├── index.php
└── MathFunctionsTest.php
1 directory, 3 files
### index.php
<?php
function add($a, $b) {
return $a + $b;
}
function sub($a, $b) {
return $a - $b;
}
### MathFunctionsTest.php
<?php
use PHPUnit\Framework\TestCase;
class MathFunctionsTest extends TestCase {
public function testAdd() {
$this->assertEquals(3, add(1, 2));
$this->assertEquals(0, add(-1, 1));
$this->assertEquals(-2, add(-1, -1));
}
public function testSub() {
$this->assertEquals(1, sub(2, 1));
$this->assertEquals(0, sub(-1, -1));
$this->assertEquals(-2, sub(-1, 1));
}
}
## composer.json
╰─❯ cat composer.json ─╯
{
"require-dev": {
"phpunit/phpunit": "^9.5"
},
"autoload": {
"files": ["src/index.php"]
}
}
### bash
composer install
vendor/bin/phpunit src/MathFunctionsTest.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment