Skip to content

Commit

Permalink
feat(testing): Custom test requirements (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDragon-ru authored Jan 20, 2024
2 parents 0d1d914 + abb2c92 commit 936a493
Show file tree
Hide file tree
Showing 23 changed files with 583 additions and 63 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,13 @@ This package provides various useful asserts for [PHPUnit](https://phpunit.de/)
[Read more](<packages/testing/README.md>).

[//]: # (end: df3ee6374fabefbdeb79b26164b3f2ef88f6ed94646bb5d44751ea6da758de19)

[include:file]: ./docs/Shared/Upgrading.md
[//]: # (start: 58c515c01daf29a92b704a09f78da2fa719462cc37e47d3abde0331a7b1da0a3)
[//]: # (warning: Generated automatically. Do not edit.)

# Upgrading

Please follow [Upgrade Guide](UPGRADE.md).

[//]: # (end: 58c515c01daf29a92b704a09f78da2fa719462cc37e47d3abde0331a7b1da0a3)
2 changes: 1 addition & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)
## Legend

| 🤝 | Backward-compatible change. Please note that despite you can ignore it now, but it will be mandatory in the future. |
|:--:|---------------------------------------------------------------------------------------------------------------------|
|:--:|:--------------------------------------------------------------------------------------------------------------------|

[//]: # (end: 39d35167e0d4cea1b3b411d449b79f0b6df5fcbf65c5d8b9775671fe5603b7c9)

Expand Down
2 changes: 1 addition & 1 deletion docs/Shared/Upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)
## Legend

| 🤝 | Backward-compatible change. Please note that despite you can ignore it now, but it will be mandatory in the future. |
|:--:|---------------------------------------------------------------------------------------------------------------------|
|:--:|:--------------------------------------------------------------------------------------------------------------------|
2 changes: 1 addition & 1 deletion packages/core/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)
## Legend

| 🤝 | Backward-compatible change. Please note that despite you can ignore it now, but it will be mandatory in the future. |
|:--:|---------------------------------------------------------------------------------------------------------------------|
|:--:|:--------------------------------------------------------------------------------------------------------------------|

[//]: # (end: c70a9a43c0a80bd2e7fa6010a9b2c0fbcab4cb4d536d7a498216d9df7431f7e2)

Expand Down
2 changes: 1 addition & 1 deletion packages/documentator/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)
## Legend

| 🤝 | Backward-compatible change. Please note that despite you can ignore it now, but it will be mandatory in the future. |
|:--:|---------------------------------------------------------------------------------------------------------------------|
|:--:|:--------------------------------------------------------------------------------------------------------------------|

[//]: # (end: c70a9a43c0a80bd2e7fa6010a9b2c0fbcab4cb4d536d7a498216d9df7431f7e2)

Expand Down
2 changes: 1 addition & 1 deletion packages/eloquent/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)
## Legend

| 🤝 | Backward-compatible change. Please note that despite you can ignore it now, but it will be mandatory in the future. |
|:--:|---------------------------------------------------------------------------------------------------------------------|
|:--:|:--------------------------------------------------------------------------------------------------------------------|

[//]: # (end: c70a9a43c0a80bd2e7fa6010a9b2c0fbcab4cb4d536d7a498216d9df7431f7e2)

Expand Down
2 changes: 1 addition & 1 deletion packages/formatter/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)
## Legend

| 🤝 | Backward-compatible change. Please note that despite you can ignore it now, but it will be mandatory in the future. |
|:--:|---------------------------------------------------------------------------------------------------------------------|
|:--:|:--------------------------------------------------------------------------------------------------------------------|

[//]: # (end: c70a9a43c0a80bd2e7fa6010a9b2c0fbcab4cb4d536d7a498216d9df7431f7e2)

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-printer/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)
## Legend

| 🤝 | Backward-compatible change. Please note that despite you can ignore it now, but it will be mandatory in the future. |
|:--:|---------------------------------------------------------------------------------------------------------------------|
|:--:|:--------------------------------------------------------------------------------------------------------------------|

[//]: # (end: c70a9a43c0a80bd2e7fa6010a9b2c0fbcab4cb4d536d7a498216d9df7431f7e2)
2 changes: 1 addition & 1 deletion packages/graphql/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)
## Legend

| 🤝 | Backward-compatible change. Please note that despite you can ignore it now, but it will be mandatory in the future. |
|:--:|---------------------------------------------------------------------------------------------------------------------|
|:--:|:--------------------------------------------------------------------------------------------------------------------|

[//]: # (end: c70a9a43c0a80bd2e7fa6010a9b2c0fbcab4cb4d536d7a498216d9df7431f7e2)

Expand Down
2 changes: 1 addition & 1 deletion packages/migrator/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)
## Legend

| 🤝 | Backward-compatible change. Please note that despite you can ignore it now, but it will be mandatory in the future. |
|:--:|---------------------------------------------------------------------------------------------------------------------|
|:--:|:--------------------------------------------------------------------------------------------------------------------|

[//]: # (end: c70a9a43c0a80bd2e7fa6010a9b2c0fbcab4cb4d536d7a498216d9df7431f7e2)

Expand Down
2 changes: 1 addition & 1 deletion packages/serializer/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)
## Legend

| 🤝 | Backward-compatible change. Please note that despite you can ignore it now, but it will be mandatory in the future. |
|:--:|---------------------------------------------------------------------------------------------------------------------|
|:--:|:--------------------------------------------------------------------------------------------------------------------|

[//]: # (end: c70a9a43c0a80bd2e7fa6010a9b2c0fbcab4cb4d536d7a498216d9df7431f7e2)

Expand Down
2 changes: 1 addition & 1 deletion packages/spa/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)
## Legend

| 🤝 | Backward-compatible change. Please note that despite you can ignore it now, but it will be mandatory in the future. |
|:--:|---------------------------------------------------------------------------------------------------------------------|
|:--:|:--------------------------------------------------------------------------------------------------------------------|

[//]: # (end: c70a9a43c0a80bd2e7fa6010a9b2c0fbcab4cb4d536d7a498216d9df7431f7e2)

Expand Down
34 changes: 34 additions & 0 deletions packages/testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This package provides various useful asserts for [PHPUnit](https://phpunit.de/)
| | `^9.0.0` | `5.0.0-beta.0 ⋯ 0.12.0` |
| | `^8.22.1` | `3.0.0 ⋯ 0.2.0` |
| | `^8.0` | `0.1.0` |
| PHPUnit | `^10.1.0` | `HEAD` |

[//]: # (end: 876a9177c0e8e3722ac84e8f3888245fc9070a64a87dedfe7c9d9ba2a13b374b)

Expand Down Expand Up @@ -635,6 +636,39 @@ class ExampleTest extends TestCase {

Enjoy 😸

# Custom Test Requirements

Unfortunately, PHPUnit doesn't allow to add/extend existing requirements and probably will not:

> I do not think that additional attributes for test requirements should be added. After all, the existing ones are only convenient syntax sugar. Simply check your custom requirements in a before-test method and call `markTestSkipped()` when they are not met.
> [©](https://github.com/sebastianbergmann/phpunit/issues/5674#issuecomment-1899839119) @sebastianbergmann
The extension listen several events and checks all attributes of test class/method which are implements [`Requirement`](./src/PhpUnit/Requirements/Requirement.php). If the requirements don't meet, the test will be marked as skipped. Please note that at least one "before" hook will be executed anyway (PHPUnit emits events after hook execution).

You need to [register extension](https://docs.phpunit.de/en/main/extending-phpunit.html#registering-an-extension-from-a-composer-package) first:

```xml
<extensions>
<bootstrap class="LastDragon_ru\LaraASP\Testing\PhpUnit\Requirements\Extension"/>
</extensions>
```

And then

```php
<?php declare(strict_types = 1);

use LastDragon_ru\LaraASP\Testing\Requirements\RequiresComposerPackage;
use PHPUnit\Framework\TestCase;

class SomePackageTest extends TestCase {
#[RequiresComposerPackage('some/package')]
public function testSomePackage(): void {
// .....
}
}
```

[include:file]: ../../docs/Shared/Upgrading.md
[//]: # (start: e9139abedb89f69284102c9112b548fd7add07cf196259916ea4f1c98977223b)
[//]: # (warning: Generated automatically. Do not edit.)
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)
## Legend

| 🤝 | Backward-compatible change. Please note that despite you can ignore it now, but it will be mandatory in the future. |
|:--:|---------------------------------------------------------------------------------------------------------------------|
|:--:|:--------------------------------------------------------------------------------------------------------------------|

[//]: # (end: c70a9a43c0a80bd2e7fa6010a9b2c0fbcab4cb4d536d7a498216d9df7431f7e2)

Expand Down
1 change: 1 addition & 0 deletions packages/testing/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"ext-dom": "*",
"ext-xmlreader": "*",
"ext-mbstring": "*",
"composer/semver": "^3.2",
"doctrine/dbal": "^3.1.4",
"doctrine/sql-formatter": "^1.1",
"http-interop/http-factory-guzzle": "^1.0.0",
Expand Down
Loading

0 comments on commit 936a493

Please sign in to comment.