mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
Compare commits
158 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1241e929b1 | |||
| db7c4b174f | |||
| 460ce45349 | |||
| 8e203e914e | |||
| 64a8ed04ff | |||
| 234b6847ad | |||
| 933820c8d3 | |||
| 4e9587da59 | |||
| 60a5db14ba | |||
| 7ea3e02afa | |||
| 421c52fb74 | |||
| a3644f7efa | |||
| c7326f430b | |||
| 9ea51caf3f | |||
| cb4c9563bd | |||
| fac44d9afe | |||
| 6e27c6d85d | |||
| 9a0cfaf339 | |||
| 321b3e8df3 | |||
| bff97418ed | |||
| a47ad6a1d3 | |||
| 74c14808cf | |||
| eff2d7f613 | |||
| e135979f34 | |||
| 15edde8e87 | |||
| 211f5c2433 | |||
| 5d58d58f71 | |||
| d5a4008d3e | |||
| 1bf802268f | |||
| 807a4b004f | |||
| 53a8c7b05e | |||
| ef5715ce10 | |||
| 0c04882389 | |||
| 323c5f211f | |||
| 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 |
10
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
10
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
| Q | A
|
||||||
|
| ------------- | ---
|
||||||
|
| Bug fix? | yes/no
|
||||||
|
| New feature? | yes/no
|
||||||
|
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
- Replace this comment by a description of what your PR is solving.
|
||||||
|
-->
|
||||||
|
|
||||||
54
.github/workflows/changelog.yml
vendored
Normal file
54
.github/workflows/changelog.yml
vendored
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
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 }}
|
||||||
|
|
||||||
|
Next section: [Upgrade Guide →](/docs/upgrade-guide)
|
||||||
|
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']
|
on: ['push', 'pull_request']
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
ci:
|
ci:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: true
|
fail-fast: true
|
||||||
matrix:
|
matrix:
|
||||||
php: [7.3, 7.4]
|
os: [ubuntu-latest]
|
||||||
|
php: [7.4]
|
||||||
dependency-version: [prefer-lowest, prefer-stable]
|
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:
|
steps:
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ jobs:
|
|||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: ${{ matrix.php }}
|
php-version: ${{ matrix.php }}
|
||||||
extensions: mbstring, zip
|
extensions: dom, mbstring, zip
|
||||||
tools: prestissimo
|
tools: prestissimo
|
||||||
coverage: pcov
|
coverage: pcov
|
||||||
|
|
||||||
@ -43,9 +44,3 @@ jobs:
|
|||||||
|
|
||||||
- name: Type Checks
|
- name: Type Checks
|
||||||
run: vendor/bin/phpstan analyse --ansi
|
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
|
.temp/coverage.php
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
|
.vscode/
|
||||||
46
CHANGELOG.md
46
CHANGELOG.md
@ -5,6 +5,52 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Added
|
||||||
|
- `--init` and `pest:install` artisan command output changes ([#118](https://github.com/pestphp/pest/pull/118), [db7c4b1](https://github.com/pestphp/pest/commit/db7c4b174f0974969450dda71dcd649ef0c073a3))
|
||||||
|
- `--version` option to view the current version of Pest ([9ea51ca](https://github.com/pestphp/pest/commit/9ea51caf3f74569debb1e465992e9ea916cb80fe))
|
||||||
|
|
||||||
|
## [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)
|
## [v0.1.3 (2020-05-21)](https://github.com/pestphp/pest/compare/v0.1.2...v0.1.3)
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
</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)**
|
- Explore the docs: **[pestphp.com »](https://pestphp.com)**
|
||||||
- Follow us on Twitter: **[@pestphp »](https://twitter.com/pestphp)**
|
- Follow us on Twitter: **[@pestphp »](https://twitter.com/pestphp)**
|
||||||
|
|||||||
18
bin/pest
18
bin/pest
@ -1,31 +1,39 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
use NunoMaduro\Collision\Provider;
|
||||||
use Pest\Actions\ValidatesEnvironment;
|
use Pest\Actions\ValidatesEnvironment;
|
||||||
use Pest\Console\Command;
|
use Pest\Console\Command;
|
||||||
|
use Pest\Support\Container;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
(static function () {
|
(static function () {
|
||||||
// Used when Pest is required using composer.
|
// 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.
|
// 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;
|
include_once $vendorPath;
|
||||||
} else {
|
} else {
|
||||||
include_once $localPath;
|
include_once $localPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
(new \NunoMaduro\Collision\Provider)->register();
|
(new Provider())->register();
|
||||||
|
|
||||||
$rootPath = getcwd();
|
$rootPath = getcwd();
|
||||||
|
|
||||||
$testSuite = TestSuite::getInstance($rootPath);
|
$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);
|
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": {
|
"require": {
|
||||||
"php": "^7.3",
|
"php": "^7.3",
|
||||||
"nunomaduro/collision": "^5.0",
|
"nunomaduro/collision": "^5.0.0-BETA3",
|
||||||
|
"pestphp/pest-plugin": "^0.2",
|
||||||
|
"pestphp/pest-plugin-coverage": "^0.2",
|
||||||
|
"pestphp/pest-plugin-init": "^0.2",
|
||||||
"phpunit/phpunit": "^9.1.4",
|
"phpunit/phpunit": "^9.1.4",
|
||||||
"sebastian/environment": "^5.1"
|
"sebastian/environment": "^5.1"
|
||||||
},
|
},
|
||||||
@ -28,6 +31,7 @@
|
|||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src/globals.php",
|
"src/globals.php",
|
||||||
|
"src/Pest.php",
|
||||||
"compiled/globals.php"
|
"compiled/globals.php"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -40,15 +44,15 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"ergebnis/phpstan-rules": "^0.14.4",
|
"ergebnis/phpstan-rules": "^0.15.0",
|
||||||
"friendsofphp/php-cs-fixer": "^2.16.3",
|
"friendsofphp/php-cs-fixer": "^2.16.3",
|
||||||
"illuminate/console": "^7.10.3",
|
"illuminate/console": "^7.16.1",
|
||||||
"illuminate/support": "^7.10.3",
|
"illuminate/support": "^7.16.1",
|
||||||
"mockery/mockery": "^1.3.1",
|
"mockery/mockery": "^1.4.0",
|
||||||
"phpstan/phpstan": "^0.12.25",
|
"phpstan/phpstan": "^0.12.30",
|
||||||
"phpstan/phpstan-strict-rules": "^0.12.2",
|
"phpstan/phpstan-strict-rules": "^0.12.2",
|
||||||
"rector/rector": "^0.7.25",
|
"rector/rector": "^0.7.37",
|
||||||
"symfony/var-dumper": "^5.0.8",
|
"symfony/var-dumper": "^5.1.2",
|
||||||
"thecodingmachine/phpstan-strict-rules": "^0.12.0"
|
"thecodingmachine/phpstan-strict-rules": "^0.12.0"
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
@ -64,10 +68,10 @@
|
|||||||
"compile": "@php ./scripts/compile.php",
|
"compile": "@php ./scripts/compile.php",
|
||||||
"lint": "rector process src && php-cs-fixer fix -v",
|
"lint": "rector process src && php-cs-fixer fix -v",
|
||||||
"test:lint": "php-cs-fixer fix -v --dry-run && rector process src --dry-run",
|
"test:lint": "php-cs-fixer fix -v --dry-run && rector process src --dry-run",
|
||||||
"test:types": "phpstan analyse --ansi",
|
"test:types": "phpstan analyse --ansi --memory-limit=0",
|
||||||
"test:unit": "bin/pest --colors=always --exclude-group=integration",
|
"test:unit": "php bin/pest --colors=always --exclude-group=integration",
|
||||||
"test:integration": "bin/pest --colors=always --group=integration",
|
"test:integration": "php bin/pest --colors=always --group=integration",
|
||||||
"test:integration:snapshots": "REBUILD_SNAPSHOTS=true bin/pest --colors=always",
|
"update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always",
|
||||||
"test": [
|
"test": [
|
||||||
"@test:lint",
|
"@test:lint",
|
||||||
"@test:types",
|
"@test:types",
|
||||||
@ -76,6 +80,14 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "0.2.x-dev"
|
||||||
|
},
|
||||||
|
"pest": {
|
||||||
|
"plugins": [
|
||||||
|
"Pest\\Plugins\\Version"
|
||||||
|
]
|
||||||
|
},
|
||||||
"laravel": {
|
"laravel": {
|
||||||
"providers": [
|
"providers": [
|
||||||
"Pest\\Laravel\\PestServiceProvider"
|
"Pest\\Laravel\\PestServiceProvider"
|
||||||
|
|||||||
@ -15,8 +15,9 @@ parameters:
|
|||||||
reportUnmatchedIgnoredErrors: true
|
reportUnmatchedIgnoredErrors: true
|
||||||
|
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
|
- "#Undefined variable: \\$this#"
|
||||||
- "#is not allowed to extend#"
|
- "#is not allowed to extend#"
|
||||||
- "#Language construct eval#"
|
- "#Language construct eval#"
|
||||||
- "# with null as default value#"
|
- "# with null as default value#"
|
||||||
- "#Using \\$this in static method#"
|
|
||||||
- "#has parameter \\$closure with default value.#"
|
- "#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
|
public static function to(array $arguments): array
|
||||||
{
|
{
|
||||||
if (!array_key_exists('printer', $arguments)) {
|
if (!array_key_exists('printer', $arguments)) {
|
||||||
$arguments['printer'] = new Printer();
|
$arguments['printer'] = new Printer(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? 'always');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $arguments;
|
return $arguments;
|
||||||
|
|||||||
@ -19,7 +19,6 @@ final class ValidatesEnvironment
|
|||||||
*/
|
*/
|
||||||
private const NEEDED_FILES = [
|
private const NEEDED_FILES = [
|
||||||
'composer.json',
|
'composer.json',
|
||||||
'tests',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -129,16 +129,25 @@ trait TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the test.
|
* 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) {
|
return ExceptionTrace::ensure(function () use ($closure, $arguments) {
|
||||||
call_user_func_array(Closure::bind($closure, $this, get_class($this)), $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;
|
namespace Pest\Console;
|
||||||
|
|
||||||
use Pest\Actions\AddsCoverage;
|
|
||||||
use Pest\Actions\AddsDefaults;
|
use Pest\Actions\AddsDefaults;
|
||||||
use Pest\Actions\AddsTests;
|
use Pest\Actions\AddsTests;
|
||||||
use Pest\Actions\LoadStructure;
|
use Pest\Actions\LoadStructure;
|
||||||
use Pest\Actions\ValidatesConfiguration;
|
use Pest\Actions\ValidatesConfiguration;
|
||||||
|
use Pest\Contracts\Plugins\AddsOutput;
|
||||||
|
use Pest\Contracts\Plugins\HandlesArguments;
|
||||||
|
use Pest\Plugin\Loader;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use PHPUnit\Framework\TestSuite as BaseTestSuite;
|
use PHPUnit\Framework\TestSuite as BaseTestSuite;
|
||||||
use PHPUnit\TextUI\Command as BaseCommand;
|
use PHPUnit\TextUI\Command as BaseCommand;
|
||||||
@ -54,9 +56,14 @@ final class Command extends BaseCommand
|
|||||||
protected function handleArguments(array $argv): void
|
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.
|
* 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);
|
$this->arguments = AddsDefaults::to($this->arguments);
|
||||||
|
|
||||||
|
LoadStructure::in($this->testSuite->rootPath);
|
||||||
|
|
||||||
$testRunner = new TestRunner($this->arguments['loader']);
|
$testRunner = new TestRunner($this->arguments['loader']);
|
||||||
$testSuite = $this->arguments['test'];
|
$testSuite = $this->arguments['test'];
|
||||||
|
|
||||||
@ -102,7 +111,6 @@ final class Command extends BaseCommand
|
|||||||
$this->arguments['test'] = $testSuite;
|
$this->arguments['test'] = $testSuite;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadStructure::in($this->testSuite->rootPath);
|
|
||||||
AddsTests::to($testSuite, $this->testSuite);
|
AddsTests::to($testSuite, $this->testSuite);
|
||||||
|
|
||||||
return $testRunner;
|
return $testRunner;
|
||||||
@ -119,25 +127,14 @@ final class Command extends BaseCommand
|
|||||||
{
|
{
|
||||||
$result = parent::run($argv, false);
|
$result = parent::run($argv, false);
|
||||||
|
|
||||||
if ($result === 0 && $this->testSuite->coverage) {
|
/*
|
||||||
if (!Coverage::isAvailable()) {
|
* Let's call all plugins that want to add output after test execution
|
||||||
$this->output->writeln(
|
*/
|
||||||
"\n <fg=white;bg=red;options=bold> ERROR </> No code coverage driver is available.</>",
|
$plugins = Loader::getPlugins(AddsOutput::class);
|
||||||
);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$coverage = Coverage::report($this->output);
|
/** @var AddsOutput $plugin */
|
||||||
|
foreach ($plugins as $plugin) {
|
||||||
$result = (int) ($coverage < $this->testSuite->coverageMin);
|
$result = $plugin->addOutput($result);
|
||||||
|
|
||||||
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)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit($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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
66
src/Console/Thanks.php
Normal file
66
src/Console/Thanks.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest\Console;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
|
||||||
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class Thanks
|
||||||
|
{
|
||||||
|
/** @var array<int, string> */
|
||||||
|
private const FUNDING_MESSAGES = [
|
||||||
|
'',
|
||||||
|
' - Star or contribute to Pest:',
|
||||||
|
' <options=bold>https://github.com/pestphp/pest</>',
|
||||||
|
' - Tweet something about Pest on Twitter:',
|
||||||
|
' <options=bold>https://twitter.com/pestphp</>',
|
||||||
|
' - Sponsor the creator:',
|
||||||
|
' <options=bold>https://github.com/sponsors/nunomaduro</>',
|
||||||
|
];
|
||||||
|
|
||||||
|
/** @var OutputInterface */
|
||||||
|
private $output;
|
||||||
|
|
||||||
|
public function __construct(OutputInterface $output)
|
||||||
|
{
|
||||||
|
$this->output = $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asks the user to support Pest.
|
||||||
|
*/
|
||||||
|
public function __invoke(): void
|
||||||
|
{
|
||||||
|
$wantsToSupport = (new SymfonyQuestionHelper())->ask(
|
||||||
|
new ArrayInput([]),
|
||||||
|
$this->output,
|
||||||
|
new ConfirmationQuestion(
|
||||||
|
'Can you quickly <options=bold>star our GitHub repository</>? 🙏🏻',
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($wantsToSupport === true) {
|
||||||
|
if (PHP_OS_FAMILY == 'Darwin') {
|
||||||
|
exec('open https://github.com/pestphp/pest');
|
||||||
|
}
|
||||||
|
if (PHP_OS_FAMILY == 'Windows') {
|
||||||
|
exec('start https://github.com/pestphp/pest');
|
||||||
|
}
|
||||||
|
if (PHP_OS_FAMILY == 'Linux') {
|
||||||
|
exec('xdg-open https://github.com/pestphp/pest');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (self::FUNDING_MESSAGES as $message) {
|
||||||
|
$this->output->writeln($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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);
|
$data = iterator_to_array($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$namedData = [];
|
$dataSetDescriptions = [];
|
||||||
|
$dataSetValues = [];
|
||||||
|
|
||||||
foreach ($data as $values) {
|
foreach ($data as $values) {
|
||||||
$values = is_array($values) ? $values : [$values];
|
$values = is_array($values) ? $values : [$values];
|
||||||
|
|
||||||
$name = $description . self::getDataSetDescription($values);
|
$dataSetDescriptions[] = $description . self::getDataSetDescription($values);
|
||||||
$namedData[$name] = $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;
|
return $namedData;
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use Closure;
|
|||||||
use Pest\Concerns;
|
use Pest\Concerns;
|
||||||
use Pest\Contracts\HasPrintableTestCaseName;
|
use Pest\Contracts\HasPrintableTestCaseName;
|
||||||
use Pest\Datasets;
|
use Pest\Datasets;
|
||||||
|
use Pest\Exceptions\ShouldNotHappen;
|
||||||
use Pest\Support\HigherOrderMessageCollection;
|
use Pest\Support\HigherOrderMessageCollection;
|
||||||
use Pest\Support\NullClosure;
|
use Pest\Support\NullClosure;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
@ -39,9 +40,10 @@ final class TestCaseFactory
|
|||||||
/**
|
/**
|
||||||
* Holds the test description.
|
* 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;
|
public $description;
|
||||||
|
|
||||||
@ -104,7 +106,7 @@ final class TestCaseFactory
|
|||||||
/**
|
/**
|
||||||
* Creates a new anonymous test case pending object.
|
* 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->filename = $filename;
|
||||||
$this->description = $description;
|
$this->description = $description;
|
||||||
@ -122,14 +124,22 @@ final class TestCaseFactory
|
|||||||
*/
|
*/
|
||||||
public function build(TestSuite $testSuite): array
|
public function build(TestSuite $testSuite): array
|
||||||
{
|
{
|
||||||
|
if ($this->description === null) {
|
||||||
|
throw ShouldNotHappen::fromMessage('Description can not be empty.');
|
||||||
|
}
|
||||||
|
|
||||||
$chains = $this->chains;
|
$chains = $this->chains;
|
||||||
$proxies = $this->proxies;
|
$proxies = $this->proxies;
|
||||||
$factoryTest = $this->test;
|
$factoryTest = $this->test;
|
||||||
|
|
||||||
$test = function () use ($chains, $proxies, $factoryTest): void {
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
$test = function () use ($chains, $proxies, $factoryTest) {
|
||||||
$proxies->proxy($this);
|
$proxies->proxy($this);
|
||||||
$chains->chain($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);
|
$className = $this->makeClassFromFilename($this->filename);
|
||||||
@ -152,16 +162,25 @@ final class TestCaseFactory
|
|||||||
*/
|
*/
|
||||||
public function makeClassFromFilename(string $filename): string
|
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;
|
$rootPath = TestSuite::getInstance()->rootPath;
|
||||||
$relativePath = str_replace($rootPath . DIRECTORY_SEPARATOR, '', $filename);
|
$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.
|
// Strip out any %-encoded octets.
|
||||||
$relativePath = (string) preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $relativePath);
|
$relativePath = (string) preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $relativePath);
|
||||||
|
|
||||||
// Limit to A-Z, a-z, 0-9, '_', '-'.
|
// Limit to A-Z, a-z, 0-9, '_', '-'.
|
||||||
$relativePath = (string) preg_replace('/[^A-Za-z0-9.\/]/', '', $relativePath);
|
$relativePath = (string) preg_replace('/[^A-Za-z0-9.\\\]/', '', $relativePath);
|
||||||
|
|
||||||
$classFQN = 'P\\' . basename(ucfirst(str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath)), '.php');
|
|
||||||
|
|
||||||
|
$classFQN = 'P\\' . $relativePath;
|
||||||
if (class_exists($classFQN)) {
|
if (class_exists($classFQN)) {
|
||||||
return $classFQN;
|
return $classFQN;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ namespace Pest\Laravel\Commands;
|
|||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Pest\Exceptions\InvalidConsoleArgument;
|
use Pest\Exceptions\InvalidConsoleArgument;
|
||||||
|
use Pest\Support\Str;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -36,6 +37,7 @@ final class PestInstallCommand extends Command
|
|||||||
$pest = base_path('tests/Pest.php');
|
$pest = base_path('tests/Pest.php');
|
||||||
/* @phpstan-ignore-next-line */
|
/* @phpstan-ignore-next-line */
|
||||||
$helpers = base_path('tests/Helpers.php');
|
$helpers = base_path('tests/Helpers.php');
|
||||||
|
$stubs = $this->isLumen() ? 'stubs/Lumen' : 'stubs/Laravel';
|
||||||
|
|
||||||
foreach ([$pest, $helpers] as $file) {
|
foreach ([$pest, $helpers] as $file) {
|
||||||
if (File::exists($file)) {
|
if (File::exists($file)) {
|
||||||
@ -45,17 +47,28 @@ final class PestInstallCommand extends Command
|
|||||||
|
|
||||||
File::copy(implode(DIRECTORY_SEPARATOR, [
|
File::copy(implode(DIRECTORY_SEPARATOR, [
|
||||||
dirname(__DIR__, 3),
|
dirname(__DIR__, 3),
|
||||||
'stubs',
|
$stubs,
|
||||||
'Pest.php',
|
'Pest.php',
|
||||||
]), $pest);
|
]), $pest);
|
||||||
|
|
||||||
File::copy(implode(DIRECTORY_SEPARATOR, [
|
File::copy(implode(DIRECTORY_SEPARATOR, [
|
||||||
dirname(__DIR__, 3),
|
dirname(__DIR__, 3),
|
||||||
'stubs',
|
$stubs,
|
||||||
'Helpers.php',
|
'Helpers.php',
|
||||||
]), $helpers);
|
]), $helpers);
|
||||||
|
|
||||||
$this->output->success('`tests/Pest.php` created successfully.');
|
$this->output->success('`tests/Pest.php` created successfully.');
|
||||||
$this->output->success('`tests/Helpers.php` created successfully.');
|
$this->output->success('`tests/Helpers.php` created successfully.');
|
||||||
|
|
||||||
|
(new \Pest\Console\Thanks($this->output))();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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\Backtrace;
|
||||||
use Pest\Support\NullClosure;
|
use Pest\Support\NullClosure;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
|
use SebastianBergmann\Exporter\Exporter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class TestCall
|
final class TestCall
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Holds the test suite.
|
||||||
|
*
|
||||||
|
* @readonly
|
||||||
|
*
|
||||||
|
* @var TestSuite
|
||||||
|
*/
|
||||||
|
private $testSuite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the test case factory.
|
* Holds the test case factory.
|
||||||
*
|
*
|
||||||
@ -24,14 +34,23 @@ final class TestCall
|
|||||||
*/
|
*/
|
||||||
private $testCaseFactory;
|
private $testCaseFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If test call is descriptionLess.
|
||||||
|
*
|
||||||
|
* @readonly
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $descriptionLess = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of a pending test call.
|
* 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);
|
$this->testCaseFactory = new TestCaseFactory($filename, $description, $closure);
|
||||||
|
$this->testSuite = $testSuite;
|
||||||
$testSuite->tests->set($this->testCaseFactory);
|
$this->descriptionLess = $description === null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,13 +59,13 @@ final class TestCall
|
|||||||
public function throws(string $exceptionClass, string $exceptionMessage = null): TestCall
|
public function throws(string $exceptionClass, string $exceptionMessage = null): TestCall
|
||||||
{
|
{
|
||||||
$this->testCaseFactory
|
$this->testCaseFactory
|
||||||
->proxies
|
->proxies
|
||||||
->add(Backtrace::file(), Backtrace::line(), 'expectException', [$exceptionClass]);
|
->add(Backtrace::file(), Backtrace::line(), 'expectException', [$exceptionClass]);
|
||||||
|
|
||||||
if (is_string($exceptionMessage)) {
|
if (is_string($exceptionMessage)) {
|
||||||
$this->testCaseFactory
|
$this->testCaseFactory
|
||||||
->proxies
|
->proxies
|
||||||
->add(Backtrace::file(), Backtrace::line(), 'expectExceptionMessage', [$exceptionMessage]);
|
->add(Backtrace::file(), Backtrace::line(), 'expectExceptionMessage', [$exceptionMessage]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -65,6 +84,18 @@ final class TestCall
|
|||||||
return $this;
|
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.
|
* 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
|
public function group(string ...$groups): TestCall
|
||||||
{
|
{
|
||||||
$this->testCaseFactory
|
$this->testCaseFactory
|
||||||
->factoryProxies
|
->factoryProxies
|
||||||
->add(Backtrace::file(), Backtrace::line(), 'addGroups', [$groups]);
|
->add(Backtrace::file(), Backtrace::line(), 'addGroups', [$groups]);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -110,8 +141,8 @@ final class TestCall
|
|||||||
|
|
||||||
if ($condition() !== false) {
|
if ($condition() !== false) {
|
||||||
$this->testCaseFactory
|
$this->testCaseFactory
|
||||||
->chains
|
->chains
|
||||||
->add(Backtrace::file(), Backtrace::line(), 'markTestSkipped', [$message]);
|
->add(Backtrace::file(), Backtrace::line(), 'markTestSkipped', [$message]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -125,9 +156,26 @@ final class TestCall
|
|||||||
public function __call(string $name, array $arguments): self
|
public function __call(string $name, array $arguments): self
|
||||||
{
|
{
|
||||||
$this->testCaseFactory
|
$this->testCaseFactory
|
||||||
->chains
|
->chains
|
||||||
->add(Backtrace::file(), Backtrace::line(), $name, $arguments);
|
->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;
|
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
|
public function in(string ...$targets): void
|
||||||
{
|
{
|
||||||
$targets = array_map(function ($path): string {
|
$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
|
? $path
|
||||||
: implode(DIRECTORY_SEPARATOR, [
|
: implode(DIRECTORY_SEPARATOR, [
|
||||||
dirname($this->filename),
|
dirname($this->filename),
|
||||||
@ -68,12 +78,12 @@ final class UsesCall
|
|||||||
}, $targets);
|
}, $targets);
|
||||||
|
|
||||||
$this->targets = array_map(function ($target): string {
|
$this->targets = array_map(function ($target): string {
|
||||||
$realTarget = realpath($target);
|
$isValid = is_dir($target) || file_exists($target);
|
||||||
if ($realTarget === false) {
|
if (!$isValid) {
|
||||||
throw new InvalidUsesPath($target);
|
throw new InvalidUsesPath($target);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $realTarget;
|
return (string) realpath($target);
|
||||||
}, $targets);
|
}, $targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
src/Pest.php
Normal file
10
src/Pest.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest;
|
||||||
|
|
||||||
|
function version(): string
|
||||||
|
{
|
||||||
|
return '0.2.2';
|
||||||
|
}
|
||||||
39
src/Plugins/Version.php
Normal file
39
src/Plugins/Version.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest\Plugins;
|
||||||
|
|
||||||
|
use Pest\Contracts\Plugins\HandlesArguments;
|
||||||
|
use function Pest\version;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class Version implements HandlesArguments
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OutputInterface
|
||||||
|
*/
|
||||||
|
private $output;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of the plugin.
|
||||||
|
*/
|
||||||
|
public function __construct(OutputInterface $output)
|
||||||
|
{
|
||||||
|
$this->output = $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handleArguments(array $arguments): array
|
||||||
|
{
|
||||||
|
if (in_array('--version', $arguments, true)) {
|
||||||
|
$this->output->writeln(
|
||||||
|
sprintf('Pest %s', version()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $arguments;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -41,6 +41,12 @@ final class AfterEachRepository
|
|||||||
|
|
||||||
return ChainableClosure::from(function (): void {
|
return ChainableClosure::from(function (): void {
|
||||||
if (class_exists(Mockery::class)) {
|
if (class_exists(Mockery::class)) {
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
|
if ($container = Mockery::getContainer()) {
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
|
$this->addToAssertionCount($container->mockery_getExpectationCount());
|
||||||
|
}
|
||||||
|
|
||||||
Mockery::close();
|
Mockery::close();
|
||||||
}
|
}
|
||||||
}, $afterEach);
|
}, $afterEach);
|
||||||
|
|||||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Repositories;
|
namespace Pest\Repositories;
|
||||||
|
|
||||||
|
use Pest\Exceptions\ShouldNotHappen;
|
||||||
use Pest\Exceptions\TestAlreadyExist;
|
use Pest\Exceptions\TestAlreadyExist;
|
||||||
use Pest\Exceptions\TestCaseAlreadyInUse;
|
use Pest\Exceptions\TestCaseAlreadyInUse;
|
||||||
use Pest\Exceptions\TestCaseClassOrTraitNotFound;
|
use Pest\Exceptions\TestCaseClassOrTraitNotFound;
|
||||||
@ -54,7 +55,6 @@ final class TestRepository
|
|||||||
if ($testCase->class !== \PHPUnit\Framework\TestCase::class) {
|
if ($testCase->class !== \PHPUnit\Framework\TestCase::class) {
|
||||||
throw new TestCaseAlreadyInUse($testCase->class, $class, $filename);
|
throw new TestCaseAlreadyInUse($testCase->class, $class, $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
$testCase->class = $class;
|
$testCase->class = $class;
|
||||||
} elseif (trait_exists($class)) {
|
} elseif (trait_exists($class)) {
|
||||||
$testCase->traits[] = $class;
|
$testCase->traits[] = $class;
|
||||||
@ -62,9 +62,9 @@ final class TestRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
$testCase
|
$testCase
|
||||||
->factoryProxies
|
->factoryProxies
|
||||||
// Consider set the real line here.
|
// Consider set the real line here.
|
||||||
->add($filename, 0, 'addGroups', [$groups]);
|
->add($filename, 0, 'addGroups', [$groups]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -104,7 +104,14 @@ final class TestRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($paths as $path) {
|
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
|
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)) {
|
if (array_key_exists(sprintf('%s@%s', $test->filename, $test->description), $this->state)) {
|
||||||
throw new TestAlreadyExist($test->filename, $test->description);
|
throw new TestAlreadyExist($test->filename, $test->description);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,17 +4,48 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Support;
|
namespace Pest\Support;
|
||||||
|
|
||||||
|
use Pest\Exceptions\ShouldNotHappen;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class Backtrace
|
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.
|
* Returns the filename that called the current function/method.
|
||||||
*/
|
*/
|
||||||
public static function file(): string
|
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
|
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
|
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
|
* Ensures the given closure reports
|
||||||
* the good execution context.
|
* the good execution context.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*
|
||||||
|
* @throws \Throwable
|
||||||
*/
|
*/
|
||||||
public static function ensure(Closure $closure): void
|
public static function ensure(Closure $closure)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$closure();
|
return $closure();
|
||||||
} catch (Throwable $throwable) {
|
} catch (Throwable $throwable) {
|
||||||
if (Str::startsWith($message = $throwable->getMessage(), self::UNDEFINED_METHOD)) {
|
if (Str::startsWith($message = $throwable->getMessage(), self::UNDEFINED_METHOD)) {
|
||||||
$message = str_replace(self::UNDEFINED_METHOD, 'Call to undefined method ', $message);
|
$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)) {
|
if ($throwable->getMessage() === sprintf(self::UNDEFINED_METHOD, $this->methodName)) {
|
||||||
/** @var \ReflectionClass $reflection */
|
/** @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));
|
Reflection::setPropertyValue($throwable, 'message', sprintf('Call to undefined method %s::%s()', $reflection->getName(), $this->methodName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,11 +27,19 @@ final class Reflection
|
|||||||
{
|
{
|
||||||
$reflectionClass = new ReflectionClass($object);
|
$reflectionClass = new ReflectionClass($object);
|
||||||
|
|
||||||
$reflectionMethod = $reflectionClass->getMethod($method);
|
try {
|
||||||
|
$reflectionMethod = $reflectionClass->getMethod($method);
|
||||||
|
|
||||||
$reflectionMethod->setAccessible(true);
|
$reflectionMethod->setAccessible(true);
|
||||||
|
|
||||||
return $reflectionMethod->invoke($object, ...$args);
|
return $reflectionMethod->invoke($object, ...$args);
|
||||||
|
} catch (ReflectionException $exception) {
|
||||||
|
if (method_exists($object, '__call')) {
|
||||||
|
return $object->__call($method, $args);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw $exception;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -30,20 +30,6 @@ final class TestSuite
|
|||||||
*/
|
*/
|
||||||
public $tests;
|
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.
|
* Holds the before each repository.
|
||||||
*
|
*
|
||||||
@ -97,7 +83,7 @@ final class TestSuite
|
|||||||
$this->afterEach = new AfterEachRepository();
|
$this->afterEach = new AfterEachRepository();
|
||||||
$this->afterAll = new AfterAllRepository();
|
$this->afterAll = new AfterAllRepository();
|
||||||
|
|
||||||
$this->rootPath = $rootPath;
|
$this->rootPath = (string) realpath($rootPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -13,7 +13,7 @@ use Pest\TestSuite;
|
|||||||
use PHPUnit\Framework\TestCase;
|
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
|
function beforeAll(Closure $closure): void
|
||||||
{
|
{
|
||||||
@ -66,7 +66,7 @@ function test(string $description = null, Closure $closure = null)
|
|||||||
return new HigherOrderTapProxy(TestSuite::getInstance()->test);
|
return new HigherOrderTapProxy(TestSuite::getInstance()->test);
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = Backtrace::file();
|
$filename = Backtrace::testFile();
|
||||||
|
|
||||||
return new TestCall(TestSuite::getInstance(), $filename, $description, $closure);
|
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
|
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
|
✓ that gets executed
|
||||||
|
|
||||||
PASS Tests\Features\AfterAll
|
PASS Tests\Features\AfterAll
|
||||||
@ -24,7 +24,7 @@
|
|||||||
✓ it sets arrays
|
✓ it sets arrays
|
||||||
✓ it gets bound to test case object with ('a')
|
✓ it gets bound to test case object with ('a')
|
||||||
✓ it gets bound to test case object with ('b')
|
✓ 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 (1)
|
||||||
✓ lazy datasets with (2)
|
✓ lazy datasets with (2)
|
||||||
✓ lazy datasets did the job right
|
✓ lazy datasets did the job right
|
||||||
@ -40,10 +40,25 @@
|
|||||||
✓ eager wrapped registered datasets with (1)
|
✓ eager wrapped registered datasets with (1)
|
||||||
✓ eager wrapped registered datasets with (2)
|
✓ eager wrapped registered datasets with (2)
|
||||||
✓ eager registered wrapped datasets did the job right
|
✓ 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
|
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
|
||||||
✓ it catch exceptions and messages
|
✓ it catch exceptions and messages
|
||||||
|
|
||||||
@ -53,40 +68,48 @@
|
|||||||
✓ it allows to call underlying protected/private methods
|
✓ it allows to call underlying protected/private methods
|
||||||
✓ it throws error if method do not exist
|
✓ it throws error if method do not exist
|
||||||
|
|
||||||
PASS Tests\Features\HigherOrderMessages
|
PASS Tests\Features\HigherOrderTests
|
||||||
✓ it proxies calls to object
|
✓ it proxies calls to object
|
||||||
|
|
||||||
PASS Tests\Features\It
|
PASS Tests\Features\It
|
||||||
✓ it is a test
|
✓ it is a test
|
||||||
✓ it is a higher order message test
|
✓ it is a higher order message test
|
||||||
|
|
||||||
|
PASS Tests\Features\Macro
|
||||||
|
✓ it can call chained macro method
|
||||||
|
✓ it will throw exception from call if no macro exists
|
||||||
|
|
||||||
PASS Tests\Features\Mocks
|
PASS Tests\Features\Mocks
|
||||||
✓ it has bar
|
✓ it has bar
|
||||||
|
|
||||||
|
PASS Tests\Features\PendingHigherOrderTests
|
||||||
|
✓ get 'foo' → get 'bar' → assertTrue true
|
||||||
|
✓ get 'foo' → assertTrue true
|
||||||
|
|
||||||
WARN Tests\Features\Skip
|
WARN Tests\Features\Skip
|
||||||
✓ it do not skips
|
✓ it do not skips
|
||||||
s it skips with truthy
|
- it skips with truthy
|
||||||
s it skips with truthy condition by default
|
- it skips with truthy condition by default
|
||||||
s it skips with message → skipped because bar
|
- it skips with message → skipped because bar
|
||||||
s it skips with truthy closure condition
|
- it skips with truthy closure condition
|
||||||
✓ it do not skips with falsy closure condition
|
✓ it do not skips with falsy closure condition
|
||||||
s it skips with condition and messsage → skipped because foo
|
- it skips with condition and message → skipped because foo
|
||||||
|
|
||||||
PASS Tests\Features\Test
|
PASS Tests\Features\Test
|
||||||
✓ a test
|
✓ a test
|
||||||
✓ higher order message test
|
✓ higher order message test
|
||||||
|
|
||||||
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
||||||
✓ it example
|
✓ it example 1
|
||||||
|
|
||||||
PASS Tests\Fixtures\ExampleTest
|
PASS Tests\Fixtures\ExampleTest
|
||||||
✓ it example
|
✓ it example 2
|
||||||
|
|
||||||
PASS Tests\PHPUnit\CustomTestCase\UsesPerDirectory
|
PASS Tests\PHPUnit\CustomTestCase\UsesPerDirectory
|
||||||
✓ closure was bound to custom test case
|
✓ closure was bound to CustomTestCase
|
||||||
|
|
||||||
PASS Tests\PHPUnit\CustomTestCaseInSubFolders\SubFolder\SubFolder\UsesPerSubDirectory
|
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
|
PASS Tests\PHPUnit\CustomTestCaseInSubFolders\SubFolder2\UsesPerFile
|
||||||
✓ custom traits can be used
|
✓ custom traits can be used
|
||||||
@ -97,10 +120,7 @@
|
|||||||
|
|
||||||
PASS Tests\Plugins\Traits
|
PASS Tests\Plugins\Traits
|
||||||
✓ it allows global uses
|
✓ it allows global uses
|
||||||
|
✓ it allows multiple global uses registered in the same path
|
||||||
PASS Tests\Unit\Actions\AddsCoverage
|
|
||||||
✓ it adds coverage if --coverage exist
|
|
||||||
✓ it adds coverage if --min exist
|
|
||||||
|
|
||||||
PASS Tests\Unit\Actions\AddsDefaults
|
PASS Tests\Unit\Actions\AddsDefaults
|
||||||
✓ it sets defaults
|
✓ it sets defaults
|
||||||
@ -115,12 +135,22 @@
|
|||||||
✓ it throws exception when `process isolation` is true
|
✓ it throws exception when `process isolation` is true
|
||||||
✓ it do not throws exception when `process isolation` is false
|
✓ it do not throws exception when `process isolation` is false
|
||||||
|
|
||||||
PASS Tests\Unit\Console\Coverage
|
PASS Tests\Unit\Plugins\Version
|
||||||
✓ it generates coverage based on file input
|
✓ it outputs the version when --version is used
|
||||||
|
✓ it do not outputs version when --version is not used
|
||||||
|
|
||||||
PASS Tests\Unit\Support\Backtrace
|
PASS Tests\Unit\Support\Backtrace
|
||||||
✓ it gets file name from called file
|
✓ 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
|
PASS Tests\Unit\Support\Reflection
|
||||||
✓ it gets file name from closure
|
✓ it gets file name from closure
|
||||||
✓ it gets property values
|
✓ it gets property values
|
||||||
@ -131,9 +161,11 @@
|
|||||||
PASS Tests\Visual\SingleTestOrDirectory
|
PASS Tests\Visual\SingleTestOrDirectory
|
||||||
✓ allows to run a single test
|
✓ allows to run a single test
|
||||||
✓ allows to run a directory
|
✓ allows to run a directory
|
||||||
|
✓ it has ascii chars
|
||||||
|
✓ it disable decorating printer when colors is set to never
|
||||||
|
|
||||||
WARN Tests\Visual\Success
|
WARN Tests\Visual\Success
|
||||||
s visual snapshot of test suite on success
|
- visual snapshot of test suite on success
|
||||||
|
|
||||||
Tests: 6 skipped, 70 passed
|
Tests: 6 skipped, 96 passed
|
||||||
Time: 2.68s
|
Time: 3.43s
|
||||||
|
|||||||
@ -12,4 +12,13 @@ trait PluginTrait
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait SecondPluginTrait
|
||||||
|
{
|
||||||
|
public function assertSecondPluginTraitGotRegistered(): void
|
||||||
|
{
|
||||||
|
assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Pest\Plugin::uses(PluginTrait::class);
|
Pest\Plugin::uses(PluginTrait::class);
|
||||||
|
Pest\Plugin::uses(SecondPluginTrait::class);
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
use Pest\Datasets;
|
use Pest\Datasets;
|
||||||
use Pest\Exceptions\DatasetAlreadyExist;
|
use Pest\Exceptions\DatasetAlreadyExist;
|
||||||
use Pest\Exceptions\DatasetDoesNotExist;
|
use Pest\Exceptions\DatasetDoesNotExist;
|
||||||
|
use Pest\Plugin;
|
||||||
|
|
||||||
it('throws exception if dataset does not exist', function () {
|
it('throws exception if dataset does not exist', function () {
|
||||||
$this->expectException(DatasetDoesNotExist::class);
|
$this->expectException(DatasetDoesNotExist::class);
|
||||||
@ -106,3 +107,21 @@ $namedDatasets = [
|
|||||||
test('lazy named datasets', function ($text) use ($state, $datasets) {
|
test('lazy named datasets', function ($text) use ($state, $datasets) {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
})->with($namedDatasets);
|
})->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');
|
||||||
16
tests/Features/Macro.php
Normal file
16
tests/Features/Macro.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Traits\Macroable;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
uses(Macroable::class);
|
||||||
|
|
||||||
|
beforeEach()->macro('bar', function () {
|
||||||
|
assertInstanceOf(TestCase::class, $this);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can call chained macro method')->bar();
|
||||||
|
|
||||||
|
it('will throw exception from call if no macro exists')
|
||||||
|
->throws(BadMethodCallException::class)
|
||||||
|
->foo();
|
||||||
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use function Tests\mock;
|
||||||
|
|
||||||
interface Foo
|
interface Foo
|
||||||
{
|
{
|
||||||
public function bar(): int;
|
public function bar(): int;
|
||||||
@ -11,5 +13,5 @@ it('has bar', function () {
|
|||||||
->times(1)
|
->times(1)
|
||||||
->andReturn(2);
|
->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; })
|
->skip(function () { return false; })
|
||||||
->assertTrue(true);
|
->assertTrue(true);
|
||||||
|
|
||||||
it('skips with condition and messsage')
|
it('skips with condition and message')
|
||||||
->skip(true, 'skipped because foo')
|
->skip(true, 'skipped because foo')
|
||||||
->assertTrue(false);
|
->assertTrue(false);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
it('example')->assertTrue(true);
|
it('example 1')->assertTrue(true);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
it('example')->assertTrue(true);
|
it('example 2')->assertTrue(true);
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace Tests;
|
||||||
|
|
||||||
|
use Mockery;
|
||||||
use Mockery\MockInterface;
|
use Mockery\MockInterface;
|
||||||
|
|
||||||
function mock(string $class): MockInterface
|
function mock(string $class): MockInterface
|
||||||
|
|||||||
@ -7,7 +7,7 @@ namespace Tests\CustomTestCase;
|
|||||||
use function PHPUnit\Framework\assertTrue;
|
use function PHPUnit\Framework\assertTrue;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class PhpunitTest extends TestCase
|
class ExecutedTest extends TestCase
|
||||||
{
|
{
|
||||||
public static $executed = false;
|
public static $executed = false;
|
||||||
|
|
||||||
@ -16,8 +16,8 @@ class PhpunitTest extends TestCase
|
|||||||
{
|
{
|
||||||
self::$executed = true;
|
self::$executed = true;
|
||||||
|
|
||||||
$this->assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// register_shutdown_function(fn () => assertTrue(PhpunitTest::$executed));
|
// register_shutdown_function(fn () => assertTrue(ExecutedTest::$executed));
|
||||||
@ -1,3 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
it('allows global uses')->assertPluginTraitGotRegistered();
|
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 => [],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
20
tests/Unit/Plugins/Version.php
Normal file
20
tests/Unit/Plugins/Version.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Pest\Plugins\Version;
|
||||||
|
use Symfony\Component\Console\Output\BufferedOutput;
|
||||||
|
|
||||||
|
it('outputs the version when --version is used', function () {
|
||||||
|
$output = new BufferedOutput();
|
||||||
|
$plugin = new Version($output);
|
||||||
|
|
||||||
|
$plugin->handleArguments(['foo', '--version']);
|
||||||
|
assertStringContainsString('Pest 0.2.2', $output->fetch());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('do not outputs version when --version is not used', function () {
|
||||||
|
$output = new BufferedOutput();
|
||||||
|
$plugin = new Version($output);
|
||||||
|
|
||||||
|
$plugin->handleArguments(['foo', 'bar']);
|
||||||
|
assertEquals('', $output->fetch());
|
||||||
|
});
|
||||||
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;
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
$run = function (string $target) {
|
$run = function (string $target, $decorated = false) {
|
||||||
$process = new Process(['./bin/pest', $target], dirname(__DIR__, 2));
|
$process = new Process(['php', 'bin/pest', $target], dirname(__DIR__, 2));
|
||||||
|
|
||||||
$process->run();
|
$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) {
|
$snapshot = function ($name) {
|
||||||
assertStringContainsString(<<<EOF
|
$testsPath = dirname(__DIR__);
|
||||||
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
|
||||||
✓ it example
|
|
||||||
|
|
||||||
Tests: 1 passed
|
return file_get_contents(implode(DIRECTORY_SEPARATOR, [
|
||||||
EOF, $run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'));
|
$testsPath,
|
||||||
});
|
'.snapshots',
|
||||||
|
"$name.txt",
|
||||||
|
]));
|
||||||
|
};
|
||||||
|
|
||||||
test('allows to run a directory', function () use ($run) {
|
test('allows to run a single test', function () use ($run, $snapshot) {
|
||||||
assertStringContainsString(<<<EOF
|
assertStringContainsString(
|
||||||
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
$snapshot('allows-to-run-a-single-test'),
|
||||||
✓ it example
|
$run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'));
|
||||||
|
})->skip(PHP_OS_FAMILY === 'Windows');
|
||||||
|
|
||||||
PASS Tests\Fixtures\ExampleTest
|
test('allows to run a directory', function () use ($run, $snapshot) {
|
||||||
✓ it example
|
assertStringContainsString(
|
||||||
|
$snapshot('allows-to-run-a-directory'),
|
||||||
|
$run('tests/Fixtures')
|
||||||
|
);
|
||||||
|
})->skip(PHP_OS_FAMILY === 'Windows');
|
||||||
|
|
||||||
Tests: 2 passed
|
it('has ascii chars', function () use ($run, $snapshot) {
|
||||||
EOF, $run('tests/Fixtures'));
|
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) {
|
$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();
|
$process->run();
|
||||||
|
|
||||||
@ -24,4 +24,5 @@ test('visual snapshot of test suite on success', function () {
|
|||||||
array_pop($output);
|
array_pop($output);
|
||||||
assertStringContainsString(implode("\n", $output), file_get_contents($snapshot));
|
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