|
| 1 | +<p align="center"> |
| 2 | + <a href="#get-started"><img alt="TESTO" |
| 3 | + src="https://github.com/php-testo/.github/blob/1.x/resources/logo-full.svg?raw=true" |
| 4 | + style="width: 2in; display: block" |
| 5 | + /></a> |
| 6 | +</p> |
| 7 | + |
| 8 | +<p align="center">The PHP Testing Framework You Control</p> |
| 9 | + |
| 10 | +<div align="center"> |
| 11 | + |
| 12 | +[](https://boosty.to/roxblnfk) |
| 13 | +[](https://patreon.com/roxblnfk) |
| 14 | + |
| 15 | +</div> |
| 16 | + |
| 17 | +Testo (pronounced [test-oh], meaning "dough" in East and South Slavic languages) — is an extensible testing framework for PHP. Built for scenarios requiring complete customization of the testing process: SDKs, framework tools, complex integrations. |
| 18 | + |
| 19 | +Unlike other testing frameworks, Testo provides all at once: familiar and convenient PHP syntax, unprecedented extensibility and customizability, and a simple yet powerful architecture based on a minimal core and middleware system. |
| 20 | + |
| 21 | +Like dough, you can mold and shape it into any testing infrastructure you need. |
| 22 | + |
| 23 | +We believe developers should have full control over their testing environment, and Testo delivers exactly that. |
| 24 | + |
| 25 | + |
| 26 | +<br /> |
| 27 | + |
| 28 | +Testo is an extensible testing framework built on a lightweight core with a middleware system. |
| 29 | +It gives you full control over your testing environment while keeping the familiar PHP syntax you already know. |
| 30 | + |
| 31 | + |
| 32 | +## Get Started |
| 33 | + |
| 34 | +### Installation |
| 35 | + |
| 36 | +```bash |
| 37 | +composer require --dev testo/testo * |
| 38 | +``` |
| 39 | + |
| 40 | +[](https://packagist.org/packages/testo/testo) |
| 41 | +[](https://packagist.org/packages/testo/testo) |
| 42 | +[](LICENSE.md) |
| 43 | +[](https://packagist.org/packages/testo/testo/stats) |
| 44 | + |
| 45 | +### Configuration |
| 46 | + |
| 47 | +By default, if no configuration file is provided, Testo will run tests from the `tests` folder. |
| 48 | + |
| 49 | +To customize the configuration, create a `testo.php` file in the root of your project: |
| 50 | + |
| 51 | +```php |
| 52 | +<?php |
| 53 | + |
| 54 | +declare(strict_types=1); |
| 55 | + |
| 56 | +use Testo\Config\ApplicationConfig; |
| 57 | +use Testo\Config\SuiteConfig; |
| 58 | +use Testo\Config\FinderConfig; |
| 59 | + |
| 60 | +return new ApplicationConfig( |
| 61 | + suites: [ |
| 62 | + new SuiteConfig( |
| 63 | + name: 'Unit', |
| 64 | + location: new FinderConfig( |
| 65 | + include: ['tests/Unit'], |
| 66 | + ), |
| 67 | + ), |
| 68 | + ], |
| 69 | +); |
| 70 | +``` |
| 71 | + |
| 72 | +### Running Tests |
| 73 | + |
| 74 | +To run your tests, execute: |
| 75 | + |
| 76 | +```bash |
| 77 | +vendor/bin/testo |
| 78 | +``` |
| 79 | + |
| 80 | +### Writing Your First Test |
| 81 | + |
| 82 | +Create a test class in the configured test directory (e.g., `tests/CalculatorTest.php`): |
| 83 | + |
| 84 | +```php |
| 85 | +<?php |
| 86 | + |
| 87 | +declare(strict_types=1); |
| 88 | + |
| 89 | +namespace Tests; |
| 90 | + |
| 91 | +use Testo\Assert; |
| 92 | +use Testo\Attribute\Test; |
| 93 | +use Testo\Attribute\RetryPolicy; |
| 94 | +use Testo\Attribute\ExpectException; |
| 95 | + |
| 96 | +final class CalculatorTest |
| 97 | +{ |
| 98 | + #[Test] |
| 99 | + public function dividesNumbers(): void |
| 100 | + { |
| 101 | + $result = 10 / 2; |
| 102 | + |
| 103 | + Assert::same(5.0, $result); |
| 104 | + Assert::notSame(5, $result); // Types matter! |
| 105 | + } |
| 106 | + |
| 107 | + #[Test] |
| 108 | + #[RetryPolicy(maxAttempts: 3)] |
| 109 | + public function flakyApiCall(): void |
| 110 | + { |
| 111 | + // Retries up to 3 times if test fails |
| 112 | + $response = $this->makeExternalApiCall(); |
| 113 | + |
| 114 | + Assert::same(200, $response->status); |
| 115 | + } |
| 116 | + |
| 117 | + #[Test] |
| 118 | + #[ExpectException(\RuntimeException::class)] |
| 119 | + public function throwsException(): void |
| 120 | + { |
| 121 | + throw new \RuntimeException('Expected error'); |
| 122 | + } |
| 123 | +} |
| 124 | +``` |
| 125 | + |
| 126 | +What to note: |
| 127 | +- Use the `#[Test]` attribute to mark test methods |
| 128 | +- Test classes don't need to extend any base class |
| 129 | +- Use `Assert` class for assertions (`same`, `true`, `false`, `null`, `contains`, `instanceOf`, etc.) |
| 130 | +- Testo provides multiple attributes to extend testing capabilities (retry policies, exception handling, and more) |
| 131 | + |
| 132 | +## IDE Support |
| 133 | + |
| 134 | +Testo comes with the [IDEA plugin `Testo`](https://plugins.jetbrains.com/plugin/28842-testo?noRedirect=true). |
| 135 | + |
| 136 | +[](https://plugins.jetbrains.com/plugin/28842-testo/versions) |
| 137 | +[](https://plugins.jetbrains.com/plugin/28842-testo/reviews) |
| 138 | +[](https://plugins.jetbrains.com/plugin/28842-testo) |
0 commit comments