Add PHPUnit example

This commit is contained in:
Oliver Davies 2025-09-23 22:32:20 +01:00
parent a98d4ff909
commit a47b07c5f0
7 changed files with 1766 additions and 0 deletions

1
php/phpunit/.envrc Normal file
View file

@ -0,0 +1 @@
use flake "git+https://code.oliverdavies.uk/opdavies/dev-shells#php84"

2
php/phpunit/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/.phpunit.cache
/vendor/

15
php/phpunit/composer.json Normal file
View file

@ -0,0 +1,15 @@
{
"require-dev": {
"phpunit/phpunit": "^12.3"
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
}
}

1693
php/phpunit/composer.lock generated Normal file

File diff suppressed because it is too large Load diff

24
php/phpunit/phpunit.xml Normal file
View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
displayDetailsOnPhpunitDeprecations="true"
failOnPhpunitDeprecation="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>

View file

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace App;
final class Calculator
{
public function add(int $a, int $b): int
{
return $a + $b;
}
}

View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Tests;
use App\Calculator;
use PHPUnit\Framework\TestCase;
class CalculatorTest extends TestCase
{
public function test_add(): void
{
$calculator = new Calculator();
$this->assertSame(3, $calculator->add(1, 2));
}
}