mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Compare commits
140 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 15edde8e87 | |||
| 211f5c2433 | |||
| 5d58d58f71 | |||
| d5a4008d3e | |||
| 1bf802268f | |||
| 807a4b004f | |||
| f7a3fa15f4 | |||
| 6dd3ca20e4 | |||
| d9ea378819 | |||
| 6aa0356570 | |||
| 45b0d5d899 | |||
| 5be1edd7b7 | |||
| 75f7ee0acf | |||
| d0a74931dd | |||
| 0738e113ad | |||
| 283d8f3e03 | |||
| 1c3e820283 | |||
| accd4eb7b4 | |||
| ae7991c7e9 | |||
| e9e72d607e | |||
| 40766f9275 | |||
| a3fd60ce4d | |||
| f9a3e39902 | |||
| 06d707fb41 | |||
| a70c64d704 | |||
| 3a78aaef8f | |||
| c79c0feec8 | |||
| 39a5a94f3e | |||
| 961bfcaff7 | |||
| 52ba5dbd00 | |||
| 518b056fb9 | |||
| f9a936b4d9 | |||
| 4448761852 | |||
| 1192d13e6b | |||
| 57b982de48 | |||
| a3366379e0 | |||
| cd8d8fce61 | |||
| 4254d71039 | |||
| bd48232c61 | |||
| 70b3c7ea1d | |||
| c186035a13 | |||
| 2efed3ef80 | |||
| 58f2581307 | |||
| 6c4fd61db5 | |||
| afbbc35984 | |||
| a13c19cc29 | |||
| 7d7c5f1ab1 | |||
| 865f33bf80 | |||
| e33419545c | |||
| b93cd724c1 | |||
| 40a5d067ec | |||
| 3640ab0945 | |||
| cb2336d220 | |||
| 71fcb281b0 | |||
| d24830121e | |||
| 5a00a732e3 | |||
| 38584bec93 | |||
| ffa3f1d683 | |||
| dff9bbc134 | |||
| f5f717f1ad | |||
| 9bdd254007 | |||
| 6e18912ea6 | |||
| d35320c697 | |||
| fe11140fc2 | |||
| 0d198f589d | |||
| 8a42d40506 | |||
| 83797431fb | |||
| c05df43217 | |||
| f6859eeb3b | |||
| a0b8082631 | |||
| 926d8ecb8d | |||
| 24f85354e2 | |||
| 163de28338 | |||
| 3d2c83a501 | |||
| b0c964d4d9 | |||
| 20d2d9f3b7 | |||
| 6b7aa10e91 | |||
| 067aa58817 | |||
| 337e751200 | |||
| b20f208b55 | |||
| 9899b3c3a4 | |||
| 6437db7aa0 | |||
| 7d38d4bd4f | |||
| e8d426f574 | |||
| bb711108a2 | |||
| a482341b99 | |||
| f5ce472006 | |||
| a53ff3e459 | |||
| e15d77f3f6 | |||
| 504128730c | |||
| 098acaecc0 | |||
| b2dd573a67 | |||
| 84c9078bb7 | |||
| aa1917c28d | |||
| c81dce0f6d | |||
| 249869c2db | |||
| d59d8d6245 | |||
| b0680b7e2c | |||
| c7fd21999b | |||
| 28d06663d3 | |||
| 73f56e58a5 | |||
| 76796ffc67 | |||
| 01daf0316c | |||
| 1f2976c0e0 | |||
| 2e7ed741b6 | |||
| a0a4730ef8 | |||
| 5ed927d226 | |||
| 78cdd4da36 | |||
| 332139e614 | |||
| b093e8ee29 | |||
| 937374431a | |||
| ddc08cf0f9 | |||
| 88d2391d2e | |||
| bd02196950 | |||
| 4de6019206 | |||
| 85630b0aa2 | |||
| 0fda39467c | |||
| 415f571910 | |||
| 8284219035 | |||
| d0d34c7872 | |||
| 2869f11ae5 | |||
| 340c7ca04e | |||
| 81a646d64e | |||
| c23f2e4bd6 | |||
| 4496e9d9ee | |||
| ce14ffd49a | |||
| c18c481628 | |||
| 0695ea5d33 | |||
| 2e321f5465 | |||
| cbeec31bfc | |||
| 69f6a22121 | |||
| 9a179d2891 | |||
| 6c4be0190e | |||
| 5c6bb43d8d | |||
| e536c28e34 | |||
| 67bb23cda3 | |||
| 59398cfcf8 | |||
| 182377abe3 | |||
| 242e74964b | |||
| 9a2c7e45f7 |
52
.github/workflows/changelog.yml
vendored
Normal file
52
.github/workflows/changelog.yml
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
name: Changelog
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
paths:
|
||||
- CHANGELOG.md
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
paths:
|
||||
- CHANGELOG.md
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Checkout website repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
token: ${{ secrets.CHANGELOG_KEY }}
|
||||
repository: pestphp/website
|
||||
path: pestphp-website
|
||||
- name: Read CHANGELOG.md
|
||||
id: package
|
||||
uses: juliangruber/read-file-action@v1
|
||||
with:
|
||||
path: ./CHANGELOG.md
|
||||
- name: Add file headers
|
||||
uses: DamianReeves/write-file-action@v1.0
|
||||
with:
|
||||
path: ./CHANGELOG.md
|
||||
contents: |
|
||||
---
|
||||
title: Changelog
|
||||
description: Changelog
|
||||
extends: _layouts.documentation
|
||||
section: content
|
||||
---
|
||||
${{ steps.package.outputs.content }}
|
||||
write-mode: overwrite
|
||||
- name: Copy CHANGELOG to website repository
|
||||
run: cp CHANGELOG.md pestphp-website/source/docs/changelog.md
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v2
|
||||
with:
|
||||
token: ${{ secrets.CHANGELOG_KEY }}
|
||||
commit-message: Update changelog.md
|
||||
committer: GitHub Action <noreply@github.com>
|
||||
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
|
||||
title: 'Update changelog.md'
|
||||
path: ./pestphp-website
|
||||
@ -1,18 +1,19 @@
|
||||
name: Continuous Integration
|
||||
name: Formats
|
||||
|
||||
on: ['push', 'pull_request']
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
php: [7.3, 7.4]
|
||||
os: [ubuntu-latest]
|
||||
php: [7.4]
|
||||
dependency-version: [prefer-lowest, prefer-stable]
|
||||
|
||||
name: CI - PHP ${{ matrix.php }} (${{ matrix.dependency-version }})
|
||||
name: Formats P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
|
||||
|
||||
steps:
|
||||
|
||||
@ -29,7 +30,7 @@ jobs:
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
extensions: mbstring, zip
|
||||
extensions: dom, mbstring, zip
|
||||
tools: prestissimo
|
||||
coverage: pcov
|
||||
|
||||
@ -43,9 +44,3 @@ jobs:
|
||||
|
||||
- name: Type Checks
|
||||
run: vendor/bin/phpstan analyse --ansi
|
||||
|
||||
- name: Unit Tests
|
||||
run: bin/pest --colors=always --exclude-group=integration
|
||||
|
||||
- name: Integration Tests
|
||||
run: bin/pest --colors=always --group=integration
|
||||
48
.github/workflows/tests.yml
vendored
Normal file
48
.github/workflows/tests.yml
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
name: Tests
|
||||
|
||||
on: ['push', 'pull_request']
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
php: [7.3, 7.4]
|
||||
dependency-version: [prefer-lowest, prefer-stable]
|
||||
|
||||
name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
|
||||
|
||||
steps:
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.composer/cache/files
|
||||
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
extensions: dom, mbstring, zip
|
||||
coverage: none
|
||||
|
||||
- name: Install Composer dependencies
|
||||
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist
|
||||
|
||||
- name: Unit Tests
|
||||
run: php bin/pest --colors=always --exclude-group=integration
|
||||
|
||||
- name: Integration Tests
|
||||
run: php bin/pest --colors=always --group=integration
|
||||
|
||||
- name: Setup problem matchers for PHP
|
||||
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
|
||||
|
||||
- name: Setup problem matchers for Pest
|
||||
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ coverage.xml
|
||||
.temp/coverage.php
|
||||
*.swp
|
||||
*.swo
|
||||
.vscode/
|
||||
47
CHANGELOG.md
47
CHANGELOG.md
@ -6,6 +6,53 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [v0.2.2 (2020-06-21)](https://github.com/pestphp/pest/compare/v0.2.1...v0.2.2)
|
||||
### Added
|
||||
- `depends` phpunit feature ([#103](https://github.com/pestphp/pest/pull/103))
|
||||
|
||||
### Fixes
|
||||
- datasets name conflit ([#101](https://github.com/pestphp/pest/pull/101))
|
||||
|
||||
## [v0.2.1 (2020-06-17)](https://github.com/pestphp/pest/compare/v0.2.0...v0.2.1)
|
||||
### Fixes
|
||||
- Multiple `uses` in the same path override previous `uses` ([#97](https://github.com/pestphp/pest/pull/97))
|
||||
|
||||
## [v0.2.0 (2020-06-14)](https://github.com/pestphp/pest/compare/v0.1.5...v0.2.0)
|
||||
### Adds
|
||||
- `--init` option to install Pest on a new blank project ([70b3c7e](https://github.com/pestphp/pest/commit/70b3c7ea1ddb031f3bbfaabdc28d56270608ebbd))
|
||||
- pending higher orders tests aka tests without description ([aa1917c](https://github.com/pestphp/pest/commit/aa1917c28d9b69c2bd1d51f986c4f61318ee7e16))
|
||||
|
||||
### Fixed
|
||||
- `--verbose` and `--colors` options not being used by printers ([#51](https://github.com/pestphp/pest/pull/51))
|
||||
- missing support on windows ([#61](https://github.com/pestphp/pest/pull/61))
|
||||
|
||||
### Changed
|
||||
- `helpers.php` stub provides now namespaced functions
|
||||
- functions provided by plugins are now namespaced functions:
|
||||
|
||||
```php
|
||||
use function Pest\Faker\faker;
|
||||
|
||||
it('foo', function () {
|
||||
$name = faker()->name;
|
||||
});
|
||||
```
|
||||
|
||||
## [v0.1.5 (2020-05-24)](https://github.com/pestphp/pest/compare/v0.1.4...v0.1.5)
|
||||
### Fixed
|
||||
- Missing default decorated output on coverage ([88d2391](https://github.com/pestphp/pest/commit/88d2391d2e6fe9c9416462734b9b523cb418f469))
|
||||
|
||||
## [v0.1.4 (2020-05-24)](https://github.com/pestphp/pest/compare/v0.1.3...v0.1.4)
|
||||
### Added
|
||||
- Support to Lumen on artisan commands ([#18](https://github.com/pestphp/pest/pull/18))
|
||||
|
||||
### Fixed
|
||||
- Mockery tests without assertions being considered risky ([415f571](https://github.com/pestphp/pest/commit/415f5719101b30c11d87f74810a71686ef2786c6))
|
||||
|
||||
## [v0.1.3 (2020-05-21)](https://github.com/pestphp/pest/compare/v0.1.2...v0.1.3)
|
||||
### Added
|
||||
- `Plugin::uses()` method for making traits globally available ([6c4be01](https://github.com/pestphp/pest/commit/6c4be0190e9493702a976b996bbbf5150cc6bb53))
|
||||
|
||||
## [v0.1.2 (2020-05-15)](https://github.com/pestphp/pest/compare/v0.1.1...v0.1.2)
|
||||
### Added
|
||||
- Support to custom helpers ([#7](https://github.com/pestphp/pest/pull/7))
|
||||
|
||||
17
README.md
17
README.md
@ -1,17 +1,18 @@
|
||||
<p align="center">
|
||||
<img src="https://next.pestphp.com/assets/img/og.png" width="600" alt="PEST Preview">
|
||||
<img src="https://raw.githubusercontent.com/pestphp/art/master/readme.png" width="600" alt="PEST">
|
||||
<p align="center">
|
||||
<a href="https://github.com/pestphp/pest/actions"><img src="https://github.com/pest/pestphp/workflows/tests/badge.svg" alt="Build Status"></a>
|
||||
<a href="https://packagist.org/packages/pestphp/pest"><img src="https://poser.pugx.org/pestphp/pest/d/total.svg" alt="Total Downloads"></a>
|
||||
<a href="https://packagist.org/packages/pestphp/pest"><img src="https://poser.pugx.org/pestphp/pest/v/stable.svg" alt="Latest Version"></a>
|
||||
<a href="https://packagist.org/packages/pestphp/pest"><img src="https://poser.pugx.org/pestphp/pest/license.svg" alt="License"></a>
|
||||
<a href="https://github.com/pestphp/pest/actions"><img alt="GitHub Workflow Status (master)" src="https://img.shields.io/github/workflow/status/pestphp/pest/Continuous Integration/master"></a>
|
||||
<a href="https://packagist.org/packages/pestphp/pest"><img alt="Total Downloads" src="https://img.shields.io/packagist/dt/pestphp/pest"></a>
|
||||
<a href="https://packagist.org/packages/pestphp/pest"><img alt="Latest Version" src="https://img.shields.io/packagist/v/pestphp/pest"></a>
|
||||
<a href="https://packagist.org/packages/pestphp/pest"><img alt="License" src="https://img.shields.io/packagist/l/pestphp/pest"></a>
|
||||
</p>
|
||||
</p>
|
||||
|
||||
------
|
||||
**Pest** it's an elegant PHP Testing Framework with a focus on simplicity. It was carefully crafted to bring the joy of testing to PHP.
|
||||
**Pest** is an elegant PHP Testing Framework with a focus on simplicity. It was carefully crafted to bring the joy of testing to PHP.
|
||||
|
||||
- Explore the docs: **[pestphp.com »](https://pestphp.com)**
|
||||
- Join the Discord Server: **[discord.gg/4UMHUb5 »](https://discord.gg/4UMHUb5)**
|
||||
- Follow us on Twitter: **[@pestphp »](https://twitter.com/pestphp)**
|
||||
- Join us on the Discord Server: **[discord.gg/bMAJv82 »](https://discord.gg/bMAJv82)**
|
||||
|
||||
Pest was created by **[Nuno Maduro](https://twitter.com/enunomaduro)** and is open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.
|
||||
Pest was created by **[Nuno Maduro](https://twitter.com/enunomaduro)** under the **[Sponsorware license](https://github.com/sponsorware/docs)**. It got open-sourced and is now licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.
|
||||
|
||||
18
bin/pest
18
bin/pest
@ -1,31 +1,39 @@
|
||||
#!/usr/bin/env php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use NunoMaduro\Collision\Provider;
|
||||
use Pest\Actions\ValidatesEnvironment;
|
||||
use Pest\Console\Command;
|
||||
use Pest\Support\Container;
|
||||
use Pest\TestSuite;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
(static function () {
|
||||
// Used when Pest is required using composer.
|
||||
$vendorPath = realpath(__DIR__ . '/../../../../vendor/autoload.php');
|
||||
$vendorPath = dirname(__DIR__, 4) . '/vendor/autoload.php';
|
||||
|
||||
// Used when Pest maintainers are running Pest tests.
|
||||
$localPath = realpath(__DIR__ . '/../vendor/autoload.php');
|
||||
$localPath = dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
if ($vendorPath) {
|
||||
if (file_exists($vendorPath)) {
|
||||
include_once $vendorPath;
|
||||
} else {
|
||||
include_once $localPath;
|
||||
}
|
||||
|
||||
(new \NunoMaduro\Collision\Provider)->register();
|
||||
(new Provider())->register();
|
||||
|
||||
$rootPath = getcwd();
|
||||
|
||||
$testSuite = TestSuite::getInstance($rootPath);
|
||||
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, true);
|
||||
|
||||
$container = Container::getInstance();
|
||||
$container->add(TestSuite::class, $testSuite);
|
||||
$container->add(OutputInterface::class, $output);
|
||||
|
||||
ValidatesEnvironment::in($testSuite);
|
||||
|
||||
exit((new Command($testSuite, new ConsoleOutput()))->run($_SERVER['argv']));
|
||||
exit($container->get(Command::class)->run($_SERVER['argv']));
|
||||
})();
|
||||
|
||||
@ -18,7 +18,10 @@
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.3",
|
||||
"nunomaduro/collision": "^5.0",
|
||||
"nunomaduro/collision": "^5.0.0-BETA2",
|
||||
"pestphp/pest-plugin": "^0.2",
|
||||
"pestphp/pest-plugin-coverage": "^0.2",
|
||||
"pestphp/pest-plugin-init": "^0.2",
|
||||
"phpunit/phpunit": "^9.1.4",
|
||||
"sebastian/environment": "^5.1"
|
||||
},
|
||||
@ -34,18 +37,21 @@
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/PHPUnit/"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"tests/Autoload.php"
|
||||
]
|
||||
},
|
||||
"require-dev": {
|
||||
"ergebnis/phpstan-rules": "^0.14.4",
|
||||
"ergebnis/phpstan-rules": "^0.15.0",
|
||||
"friendsofphp/php-cs-fixer": "^2.16.3",
|
||||
"illuminate/console": "^7.10.3",
|
||||
"illuminate/support": "^7.10.3",
|
||||
"mockery/mockery": "^1.3.1",
|
||||
"phpstan/phpstan": "^0.12.25",
|
||||
"illuminate/console": "^7.16.1",
|
||||
"illuminate/support": "^7.16.1",
|
||||
"mockery/mockery": "^1.4.0",
|
||||
"phpstan/phpstan": "^0.12.30",
|
||||
"phpstan/phpstan-strict-rules": "^0.12.2",
|
||||
"rector/rector": "^0.7.25",
|
||||
"symfony/var-dumper": "^5.0.8",
|
||||
"rector/rector": "^0.7.37",
|
||||
"symfony/var-dumper": "^5.1.2",
|
||||
"thecodingmachine/phpstan-strict-rules": "^0.12.0"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
@ -62,9 +68,9 @@
|
||||
"lint": "rector process src && php-cs-fixer fix -v",
|
||||
"test:lint": "php-cs-fixer fix -v --dry-run && rector process src --dry-run",
|
||||
"test:types": "phpstan analyse --ansi",
|
||||
"test:unit": "bin/pest --colors=always --exclude-group=integration",
|
||||
"test:integration": "bin/pest --colors=always --group=integration",
|
||||
"test:integration:snapshots": "REBUILD_SNAPSHOTS=true bin/pest --colors=always",
|
||||
"test:unit": "php bin/pest --colors=always --exclude-group=integration",
|
||||
"test:integration": "php bin/pest --colors=always --group=integration",
|
||||
"update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always",
|
||||
"test": [
|
||||
"@test:lint",
|
||||
"@test:types",
|
||||
@ -73,6 +79,9 @@
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "0.2.x-dev"
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Pest\\Laravel\\PestServiceProvider"
|
||||
|
||||
@ -15,8 +15,9 @@ parameters:
|
||||
reportUnmatchedIgnoredErrors: true
|
||||
|
||||
ignoreErrors:
|
||||
- "#Undefined variable: \\$this#"
|
||||
- "#is not allowed to extend#"
|
||||
- "#Language construct eval#"
|
||||
- "# with null as default value#"
|
||||
- "#Using \\$this in static method#"
|
||||
- "#has parameter \\$closure with default value.#"
|
||||
- "#has parameter \\$description with default value.#"
|
||||
|
||||
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Actions;
|
||||
|
||||
use Pest\Console\Coverage;
|
||||
use Pest\Support\Str;
|
||||
use Pest\TestSuite;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class AddsCoverage
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const COVERAGE_OPTION = 'coverage';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const MIN_OPTION = 'min';
|
||||
|
||||
/**
|
||||
* Holds the coverage related options.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
private const OPTIONS = [self::COVERAGE_OPTION, self::MIN_OPTION];
|
||||
|
||||
/**
|
||||
* If any, adds the coverage params to the given original arguments.
|
||||
*
|
||||
* @param array<int, string> $originals
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function from(TestSuite $testSuite, array $originals): array
|
||||
{
|
||||
$arguments = array_merge([''], array_values(array_filter($originals, function ($original): bool {
|
||||
foreach (self::OPTIONS as $option) {
|
||||
if ($original === sprintf('--%s', $option) || Str::startsWith($original, sprintf('--%s=', $option))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
})));
|
||||
|
||||
$originals = array_flip($originals);
|
||||
foreach ($arguments as $argument) {
|
||||
unset($originals[$argument]);
|
||||
}
|
||||
$originals = array_flip($originals);
|
||||
|
||||
$inputs = [];
|
||||
$inputs[] = new InputOption(self::COVERAGE_OPTION, null, InputOption::VALUE_NONE);
|
||||
$inputs[] = new InputOption(self::MIN_OPTION, null, InputOption::VALUE_REQUIRED);
|
||||
|
||||
$input = new ArgvInput($arguments, new InputDefinition($inputs));
|
||||
if ((bool) $input->getOption(self::COVERAGE_OPTION)) {
|
||||
$testSuite->coverage = true;
|
||||
$originals[] = '--coverage-php';
|
||||
$originals[] = Coverage::getPath();
|
||||
}
|
||||
|
||||
if ($input->getOption(self::MIN_OPTION) !== null) {
|
||||
/* @phpstan-ignore-next-line */
|
||||
$testSuite->coverageMin = (float) $input->getOption(self::MIN_OPTION);
|
||||
}
|
||||
|
||||
return $originals;
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,7 @@ final class AddsDefaults
|
||||
public static function to(array $arguments): array
|
||||
{
|
||||
if (!array_key_exists('printer', $arguments)) {
|
||||
$arguments['printer'] = new Printer();
|
||||
$arguments['printer'] = new Printer(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? 'always');
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
|
||||
@ -19,7 +19,6 @@ final class ValidatesEnvironment
|
||||
*/
|
||||
private const NEEDED_FILES = [
|
||||
'composer.json',
|
||||
'tests',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@ -129,16 +129,25 @@ trait TestCase
|
||||
|
||||
/**
|
||||
* Runs the test.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function __test(): void
|
||||
public function __test()
|
||||
{
|
||||
$this->__callClosure($this->__test, func_get_args());
|
||||
return $this->__callClosure($this->__test, func_get_args());
|
||||
}
|
||||
|
||||
private function __callClosure(Closure $closure, array $arguments): void
|
||||
/**
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
private function __callClosure(Closure $closure, array $arguments)
|
||||
{
|
||||
ExceptionTrace::ensure(function () use ($closure, $arguments) {
|
||||
call_user_func_array(Closure::bind($closure, $this, get_class($this)), $arguments);
|
||||
return ExceptionTrace::ensure(function () use ($closure, $arguments) {
|
||||
return call_user_func_array(Closure::bind($closure, $this, get_class($this)), $arguments);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -4,11 +4,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Console;
|
||||
|
||||
use Pest\Actions\AddsCoverage;
|
||||
use Pest\Actions\AddsDefaults;
|
||||
use Pest\Actions\AddsTests;
|
||||
use Pest\Actions\LoadStructure;
|
||||
use Pest\Actions\ValidatesConfiguration;
|
||||
use Pest\Contracts\Plugins\AddsOutput;
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
use Pest\Plugin\Loader;
|
||||
use Pest\TestSuite;
|
||||
use PHPUnit\Framework\TestSuite as BaseTestSuite;
|
||||
use PHPUnit\TextUI\Command as BaseCommand;
|
||||
@ -54,9 +56,14 @@ final class Command extends BaseCommand
|
||||
protected function handleArguments(array $argv): void
|
||||
{
|
||||
/*
|
||||
* First, let's handle pest is own `--coverage` param.
|
||||
* First, let's call all plugins that want to handle arguments
|
||||
*/
|
||||
$argv = AddsCoverage::from($this->testSuite, $argv);
|
||||
$plugins = Loader::getPlugins(HandlesArguments::class);
|
||||
|
||||
/** @var HandlesArguments $plugin */
|
||||
foreach ($plugins as $plugin) {
|
||||
$argv = $plugin->handleArguments($argv);
|
||||
}
|
||||
|
||||
/*
|
||||
* Next, as usual, let's send the console arguments to PHPUnit.
|
||||
@ -81,6 +88,8 @@ final class Command extends BaseCommand
|
||||
*/
|
||||
$this->arguments = AddsDefaults::to($this->arguments);
|
||||
|
||||
LoadStructure::in($this->testSuite->rootPath);
|
||||
|
||||
$testRunner = new TestRunner($this->arguments['loader']);
|
||||
$testSuite = $this->arguments['test'];
|
||||
|
||||
@ -102,7 +111,6 @@ final class Command extends BaseCommand
|
||||
$this->arguments['test'] = $testSuite;
|
||||
}
|
||||
|
||||
LoadStructure::in($this->testSuite->rootPath);
|
||||
AddsTests::to($testSuite, $this->testSuite);
|
||||
|
||||
return $testRunner;
|
||||
@ -119,25 +127,14 @@ final class Command extends BaseCommand
|
||||
{
|
||||
$result = parent::run($argv, false);
|
||||
|
||||
if ($result === 0 && $this->testSuite->coverage) {
|
||||
if (!Coverage::isAvailable()) {
|
||||
$this->output->writeln(
|
||||
"\n <fg=white;bg=red;options=bold> ERROR </> No code coverage driver is available.</>",
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
/*
|
||||
* Let's call all plugins that want to add output after test execution
|
||||
*/
|
||||
$plugins = Loader::getPlugins(AddsOutput::class);
|
||||
|
||||
$coverage = Coverage::report($this->output);
|
||||
|
||||
$result = (int) ($coverage < $this->testSuite->coverageMin);
|
||||
|
||||
if ($result === 1) {
|
||||
$this->output->writeln(sprintf(
|
||||
"\n <fg=white;bg=red;options=bold> FAIL </> Code coverage below expected:<fg=red;options=bold> %s %%</>. Minimum:<fg=white;options=bold> %s %%</>.",
|
||||
number_format($coverage, 1),
|
||||
number_format($this->testSuite->coverageMin, 1)
|
||||
));
|
||||
}
|
||||
/** @var AddsOutput $plugin */
|
||||
foreach ($plugins as $plugin) {
|
||||
$result = $plugin->addOutput($result);
|
||||
}
|
||||
|
||||
exit($result);
|
||||
|
||||
@ -1,167 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Console;
|
||||
|
||||
use Pest\Exceptions\ShouldNotHappen;
|
||||
use SebastianBergmann\CodeCoverage\Node\Directory;
|
||||
use SebastianBergmann\CodeCoverage\Node\File;
|
||||
use SebastianBergmann\Environment\Runtime;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Terminal;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Coverage
|
||||
{
|
||||
/**
|
||||
* Returns the coverage path.
|
||||
*/
|
||||
public static function getPath(): string
|
||||
{
|
||||
return implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__, 2),
|
||||
'.temp',
|
||||
'coverage.php',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs true there is any code
|
||||
* coverage driver available.
|
||||
*/
|
||||
public static function isAvailable(): bool
|
||||
{
|
||||
return (new Runtime())->canCollectCodeCoverage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports the code coverage report to the
|
||||
* console and returns the result in float.
|
||||
*/
|
||||
public static function report(OutputInterface $output): float
|
||||
{
|
||||
if (!file_exists($reportPath = self::getPath())) {
|
||||
throw ShouldNotHappen::fromMessage(sprintf('Coverage not found in path: %s.', $reportPath));
|
||||
}
|
||||
|
||||
/** @var \SebastianBergmann\CodeCoverage\CodeCoverage $codeCoverage */
|
||||
$codeCoverage = require $reportPath;
|
||||
unlink($reportPath);
|
||||
|
||||
$totalWidth = (new Terminal())->getWidth();
|
||||
|
||||
$dottedLineLength = $totalWidth <= 70 ? $totalWidth : 70;
|
||||
|
||||
$totalCoverage = $codeCoverage->getReport()->getLineExecutedPercent();
|
||||
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
' <fg=white;options=bold>Cov: </><fg=default>%s</>',
|
||||
$totalCoverage
|
||||
)
|
||||
);
|
||||
|
||||
$output->writeln('');
|
||||
|
||||
/** @var Directory<File|Directory> $report */
|
||||
$report = $codeCoverage->getReport();
|
||||
|
||||
foreach ($report->getIterator() as $file) {
|
||||
if (!$file instanceof File) {
|
||||
continue;
|
||||
}
|
||||
$dirname = dirname($file->getId());
|
||||
$basename = basename($file->getId(), '.php');
|
||||
|
||||
$name = $dirname === '.' ? $basename : implode(DIRECTORY_SEPARATOR, [
|
||||
$dirname,
|
||||
$basename,
|
||||
]);
|
||||
$rawName = $dirname === '.' ? $basename : implode(DIRECTORY_SEPARATOR, [
|
||||
$dirname,
|
||||
$basename,
|
||||
]);
|
||||
|
||||
$linesExecutedTakenSize = 0;
|
||||
|
||||
if ($file->getLineExecutedPercent() != '0.00%') {
|
||||
$linesExecutedTakenSize = strlen($uncoveredLines = trim(implode(', ', self::getMissingCoverage($file)))) + 1;
|
||||
$name .= sprintf(' <fg=red>%s</>', $uncoveredLines);
|
||||
}
|
||||
|
||||
$percentage = $file->getNumExecutableLines() === 0
|
||||
? '100.0'
|
||||
: number_format((float) $file->getLineExecutedPercent(), 1, '.', '');
|
||||
|
||||
$takenSize = strlen($rawName . $percentage) + 4 + $linesExecutedTakenSize; // adding 3 space and percent sign
|
||||
|
||||
$percentage = sprintf(
|
||||
'<fg=%s>%s</>',
|
||||
$percentage === '100.0' ? 'green' : ($percentage === '0.0' ? 'red' : 'yellow'),
|
||||
$percentage
|
||||
);
|
||||
|
||||
$output->writeln(sprintf(' %s %s %s %%',
|
||||
$name,
|
||||
str_repeat('.', max($dottedLineLength - $takenSize, 1)),
|
||||
$percentage
|
||||
));
|
||||
}
|
||||
|
||||
return (float) $totalCoverage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an array of missing coverage on the following format:.
|
||||
*
|
||||
* ```
|
||||
* ['11', '20..25', '50', '60...80'];
|
||||
* ```
|
||||
*
|
||||
* @param File $file
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getMissingCoverage($file): array
|
||||
{
|
||||
$shouldBeNewLine = true;
|
||||
|
||||
$eachLine = function (array $array, array $tests, int $line) use (&$shouldBeNewLine): array {
|
||||
if (count($tests) > 0) {
|
||||
$shouldBeNewLine = true;
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
if ($shouldBeNewLine) {
|
||||
$array[] = (string) $line;
|
||||
$shouldBeNewLine = false;
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
$lastKey = count($array) - 1;
|
||||
|
||||
if (array_key_exists($lastKey, $array) && strpos($array[$lastKey], '..') !== false) {
|
||||
[$from] = explode('..', $array[$lastKey]);
|
||||
$array[$lastKey] = sprintf('%s..%s', $from, $line);
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
$array[$lastKey] = sprintf('%s..%s', $array[$lastKey], $line);
|
||||
|
||||
return $array;
|
||||
};
|
||||
|
||||
$array = [];
|
||||
foreach (array_filter($file->getCoverageData(), 'is_array') as $line => $tests) {
|
||||
$array = $eachLine($array, $tests, $line);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
16
src/Contracts/Plugins/AddsOutput.php
Normal file
16
src/Contracts/Plugins/AddsOutput.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Contracts\Plugins;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface AddsOutput
|
||||
{
|
||||
/**
|
||||
* Allows to add custom output after the test suite was executed.
|
||||
*/
|
||||
public function addOutput(int $testReturnCode): int;
|
||||
}
|
||||
23
src/Contracts/Plugins/HandlesArguments.php
Normal file
23
src/Contracts/Plugins/HandlesArguments.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Contracts\Plugins;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface HandlesArguments
|
||||
{
|
||||
/**
|
||||
* Allows to handle custom command line arguments.
|
||||
*
|
||||
* PLEASE NOTE: it is necessary to remove any custom argument from the array
|
||||
* because otherwise the application will complain about them
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
*
|
||||
* @return array<int, string> the updated list of arguments
|
||||
*/
|
||||
public function handleArguments(array $arguments): array;
|
||||
}
|
||||
@ -74,12 +74,30 @@ final class Datasets
|
||||
$data = iterator_to_array($data);
|
||||
}
|
||||
|
||||
$namedData = [];
|
||||
$dataSetDescriptions = [];
|
||||
$dataSetValues = [];
|
||||
|
||||
foreach ($data as $values) {
|
||||
$values = is_array($values) ? $values : [$values];
|
||||
|
||||
$name = $description . self::getDataSetDescription($values);
|
||||
$namedData[$name] = $values;
|
||||
$dataSetDescriptions[] = $description . self::getDataSetDescription($values);
|
||||
$dataSetValues[] = $values;
|
||||
}
|
||||
|
||||
foreach (array_count_values($dataSetDescriptions) as $descriptionToCheck => $count) {
|
||||
if ($count > 1) {
|
||||
$index = 1;
|
||||
foreach ($dataSetDescriptions as $i => $dataSetDescription) {
|
||||
if ($dataSetDescription === $descriptionToCheck) {
|
||||
$dataSetDescriptions[$i] .= sprintf(' #%d', $index++);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$namedData = [];
|
||||
foreach ($dataSetDescriptions as $i => $dataSetDescription) {
|
||||
$namedData[$dataSetDescription] = $dataSetValues[$i];
|
||||
}
|
||||
|
||||
return $namedData;
|
||||
|
||||
@ -8,6 +8,7 @@ use Closure;
|
||||
use Pest\Concerns;
|
||||
use Pest\Contracts\HasPrintableTestCaseName;
|
||||
use Pest\Datasets;
|
||||
use Pest\Exceptions\ShouldNotHappen;
|
||||
use Pest\Support\HigherOrderMessageCollection;
|
||||
use Pest\Support\NullClosure;
|
||||
use Pest\TestSuite;
|
||||
@ -39,9 +40,10 @@ final class TestCaseFactory
|
||||
/**
|
||||
* Holds the test description.
|
||||
*
|
||||
* @readonly
|
||||
* If the description is null, means that it
|
||||
* will be created with the given assertions.
|
||||
*
|
||||
* @var string
|
||||
* @var string|null
|
||||
*/
|
||||
public $description;
|
||||
|
||||
@ -104,7 +106,7 @@ final class TestCaseFactory
|
||||
/**
|
||||
* Creates a new anonymous test case pending object.
|
||||
*/
|
||||
public function __construct(string $filename, string $description, Closure $closure = null)
|
||||
public function __construct(string $filename, string $description = null, Closure $closure = null)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
$this->description = $description;
|
||||
@ -122,14 +124,22 @@ final class TestCaseFactory
|
||||
*/
|
||||
public function build(TestSuite $testSuite): array
|
||||
{
|
||||
if ($this->description === null) {
|
||||
throw ShouldNotHappen::fromMessage('Description can not be empty.');
|
||||
}
|
||||
|
||||
$chains = $this->chains;
|
||||
$proxies = $this->proxies;
|
||||
$factoryTest = $this->test;
|
||||
|
||||
$test = function () use ($chains, $proxies, $factoryTest): void {
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
$test = function () use ($chains, $proxies, $factoryTest) {
|
||||
$proxies->proxy($this);
|
||||
$chains->chain($this);
|
||||
call_user_func(Closure::bind($factoryTest, $this, get_class($this)), ...func_get_args());
|
||||
|
||||
return call_user_func(Closure::bind($factoryTest, $this, get_class($this)), ...func_get_args());
|
||||
};
|
||||
|
||||
$className = $this->makeClassFromFilename($this->filename);
|
||||
@ -152,16 +162,25 @@ final class TestCaseFactory
|
||||
*/
|
||||
public function makeClassFromFilename(string $filename): string
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
// In case Windows, strtolower drive name, like in UsesCall.
|
||||
$filename = (string) preg_replace_callback('~^(?P<drive>[a-z]+:\\\)~i', function ($match): string {
|
||||
return strtolower($match['drive']);
|
||||
}, $filename);
|
||||
}
|
||||
|
||||
$filename = (string) realpath($filename);
|
||||
$rootPath = TestSuite::getInstance()->rootPath;
|
||||
$relativePath = str_replace($rootPath . DIRECTORY_SEPARATOR, '', $filename);
|
||||
$relativePath = dirname(ucfirst($relativePath)) . DIRECTORY_SEPARATOR . basename($relativePath, '.php');
|
||||
$relativePath = str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath);
|
||||
|
||||
// Strip out any %-encoded octets.
|
||||
$relativePath = (string) preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $relativePath);
|
||||
|
||||
// Limit to A-Z, a-z, 0-9, '_', '-'.
|
||||
$relativePath = (string) preg_replace('/[^A-Za-z0-9.\/]/', '', $relativePath);
|
||||
|
||||
$classFQN = 'P\\' . basename(ucfirst(str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath)), '.php');
|
||||
$relativePath = (string) preg_replace('/[^A-Za-z0-9.\\\]/', '', $relativePath);
|
||||
|
||||
$classFQN = 'P\\' . $relativePath;
|
||||
if (class_exists($classFQN)) {
|
||||
return $classFQN;
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ namespace Pest\Laravel\Commands;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Pest\Exceptions\InvalidConsoleArgument;
|
||||
use Pest\Support\Str;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -36,6 +37,7 @@ final class PestInstallCommand extends Command
|
||||
$pest = base_path('tests/Pest.php');
|
||||
/* @phpstan-ignore-next-line */
|
||||
$helpers = base_path('tests/Helpers.php');
|
||||
$stubs = $this->isLumen() ? 'stubs/Lumen' : 'stubs/Laravel';
|
||||
|
||||
foreach ([$pest, $helpers] as $file) {
|
||||
if (File::exists($file)) {
|
||||
@ -45,17 +47,26 @@ final class PestInstallCommand extends Command
|
||||
|
||||
File::copy(implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__, 3),
|
||||
'stubs',
|
||||
$stubs,
|
||||
'Pest.php',
|
||||
]), $pest);
|
||||
|
||||
File::copy(implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__, 3),
|
||||
'stubs',
|
||||
$stubs,
|
||||
'Helpers.php',
|
||||
]), $helpers);
|
||||
|
||||
$this->output->success('`tests/Pest.php` created successfully.');
|
||||
$this->output->success('`tests/Helpers.php` created successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this is a Lumen application.
|
||||
*/
|
||||
private function isLumen(): bool
|
||||
{
|
||||
/* @phpstan-ignore-next-line */
|
||||
return Str::startsWith(app()->version(), 'Lumen');
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,12 +9,22 @@ use Pest\Factories\TestCaseFactory;
|
||||
use Pest\Support\Backtrace;
|
||||
use Pest\Support\NullClosure;
|
||||
use Pest\TestSuite;
|
||||
use SebastianBergmann\Exporter\Exporter;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class TestCall
|
||||
{
|
||||
/**
|
||||
* Holds the test suite.
|
||||
*
|
||||
* @readonly
|
||||
*
|
||||
* @var TestSuite
|
||||
*/
|
||||
private $testSuite;
|
||||
|
||||
/**
|
||||
* Holds the test case factory.
|
||||
*
|
||||
@ -24,14 +34,23 @@ final class TestCall
|
||||
*/
|
||||
private $testCaseFactory;
|
||||
|
||||
/**
|
||||
* If test call is descriptionLess.
|
||||
*
|
||||
* @readonly
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $descriptionLess = false;
|
||||
|
||||
/**
|
||||
* Creates a new instance of a pending test call.
|
||||
*/
|
||||
public function __construct(TestSuite $testSuite, string $filename, string $description, Closure $closure = null)
|
||||
public function __construct(TestSuite $testSuite, string $filename, string $description = null, Closure $closure = null)
|
||||
{
|
||||
$this->testCaseFactory = new TestCaseFactory($filename, $description, $closure);
|
||||
|
||||
$testSuite->tests->set($this->testCaseFactory);
|
||||
$this->testSuite = $testSuite;
|
||||
$this->descriptionLess = $description === null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,13 +59,13 @@ final class TestCall
|
||||
public function throws(string $exceptionClass, string $exceptionMessage = null): TestCall
|
||||
{
|
||||
$this->testCaseFactory
|
||||
->proxies
|
||||
->add(Backtrace::file(), Backtrace::line(), 'expectException', [$exceptionClass]);
|
||||
->proxies
|
||||
->add(Backtrace::file(), Backtrace::line(), 'expectException', [$exceptionClass]);
|
||||
|
||||
if (is_string($exceptionMessage)) {
|
||||
$this->testCaseFactory
|
||||
->proxies
|
||||
->add(Backtrace::file(), Backtrace::line(), 'expectExceptionMessage', [$exceptionMessage]);
|
||||
->proxies
|
||||
->add(Backtrace::file(), Backtrace::line(), 'expectExceptionMessage', [$exceptionMessage]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -65,6 +84,18 @@ final class TestCall
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the test depends.
|
||||
*/
|
||||
public function depends(string ...$tests): TestCall
|
||||
{
|
||||
$this->testCaseFactory
|
||||
->factoryProxies
|
||||
->add(Backtrace::file(), Backtrace::line(), 'setDependencies', [$tests]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the test suite only this test case.
|
||||
*/
|
||||
@ -76,13 +107,13 @@ final class TestCall
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the test groups(s).
|
||||
* Sets the test group(s).
|
||||
*/
|
||||
public function group(string ...$groups): TestCall
|
||||
{
|
||||
$this->testCaseFactory
|
||||
->factoryProxies
|
||||
->add(Backtrace::file(), Backtrace::line(), 'addGroups', [$groups]);
|
||||
->factoryProxies
|
||||
->add(Backtrace::file(), Backtrace::line(), 'addGroups', [$groups]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -110,8 +141,8 @@ final class TestCall
|
||||
|
||||
if ($condition() !== false) {
|
||||
$this->testCaseFactory
|
||||
->chains
|
||||
->add(Backtrace::file(), Backtrace::line(), 'markTestSkipped', [$message]);
|
||||
->chains
|
||||
->add(Backtrace::file(), Backtrace::line(), 'markTestSkipped', [$message]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -125,9 +156,26 @@ final class TestCall
|
||||
public function __call(string $name, array $arguments): self
|
||||
{
|
||||
$this->testCaseFactory
|
||||
->chains
|
||||
->add(Backtrace::file(), Backtrace::line(), $name, $arguments);
|
||||
->chains
|
||||
->add(Backtrace::file(), Backtrace::line(), $name, $arguments);
|
||||
|
||||
if ($this->descriptionLess) {
|
||||
$exporter = new Exporter();
|
||||
if ($this->testCaseFactory->description !== null) {
|
||||
$this->testCaseFactory->description .= ' → ';
|
||||
}
|
||||
$this->testCaseFactory->description .= sprintf('%s %s', $name, $exporter->shortenedRecursiveExport($arguments));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the current test case factory
|
||||
* to the tests repository.
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->testSuite->tests->set($this->testCaseFactory);
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +59,17 @@ final class UsesCall
|
||||
public function in(string ...$targets): void
|
||||
{
|
||||
$targets = array_map(function ($path): string {
|
||||
return $path[0] === DIRECTORY_SEPARATOR
|
||||
$startChar = DIRECTORY_SEPARATOR;
|
||||
|
||||
if ('\\' === DIRECTORY_SEPARATOR || preg_match('~\A[A-Z]:(?![^/\\\\])~i', $path) > 0) {
|
||||
$path = (string) preg_replace_callback('~^(?P<drive>[a-z]+:\\\)~i', function ($match): string {
|
||||
return strtolower($match['drive']);
|
||||
}, $path);
|
||||
|
||||
$startChar = strtolower((string) preg_replace('~^([a-z]+:\\\).*$~i', '$1', __DIR__));
|
||||
}
|
||||
|
||||
return 0 === strpos($path, $startChar)
|
||||
? $path
|
||||
: implode(DIRECTORY_SEPARATOR, [
|
||||
dirname($this->filename),
|
||||
@ -68,12 +78,12 @@ final class UsesCall
|
||||
}, $targets);
|
||||
|
||||
$this->targets = array_map(function ($target): string {
|
||||
$realTarget = realpath($target);
|
||||
if ($realTarget === false) {
|
||||
$isValid = is_dir($target) || file_exists($target);
|
||||
if (!$isValid) {
|
||||
throw new InvalidUsesPath($target);
|
||||
}
|
||||
|
||||
return $realTarget;
|
||||
return (string) realpath($target);
|
||||
}, $targets);
|
||||
}
|
||||
|
||||
|
||||
28
src/Plugin.php
Normal file
28
src/Plugin.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest;
|
||||
|
||||
final class Plugin
|
||||
{
|
||||
/**
|
||||
* The lazy callables to be executed
|
||||
* once the test suite boots.
|
||||
*
|
||||
* @var array<int, callable>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public static $callables = [];
|
||||
|
||||
/**
|
||||
* Lazy loads an `uses` call on the context of plugins.
|
||||
*/
|
||||
public static function uses(string ...$traits): void
|
||||
{
|
||||
self::$callables[] = function () use ($traits): void {
|
||||
uses(...$traits)->in(TestSuite::getInstance()->rootPath . DIRECTORY_SEPARATOR . 'tests');
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -41,6 +41,12 @@ final class AfterEachRepository
|
||||
|
||||
return ChainableClosure::from(function (): void {
|
||||
if (class_exists(Mockery::class)) {
|
||||
/* @phpstan-ignore-next-line */
|
||||
if ($container = Mockery::getContainer()) {
|
||||
/* @phpstan-ignore-next-line */
|
||||
$this->addToAssertionCount($container->mockery_getExpectationCount());
|
||||
}
|
||||
|
||||
Mockery::close();
|
||||
}
|
||||
}, $afterEach);
|
||||
|
||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Repositories;
|
||||
|
||||
use Pest\Exceptions\ShouldNotHappen;
|
||||
use Pest\Exceptions\TestAlreadyExist;
|
||||
use Pest\Exceptions\TestCaseAlreadyInUse;
|
||||
use Pest\Exceptions\TestCaseClassOrTraitNotFound;
|
||||
@ -54,7 +55,6 @@ final class TestRepository
|
||||
if ($testCase->class !== \PHPUnit\Framework\TestCase::class) {
|
||||
throw new TestCaseAlreadyInUse($testCase->class, $class, $filename);
|
||||
}
|
||||
|
||||
$testCase->class = $class;
|
||||
} elseif (trait_exists($class)) {
|
||||
$testCase->traits[] = $class;
|
||||
@ -62,9 +62,9 @@ final class TestRepository
|
||||
}
|
||||
|
||||
$testCase
|
||||
->factoryProxies
|
||||
// Consider set the real line here.
|
||||
->add($filename, 0, 'addGroups', [$groups]);
|
||||
->factoryProxies
|
||||
// Consider set the real line here.
|
||||
->add($filename, 0, 'addGroups', [$groups]);
|
||||
}
|
||||
};
|
||||
|
||||
@ -104,7 +104,14 @@ final class TestRepository
|
||||
}
|
||||
|
||||
foreach ($paths as $path) {
|
||||
$this->uses[$path] = [$classOrTraits, $groups];
|
||||
if (array_key_exists($path, $this->uses)) {
|
||||
$this->uses[$path] = [
|
||||
array_merge($this->uses[$path][0], $classOrTraits),
|
||||
array_merge($this->uses[$path][1], $groups),
|
||||
];
|
||||
} else {
|
||||
$this->uses[$path] = [$classOrTraits, $groups];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,6 +120,10 @@ final class TestRepository
|
||||
*/
|
||||
public function set(TestCaseFactory $test): void
|
||||
{
|
||||
if ($test->description === null) {
|
||||
throw ShouldNotHappen::fromMessage('Trying to create a test without description.');
|
||||
}
|
||||
|
||||
if (array_key_exists(sprintf('%s@%s', $test->filename, $test->description), $this->state)) {
|
||||
throw new TestAlreadyExist($test->filename, $test->description);
|
||||
}
|
||||
|
||||
@ -4,17 +4,48 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Support;
|
||||
|
||||
use Pest\Exceptions\ShouldNotHappen;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Backtrace
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const FILE = 'file';
|
||||
|
||||
private const BACKTRACE_OPTIONS = DEBUG_BACKTRACE_IGNORE_ARGS;
|
||||
|
||||
/**
|
||||
* Returns the current test file.
|
||||
*/
|
||||
public static function testFile(): string
|
||||
{
|
||||
$current = null;
|
||||
|
||||
foreach (debug_backtrace(self::BACKTRACE_OPTIONS) as $trace) {
|
||||
if (Str::endsWith($trace[self::FILE], (string) realpath('vendor/phpunit/phpunit/src/Util/FileLoader.php'))) {
|
||||
break;
|
||||
}
|
||||
|
||||
$current = $trace;
|
||||
}
|
||||
|
||||
if ($current === null) {
|
||||
throw ShouldNotHappen::fromMessage('Test file not found.');
|
||||
}
|
||||
|
||||
return $current[self::FILE];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename that called the current function/method.
|
||||
*/
|
||||
public static function file(): string
|
||||
{
|
||||
return debug_backtrace()[1]['file'];
|
||||
return debug_backtrace(self::BACKTRACE_OPTIONS)[1][self::FILE];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -22,7 +53,7 @@ final class Backtrace
|
||||
*/
|
||||
public static function dirname(): string
|
||||
{
|
||||
return dirname(debug_backtrace()[1]['file']);
|
||||
return dirname(debug_backtrace(self::BACKTRACE_OPTIONS)[1][self::FILE]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,6 +61,6 @@ final class Backtrace
|
||||
*/
|
||||
public static function line(): int
|
||||
{
|
||||
return debug_backtrace()[1]['line'];
|
||||
return debug_backtrace(self::BACKTRACE_OPTIONS)[1]['line'];
|
||||
}
|
||||
}
|
||||
|
||||
101
src/Support/Container.php
Normal file
101
src/Support/Container.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Support;
|
||||
|
||||
use Pest\Exceptions\ShouldNotHappen;
|
||||
use ReflectionClass;
|
||||
use ReflectionParameter;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Container
|
||||
{
|
||||
/**
|
||||
* @var self
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
private $instances = [];
|
||||
|
||||
/**
|
||||
* Gets a new or already existing container.
|
||||
*/
|
||||
public static function getInstance(): self
|
||||
{
|
||||
if (static::$instance === null) {
|
||||
static::$instance = new static();
|
||||
}
|
||||
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a dependency from the container.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function get(string $id)
|
||||
{
|
||||
if (array_key_exists($id, $this->instances)) {
|
||||
return $this->instances[$id];
|
||||
}
|
||||
|
||||
$this->instances[$id] = $this->build($id);
|
||||
|
||||
return $this->instances[$id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given instance to the container.
|
||||
*
|
||||
* @param mixed $instance
|
||||
*/
|
||||
public function add(string $id, $instance): void
|
||||
{
|
||||
$this->instances[$id] = $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to build the given instance.
|
||||
*/
|
||||
private function build(string $id): object
|
||||
{
|
||||
/** @phpstan-ignore-next-line */
|
||||
$reflectionClass = new ReflectionClass($id);
|
||||
|
||||
if ($reflectionClass->isInstantiable()) {
|
||||
$constructor = $reflectionClass->getConstructor();
|
||||
|
||||
if ($constructor !== null) {
|
||||
$params = array_map(
|
||||
function (ReflectionParameter $param) use ($id) {
|
||||
$candidate = null;
|
||||
|
||||
if ($param->getType() !== null && $param->getType()->isBuiltin()) {
|
||||
$candidate = $param->getName();
|
||||
} elseif ($param->getClass() !== null) {
|
||||
$candidate = $param->getClass()->getName();
|
||||
} else {
|
||||
throw ShouldNotHappen::fromMessage(sprintf('The type of `$%s` in `%s` cannot be determined.', $id, $param->getName()));
|
||||
}
|
||||
|
||||
return $this->get($candidate);
|
||||
},
|
||||
$constructor->getParameters()
|
||||
);
|
||||
|
||||
return $reflectionClass->newInstanceArgs($params);
|
||||
}
|
||||
|
||||
return $reflectionClass->newInstance();
|
||||
}
|
||||
|
||||
throw ShouldNotHappen::fromMessage(sprintf('A dependency with the name `%s` cannot be resolved.', $id));
|
||||
}
|
||||
}
|
||||
@ -17,11 +17,15 @@ final class ExceptionTrace
|
||||
/**
|
||||
* Ensures the given closure reports
|
||||
* the good execution context.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public static function ensure(Closure $closure): void
|
||||
public static function ensure(Closure $closure)
|
||||
{
|
||||
try {
|
||||
$closure();
|
||||
return $closure();
|
||||
} catch (Throwable $throwable) {
|
||||
if (Str::startsWith($message = $throwable->getMessage(), self::UNDEFINED_METHOD)) {
|
||||
$message = str_replace(self::UNDEFINED_METHOD, 'Call to undefined method ', $message);
|
||||
|
||||
@ -78,7 +78,9 @@ final class HigherOrderMessage
|
||||
|
||||
if ($throwable->getMessage() === sprintf(self::UNDEFINED_METHOD, $this->methodName)) {
|
||||
/** @var \ReflectionClass $reflection */
|
||||
$reflection = (new ReflectionClass($target))->getParentClass();
|
||||
$reflection = new ReflectionClass($target);
|
||||
/* @phpstan-ignore-next-line */
|
||||
$reflection = $reflection->getParentClass() ?: $reflection;
|
||||
Reflection::setPropertyValue($throwable, 'message', sprintf('Call to undefined method %s::%s()', $reflection->getName(), $this->methodName));
|
||||
}
|
||||
|
||||
|
||||
@ -30,20 +30,6 @@ final class TestSuite
|
||||
*/
|
||||
public $tests;
|
||||
|
||||
/**
|
||||
* Whether should show the coverage or not.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $coverage = false;
|
||||
|
||||
/**
|
||||
* The minimum coverage.
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $coverageMin = 0.0;
|
||||
|
||||
/**
|
||||
* Holds the before each repository.
|
||||
*
|
||||
@ -97,7 +83,7 @@ final class TestSuite
|
||||
$this->afterEach = new AfterEachRepository();
|
||||
$this->afterAll = new AfterAllRepository();
|
||||
|
||||
$this->rootPath = $rootPath;
|
||||
$this->rootPath = (string) realpath($rootPath);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,7 +92,13 @@ final class TestSuite
|
||||
public static function getInstance(string $rootPath = null): TestSuite
|
||||
{
|
||||
if (is_string($rootPath)) {
|
||||
return self::$instance ?? self::$instance = new TestSuite($rootPath);
|
||||
self::$instance = new TestSuite($rootPath);
|
||||
|
||||
foreach (Plugin::$callables as $callable) {
|
||||
$callable();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
if (self::$instance === null) {
|
||||
|
||||
@ -13,7 +13,7 @@ use Pest\TestSuite;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Runs the given closure after all tests in the current file.
|
||||
* Runs the given closure before all tests in the current file.
|
||||
*/
|
||||
function beforeAll(Closure $closure): void
|
||||
{
|
||||
@ -66,7 +66,7 @@ function test(string $description = null, Closure $closure = null)
|
||||
return new HigherOrderTapProxy(TestSuite::getInstance()->test);
|
||||
}
|
||||
|
||||
$filename = Backtrace::file();
|
||||
$filename = Backtrace::testFile();
|
||||
|
||||
return new TestCall(TestSuite::getInstance(), $filename, $description, $closure);
|
||||
}
|
||||
@ -80,9 +80,9 @@ function test(string $description = null, Closure $closure = null)
|
||||
*/
|
||||
function it(string $description, Closure $closure = null): TestCall
|
||||
{
|
||||
$filename = Backtrace::file();
|
||||
$description = sprintf('it %s', $description);
|
||||
|
||||
return new TestCall(TestSuite::getInstance(), $filename, sprintf('it %s', $description), $closure);
|
||||
return test($description, $closure);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Set the currently logged in user for the application.
|
||||
*/
|
||||
function actingAs(Authenticatable $user, string $driver = null): TestCase
|
||||
{
|
||||
return test()->actingAs($user, $driver);
|
||||
}
|
||||
11
stubs/Laravel/Helpers.php
Normal file
11
stubs/Laravel/Helpers.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
/**
|
||||
* A basic assert example.
|
||||
*/
|
||||
function assertExample(): void
|
||||
{
|
||||
test()->assertTrue(true);
|
||||
}
|
||||
11
stubs/Lumen/Helpers.php
Normal file
11
stubs/Lumen/Helpers.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
/**
|
||||
* A basic assert example.
|
||||
*/
|
||||
function assertExample(): void
|
||||
{
|
||||
test()->assertTrue(true);
|
||||
}
|
||||
3
stubs/Lumen/Pest.php
Normal file
3
stubs/Lumen/Pest.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
uses(TestCase::class)->in(__DIR__);
|
||||
17
stubs/Lumen/phpunit.xml
Normal file
17
stubs/Lumen/phpunit.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?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="Application Test Suite">
|
||||
<directory suffix="Test.php">./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./app</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
7
tests/.snapshots/allows-to-run-a-directory.txt
Normal file
7
tests/.snapshots/allows-to-run-a-directory.txt
Normal file
@ -0,0 +1,7 @@
|
||||
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
||||
✓ it example 1
|
||||
|
||||
PASS Tests\Fixtures\ExampleTest
|
||||
✓ it example 2
|
||||
|
||||
Tests: 2 passed
|
||||
4
tests/.snapshots/allows-to-run-a-single-test.txt
Normal file
4
tests/.snapshots/allows-to-run-a-single-test.txt
Normal file
@ -0,0 +1,4 @@
|
||||
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
||||
✓ it example 1
|
||||
|
||||
Tests: 1 passed
|
||||
60
tests/.snapshots/coverage.txt
Normal file
60
tests/.snapshots/coverage.txt
Normal file
@ -0,0 +1,60 @@
|
||||
|
||||
PASS Tests\Playground
|
||||
✓ basic
|
||||
|
||||
Tests: 1 passed
|
||||
Time: 0.20s
|
||||
Cov: 6.49%
|
||||
|
||||
Actions/AddsDefaults ........................................... 0.0 %
|
||||
Actions/AddsTests .............................................. 0.0 %
|
||||
Actions/LoadStructure .......................................... 0.0 %
|
||||
Actions/ValidatesConfiguration ................................. 0.0 %
|
||||
Actions/ValidatesEnvironment ................................... 0.0 %
|
||||
Concerns/TestCase 40..54, 71..88, 123..126, 147 ............... 44.4 %
|
||||
Console/Command ................................................ 0.0 %
|
||||
Contracts/HasPrintableTestCaseName ............................. 0.0 %
|
||||
Contracts/Plugins/AddsOutput ................................ 100.0 %
|
||||
Contracts/Plugins/HandlesArguments .......................... 100.0 %
|
||||
Datasets ....................................................... 0.0 %
|
||||
Exceptions/AfterAllAlreadyExist ................................ 0.0 %
|
||||
Exceptions/AfterEachAlreadyExist ............................... 0.0 %
|
||||
Exceptions/AttributeNotSupportedYet ............................ 0.0 %
|
||||
Exceptions/BeforeEachAlreadyExist .............................. 0.0 %
|
||||
Exceptions/DatasetAlreadyExist ................................. 0.0 %
|
||||
Exceptions/DatasetDoesNotExist ................................. 0.0 %
|
||||
Exceptions/FileOrFolderNotFound ................................ 0.0 %
|
||||
Exceptions/InvalidConsoleArgument .............................. 0.0 %
|
||||
Exceptions/InvalidPestCommand .................................. 0.0 %
|
||||
Exceptions/InvalidUsesPath ..................................... 0.0 %
|
||||
Exceptions/ShouldNotHappen ..................................... 0.0 %
|
||||
Exceptions/TestAlreadyExist .................................... 0.0 %
|
||||
Exceptions/TestCaseAlreadyInUse ................................ 0.0 %
|
||||
Exceptions/TestCaseClassOrTraitNotFound ........................ 0.0 %
|
||||
Factories/TestCaseFactory 111..133, 141..204 ................... 8.2 %
|
||||
Laravel/Commands/PestDatasetCommand ............................ 0.0 %
|
||||
Laravel/Commands/PestInstallCommand ............................ 0.0 %
|
||||
Laravel/Commands/PestTestCommand ............................... 0.0 %
|
||||
Laravel/PestServiceProvider .................................... 0.0 %
|
||||
PendingObjects/AfterEachCall ................................... 0.0 %
|
||||
PendingObjects/BeforeEachCall .................................. 0.0 %
|
||||
PendingObjects/TestCall ........................................ 0.0 %
|
||||
PendingObjects/UsesCall ........................................ 0.0 %
|
||||
Plugin ......................................................... 0.0 %
|
||||
Repositories/AfterAllRepository ................................ 0.0 %
|
||||
Repositories/AfterEachRepository 28..33 ....................... 60.0 %
|
||||
Repositories/BeforeAllRepository ............................... 0.0 %
|
||||
Repositories/BeforeEachRepository 26..31 ...................... 20.0 %
|
||||
Repositories/TestRepository .................................... 0.0 %
|
||||
Support/Backtrace .............................................. 0.0 %
|
||||
Support/ChainableClosure .................................... 100.0 %
|
||||
Support/Container .............................................. 0.0 %
|
||||
Support/ExceptionTrace 25..32 ................................. 28.6 %
|
||||
Support/HigherOrderMessage ..................................... 0.0 %
|
||||
Support/HigherOrderMessageCollection 24..25, 33, 43 ........... 50.0 %
|
||||
Support/HigherOrderTapProxy .................................... 0.0 %
|
||||
Support/NullClosure ......................................... 100.0 %
|
||||
Support/Reflection ............................................. 0.0 %
|
||||
Support/Str .................................................... 0.0 %
|
||||
TestSuite 80..87, 95..101, 105 ................................ 20.0 %
|
||||
globals ........................................................ 0.0 %
|
||||
5
tests/.snapshots/disable-decorating-printer.txt
Normal file
5
tests/.snapshots/disable-decorating-printer.txt
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
||||
✓ [2mit example 1[22m
|
||||
|
||||
Tests: 1 passed
|
||||
5
tests/.snapshots/has-ascii-chars.txt
Normal file
5
tests/.snapshots/has-ascii-chars.txt
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
[30;42;1m PASS [39;49;22m[39m Tests\Fixtures\DirectoryWithTests\ExampleTest[39m
|
||||
[32;1m✓[39;22m[39m [2mit example 1[22m[39m
|
||||
|
||||
[37;1mTests: [39;22m[32;1m1 passed[39;22m
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
PASS Tests\CustomTestCase\PhpunitTest
|
||||
PASS Tests\CustomTestCase\ExecutedTest
|
||||
✓ that gets executed
|
||||
|
||||
PASS Tests\Features\AfterAll
|
||||
@ -24,7 +24,7 @@
|
||||
✓ it sets arrays
|
||||
✓ it gets bound to test case object with ('a')
|
||||
✓ it gets bound to test case object with ('b')
|
||||
✓ it truncates the description with (' fooo fooo fooo fooo fooo fooo fooo f...oo fooo')
|
||||
✓ it truncates the description with ('FoooFoooFoooFoooFoooFoooFoooF...ooFooo')
|
||||
✓ lazy datasets with (1)
|
||||
✓ lazy datasets with (2)
|
||||
✓ lazy datasets did the job right
|
||||
@ -40,10 +40,25 @@
|
||||
✓ eager wrapped registered datasets with (1)
|
||||
✓ eager wrapped registered datasets with (2)
|
||||
✓ eager registered wrapped datasets did the job right
|
||||
✓ lazy named datasets with ( bar object (...))
|
||||
✓ lazy named datasets with (Bar Object (...))
|
||||
✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #1
|
||||
✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #2
|
||||
✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), false)
|
||||
✓ it creates unique test case names with ('Name 2', Pest\Plugin Object (), false)
|
||||
✓ it creates unique test case names with ('Name 2', Pest\Plugin Object (), true)
|
||||
✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #3
|
||||
✓ it creates unique test case names - count
|
||||
|
||||
PASS Tests\Features\Depends
|
||||
✓ first
|
||||
✓ second
|
||||
✓ depends
|
||||
✓ depends with ...params
|
||||
✓ depends with defined arguments
|
||||
✓ depends run test only once
|
||||
|
||||
PASS Tests\Features\Exceptions
|
||||
✓ it gives access the the underlying expect exception
|
||||
✓ it gives access the the underlying expectException
|
||||
✓ it catch exceptions
|
||||
✓ it catch exceptions and messages
|
||||
|
||||
@ -53,7 +68,7 @@
|
||||
✓ it allows to call underlying protected/private methods
|
||||
✓ it throws error if method do not exist
|
||||
|
||||
PASS Tests\Features\HigherOrderMessages
|
||||
PASS Tests\Features\HigherOrderTests
|
||||
✓ it proxies calls to object
|
||||
|
||||
PASS Tests\Features\It
|
||||
@ -63,6 +78,10 @@
|
||||
PASS Tests\Features\Mocks
|
||||
✓ it has bar
|
||||
|
||||
PASS Tests\Features\PendingHigherOrderTests
|
||||
✓ get 'foo' → get 'bar' → assertTrue true
|
||||
✓ get 'foo' → assertTrue true
|
||||
|
||||
WARN Tests\Features\Skip
|
||||
✓ it do not skips
|
||||
s it skips with truthy
|
||||
@ -70,23 +89,23 @@
|
||||
s it skips with message → skipped because bar
|
||||
s it skips with truthy closure condition
|
||||
✓ it do not skips with falsy closure condition
|
||||
s it skips with condition and messsage → skipped because foo
|
||||
s it skips with condition and message → skipped because foo
|
||||
|
||||
PASS Tests\Features\Test
|
||||
✓ a test
|
||||
✓ higher order message test
|
||||
|
||||
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
||||
✓ it example
|
||||
✓ it example 1
|
||||
|
||||
PASS Tests\Fixtures\ExampleTest
|
||||
✓ it example
|
||||
✓ it example 2
|
||||
|
||||
PASS Tests\PHPUnit\CustomTestCase\UsesPerDirectory
|
||||
✓ closure was bound to custom test case
|
||||
✓ closure was bound to CustomTestCase
|
||||
|
||||
PASS Tests\PHPUnit\CustomTestCaseInSubFolders\SubFolder\SubFolder\UsesPerSubDirectory
|
||||
✓ closure was bound to custom test case
|
||||
✓ closure was bound to CustomTestCase
|
||||
|
||||
PASS Tests\PHPUnit\CustomTestCaseInSubFolders\SubFolder2\UsesPerFile
|
||||
✓ custom traits can be used
|
||||
@ -95,9 +114,9 @@
|
||||
PASS Tests\Playground
|
||||
✓ basic
|
||||
|
||||
PASS Tests\Unit\Actions\AddsCoverage
|
||||
✓ it adds coverage if --coverage exist
|
||||
✓ it adds coverage if --min exist
|
||||
PASS Tests\Plugins\Traits
|
||||
✓ it allows global uses
|
||||
✓ it allows multiple global uses registered in the same path
|
||||
|
||||
PASS Tests\Unit\Actions\AddsDefaults
|
||||
✓ it sets defaults
|
||||
@ -112,12 +131,18 @@
|
||||
✓ it throws exception when `process isolation` is true
|
||||
✓ it do not throws exception when `process isolation` is false
|
||||
|
||||
PASS Tests\Unit\Console\Coverage
|
||||
✓ it generates coverage based on file input
|
||||
|
||||
PASS Tests\Unit\Support\Backtrace
|
||||
✓ it gets file name from called file
|
||||
|
||||
PASS Tests\Unit\Support\Container
|
||||
✓ it exists
|
||||
✓ it gets an instance
|
||||
✓ autowire
|
||||
✓ it creates an instance and resolves parameters
|
||||
✓ it creates an instance and resolves also sub parameters
|
||||
✓ it can resolve builtin value types
|
||||
✓ it cannot resolve a parameter without type
|
||||
|
||||
PASS Tests\Unit\Support\Reflection
|
||||
✓ it gets file name from closure
|
||||
✓ it gets property values
|
||||
@ -128,9 +153,11 @@
|
||||
PASS Tests\Visual\SingleTestOrDirectory
|
||||
✓ allows to run a single test
|
||||
✓ allows to run a directory
|
||||
✓ it has ascii chars
|
||||
✓ it disable decorating printer when colors is set to never
|
||||
|
||||
WARN Tests\Visual\Success
|
||||
s visual snapshot of test suite on success
|
||||
|
||||
Tests: 6 skipped, 69 passed
|
||||
Time: 2.63s
|
||||
Tests: 6 skipped, 92 passed
|
||||
Time: 3.40s
|
||||
|
||||
@ -3,3 +3,22 @@
|
||||
if (class_exists(NunoMaduro\Collision\Provider::class)) {
|
||||
(new NunoMaduro\Collision\Provider())->register();
|
||||
}
|
||||
|
||||
trait PluginTrait
|
||||
{
|
||||
public function assertPluginTraitGotRegistered(): void
|
||||
{
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
trait SecondPluginTrait
|
||||
{
|
||||
public function assertSecondPluginTraitGotRegistered(): void
|
||||
{
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
Pest\Plugin::uses(PluginTrait::class);
|
||||
Pest\Plugin::uses(SecondPluginTrait::class);
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
use Pest\Datasets;
|
||||
use Pest\Exceptions\DatasetAlreadyExist;
|
||||
use Pest\Exceptions\DatasetDoesNotExist;
|
||||
use Pest\Plugin;
|
||||
|
||||
it('throws exception if dataset does not exist', function () {
|
||||
$this->expectException(DatasetDoesNotExist::class);
|
||||
@ -106,3 +107,21 @@ $namedDatasets = [
|
||||
test('lazy named datasets', function ($text) use ($state, $datasets) {
|
||||
assertTrue(true);
|
||||
})->with($namedDatasets);
|
||||
|
||||
$counter = 0;
|
||||
|
||||
it('creates unique test case names', function (string $name, Plugin $plugin, bool $bool) use (&$counter) {
|
||||
assertTrue(true);
|
||||
$counter++;
|
||||
})->with([
|
||||
['Name 1', new Plugin(), true],
|
||||
['Name 1', new Plugin(), true],
|
||||
['Name 1', new Plugin(), false],
|
||||
['Name 2', new Plugin(), false],
|
||||
['Name 2', new Plugin(), true],
|
||||
['Name 1', new Plugin(), true],
|
||||
]);
|
||||
|
||||
it('creates unique test case names - count', function () use (&$counter) {
|
||||
assertEquals(6, $counter);
|
||||
});
|
||||
|
||||
40
tests/Features/Depends.php
Normal file
40
tests/Features/Depends.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
$runCounter = 0;
|
||||
|
||||
test('first', function () use (&$runCounter) {
|
||||
assertTrue(true);
|
||||
$runCounter++;
|
||||
|
||||
return 'first';
|
||||
});
|
||||
|
||||
test('second', function () use (&$runCounter) {
|
||||
assertTrue(true);
|
||||
$runCounter++;
|
||||
|
||||
return 'second';
|
||||
});
|
||||
|
||||
test('depends', function () {
|
||||
assertEquals(
|
||||
['first', 'second'],
|
||||
func_get_args()
|
||||
);
|
||||
})->depends('first', 'second');
|
||||
|
||||
test('depends with ...params', function (string ...$params) {
|
||||
assertEquals(
|
||||
['first', 'second'],
|
||||
$params
|
||||
);
|
||||
})->depends('first', 'second');
|
||||
|
||||
test('depends with defined arguments', function (string $first, string $second) {
|
||||
assertEquals('first', $first);
|
||||
assertEquals('second', $second);
|
||||
})->depends('first', 'second');
|
||||
|
||||
test('depends run test only once', function () use (&$runCounter) {
|
||||
assertEquals(2, $runCounter);
|
||||
})->depends('first', 'second');
|
||||
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use function Tests\mock;
|
||||
|
||||
interface Foo
|
||||
{
|
||||
public function bar(): int;
|
||||
@ -11,5 +13,5 @@ it('has bar', function () {
|
||||
->times(1)
|
||||
->andReturn(2);
|
||||
|
||||
assertEquals(2, $mock->bar());
|
||||
$mock->bar();
|
||||
});
|
||||
|
||||
29
tests/Features/PendingHigherOrderTests.php
Normal file
29
tests/Features/PendingHigherOrderTests.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
uses(Gettable::class);
|
||||
|
||||
/**
|
||||
* @return TestCase|Gettable
|
||||
*/
|
||||
function get(string $route)
|
||||
{
|
||||
return test()->get($route);
|
||||
}
|
||||
|
||||
trait Gettable
|
||||
{
|
||||
/**
|
||||
* @return TestCase|Gettable
|
||||
*/
|
||||
public function get(string $route)
|
||||
{
|
||||
assertNotEmpty($route);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
get('foo')->get('bar')->assertTrue(true);
|
||||
get('foo')->assertTrue(true);
|
||||
@ -24,6 +24,6 @@ it('do not skips with falsy closure condition')
|
||||
->skip(function () { return false; })
|
||||
->assertTrue(true);
|
||||
|
||||
it('skips with condition and messsage')
|
||||
it('skips with condition and message')
|
||||
->skip(true, 'skipped because foo')
|
||||
->assertTrue(false);
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
<?php
|
||||
|
||||
it('example')->assertTrue(true);
|
||||
it('example 1')->assertTrue(true);
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
<?php
|
||||
|
||||
it('example')->assertTrue(true);
|
||||
it('example 2')->assertTrue(true);
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
|
||||
function mock(string $class): MockInterface
|
||||
|
||||
@ -7,7 +7,7 @@ namespace Tests\CustomTestCase;
|
||||
use function PHPUnit\Framework\assertTrue;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PhpunitTest extends TestCase
|
||||
class ExecutedTest extends TestCase
|
||||
{
|
||||
public static $executed = false;
|
||||
|
||||
@ -16,8 +16,8 @@ class PhpunitTest extends TestCase
|
||||
{
|
||||
self::$executed = true;
|
||||
|
||||
$this->assertTrue(true);
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
// register_shutdown_function(fn () => assertTrue(PhpunitTest::$executed));
|
||||
// register_shutdown_function(fn () => assertTrue(ExecutedTest::$executed));
|
||||
5
tests/Plugins/Traits.php
Normal file
5
tests/Plugins/Traits.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
it('allows global uses')->assertPluginTraitGotRegistered();
|
||||
|
||||
it('allows multiple global uses registered in the same path')->assertSecondPluginTraitGotRegistered();
|
||||
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Pest\Actions\AddsCoverage;
|
||||
use Pest\TestSuite;
|
||||
|
||||
it('adds coverage if --coverage exist', function () {
|
||||
$testSuite = new TestSuite(getcwd());
|
||||
assertFalse($testSuite->coverage);
|
||||
|
||||
$arguments = AddsCoverage::from($testSuite, []);
|
||||
assertEquals([], $arguments);
|
||||
assertFalse($testSuite->coverage);
|
||||
|
||||
$arguments = AddsCoverage::from($testSuite, ['--coverage']);
|
||||
assertEquals(['--coverage-php', \Pest\Console\Coverage::getPath()], $arguments);
|
||||
assertTrue($testSuite->coverage);
|
||||
});
|
||||
|
||||
it('adds coverage if --min exist', function () {
|
||||
$testSuite = new TestSuite(getcwd());
|
||||
assertEquals($testSuite->coverageMin, 0.0);
|
||||
|
||||
assertFalse($testSuite->coverage);
|
||||
AddsCoverage::from($testSuite, []);
|
||||
assertEquals($testSuite->coverageMin, 0.0);
|
||||
|
||||
AddsCoverage::from($testSuite, ['--min=2']);
|
||||
assertEquals($testSuite->coverageMin, 2.0);
|
||||
|
||||
AddsCoverage::from($testSuite, ['--min=2.4']);
|
||||
assertEquals($testSuite->coverageMin, 2.4);
|
||||
});
|
||||
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Pest\Console\Coverage;
|
||||
|
||||
it('generates coverage based on file input', function () {
|
||||
assertEquals([
|
||||
'4..6', '102',
|
||||
], Coverage::getMissingCoverage(new class() {
|
||||
public function getCoverageData(): array
|
||||
{
|
||||
return [
|
||||
1 => ['foo'],
|
||||
2 => ['bar'],
|
||||
4 => [],
|
||||
5 => [],
|
||||
6 => [],
|
||||
7 => null,
|
||||
100 => null,
|
||||
101 => ['foo'],
|
||||
102 => [],
|
||||
];
|
||||
}
|
||||
}));
|
||||
});
|
||||
69
tests/Unit/Support/Container.php
Normal file
69
tests/Unit/Support/Container.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
use Pest\Exceptions\ShouldNotHappen;
|
||||
use Pest\Support\Container;
|
||||
use Pest\TestSuite;
|
||||
|
||||
uses()->group('container');
|
||||
|
||||
beforeEach(function () {
|
||||
$this->container = new Container();
|
||||
});
|
||||
|
||||
it('exists')
|
||||
->assertTrue(class_exists(Container::class));
|
||||
|
||||
it('gets an instance', function () {
|
||||
$this->container->add(Container::class, $this->container);
|
||||
assertSame($this->container, $this->container->get(Container::class));
|
||||
});
|
||||
|
||||
test('autowire', function () {
|
||||
assertInstanceOf(Container::class, $this->container->get(Container::class));
|
||||
});
|
||||
|
||||
it('creates an instance and resolves parameters', function () {
|
||||
$this->container->add(Container::class, $this->container);
|
||||
$instance = $this->container->get(ClassWithDependency::class);
|
||||
|
||||
assertInstanceOf(ClassWithDependency::class, $instance);
|
||||
});
|
||||
|
||||
it('creates an instance and resolves also sub parameters', function () {
|
||||
$this->container->add(Container::class, $this->container);
|
||||
$instance = $this->container->get(ClassWithSubDependency::class);
|
||||
|
||||
assertInstanceOf(ClassWithSubDependency::class, $instance);
|
||||
});
|
||||
|
||||
it('can resolve builtin value types', function () {
|
||||
$this->container->add('rootPath', getcwd());
|
||||
|
||||
$instance = $this->container->get(TestSuite::class);
|
||||
assertInstanceOf(TestSuite::class, $instance);
|
||||
});
|
||||
|
||||
it('cannot resolve a parameter without type', function () {
|
||||
$this->container->get(ClassWithoutTypeParameter::class);
|
||||
})->throws(ShouldNotHappen::class);
|
||||
|
||||
class ClassWithDependency
|
||||
{
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ClassWithSubDependency
|
||||
{
|
||||
public function __construct(ClassWithDependency $param)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ClassWithoutTypeParameter
|
||||
{
|
||||
public function __construct($param)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -2,31 +2,56 @@
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
$run = function (string $target) {
|
||||
$process = new Process(['./bin/pest', $target], dirname(__DIR__, 2));
|
||||
$run = function (string $target, $decorated = false) {
|
||||
$process = new Process(['php', 'bin/pest', $target], dirname(__DIR__, 2));
|
||||
|
||||
$process->run();
|
||||
|
||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
};
|
||||
|
||||
test('allows to run a single test', function () use ($run) {
|
||||
assertStringContainsString(<<<EOF
|
||||
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
||||
✓ it example
|
||||
$snapshot = function ($name) {
|
||||
$testsPath = dirname(__DIR__);
|
||||
|
||||
Tests: 1 passed
|
||||
EOF, $run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'));
|
||||
});
|
||||
return file_get_contents(implode(DIRECTORY_SEPARATOR, [
|
||||
$testsPath,
|
||||
'.snapshots',
|
||||
"$name.txt",
|
||||
]));
|
||||
};
|
||||
|
||||
test('allows to run a directory', function () use ($run) {
|
||||
assertStringContainsString(<<<EOF
|
||||
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
||||
✓ it example
|
||||
test('allows to run a single test', function () use ($run, $snapshot) {
|
||||
assertStringContainsString(
|
||||
$snapshot('allows-to-run-a-single-test'),
|
||||
$run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'));
|
||||
})->skip(PHP_OS_FAMILY === 'Windows');
|
||||
|
||||
PASS Tests\Fixtures\ExampleTest
|
||||
✓ it example
|
||||
test('allows to run a directory', function () use ($run, $snapshot) {
|
||||
assertStringContainsString(
|
||||
$snapshot('allows-to-run-a-directory'),
|
||||
$run('tests/Fixtures')
|
||||
);
|
||||
})->skip(PHP_OS_FAMILY === 'Windows');
|
||||
|
||||
Tests: 2 passed
|
||||
EOF, $run('tests/Fixtures'));
|
||||
});
|
||||
it('has ascii chars', function () use ($run, $snapshot) {
|
||||
assertStringContainsString(
|
||||
$snapshot('has-ascii-chars'),
|
||||
$run('tests/Fixtures/DirectoryWithTests/ExampleTest.php', true)
|
||||
);
|
||||
})->skip(PHP_OS_FAMILY === 'Windows');
|
||||
|
||||
it('disable decorating printer when colors is set to never', function () use ($snapshot) {
|
||||
$process = new Process([
|
||||
'php',
|
||||
'./bin/pest',
|
||||
'--colors=never',
|
||||
'tests/Fixtures/DirectoryWithTests/ExampleTest.php',
|
||||
], dirname(__DIR__, 2));
|
||||
$process->run();
|
||||
$output = $process->getOutput();
|
||||
|
||||
assertStringContainsString(
|
||||
$snapshot('disable-decorating-printer'),
|
||||
$output
|
||||
);
|
||||
})->skip(PHP_OS_FAMILY === 'Windows');
|
||||
|
||||
@ -9,7 +9,7 @@ test('visual snapshot of test suite on success', function () {
|
||||
]);
|
||||
|
||||
$output = function () use ($testsPath) {
|
||||
$process = (new Symfony\Component\Process\Process(['./bin/pest'], dirname($testsPath), ['EXCLUDE' => 'integration', 'REBUILD_SNAPSHOTS' => false]));
|
||||
$process = (new Symfony\Component\Process\Process(['php', 'bin/pest'], dirname($testsPath), ['EXCLUDE' => 'integration', 'REBUILD_SNAPSHOTS' => false]));
|
||||
|
||||
$process->run();
|
||||
|
||||
@ -24,4 +24,5 @@ test('visual snapshot of test suite on success', function () {
|
||||
array_pop($output);
|
||||
assertStringContainsString(implode("\n", $output), file_get_contents($snapshot));
|
||||
}
|
||||
})->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE'));
|
||||
})->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE'))
|
||||
->skip(PHP_OS_FAMILY === 'Windows');
|
||||
|
||||
Reference in New Issue
Block a user