Add Pest PHP

This commit is contained in:
Oliver Davies 2025-08-12 19:22:23 +01:00
parent 4132f85176
commit ad6a0f4cf3
9 changed files with 3978 additions and 0 deletions

1
php/pest/.envrc Normal file
View file

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

1
php/pest/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/vendor/

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

@ -0,0 +1,15 @@
{
"require-dev": {
"pestphp/pest": "^3.8"
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
}
}

3878
php/pest/composer.lock generated Normal file

File diff suppressed because it is too large Load diff

18
php/pest/phpunit.xml Normal file
View file

@ -0,0 +1,18 @@
<?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"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>app</directory>
<directory>src</directory>
</include>
</source>
</phpunit>

View file

@ -0,0 +1,5 @@
<?php
test('example', function () {
expect(true)->toBeTrue();
});

45
php/pest/tests/Pest.php Normal file
View file

@ -0,0 +1,45 @@
<?php
/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "pest()" function to bind a different classes or traits.
|
*/
pest()->extend(Tests\TestCase::class)->in('Feature');
/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/
expect()->extend('toBeOne', function () {
return $this->toBe(1);
});
/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/
function something()
{
// ..
}

View file

@ -0,0 +1,10 @@
<?php
namespace Tests;
use PHPUnit\Framework\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
//
}

View file

@ -0,0 +1,5 @@
<?php
test('example', function () {
expect(true)->toBeTrue();
});