mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
Compare commits
187 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3205b571b0 | |||
| 2c4aef5272 | |||
| 4a45a7cc6b | |||
| ea8ab88056 | |||
| 564a21badd | |||
| 41ce87450f | |||
| fb0eef4200 | |||
| 819da37b89 | |||
| 8eb9c408a9 | |||
| 1f10b46402 | |||
| 7bb12b73e8 | |||
| b8103697c9 | |||
| ca3f8b5702 | |||
| daa01ea44b | |||
| 26d577f9c5 | |||
| 43fb711251 | |||
| 567af55a19 | |||
| c6a2e3b4d0 | |||
| a10428efe6 | |||
| 1440637e41 | |||
| 14cee66dfd | |||
| d048d60d04 | |||
| 1b9162151c | |||
| 885c9f1f06 | |||
| 90efcc8a8a | |||
| 7d35ee9998 | |||
| 584a7ac8a5 | |||
| f21e45ae64 | |||
| c7d26a27b6 | |||
| 54f9397f47 | |||
| ff44589572 | |||
| 53333b56ab | |||
| 6616b6299b | |||
| 0bab649156 | |||
| 2de7cb4726 | |||
| 99500d0cae | |||
| 7eb5478c42 | |||
| d2babb1331 | |||
| a6cced6b63 | |||
| 7917313422 | |||
| e02c22e136 | |||
| 2157644a39 | |||
| b6c2812a91 | |||
| 4b65d2c426 | |||
| 3589f3d5e7 | |||
| 1f39b8d239 | |||
| 7c3c390cbf | |||
| 19a1569fa8 | |||
| 9a0240bc7b | |||
| dd94a843b5 | |||
| 9426d08aa2 | |||
| fe2fac37f8 | |||
| cabd64df00 | |||
| bb57a54089 | |||
| 5e0bfba7bf | |||
| f6c19e469f | |||
| 13f09cc662 | |||
| a7e2856887 | |||
| 721e047485 | |||
| 301ff155a4 | |||
| 40f2065575 | |||
| be906eb823 | |||
| 2cee825f61 | |||
| ea6308bfdf | |||
| c6a6f7e2ab | |||
| 20077c285a | |||
| fa13016785 | |||
| b81bb9d621 | |||
| 2deb53c14f | |||
| 6b8feed08a | |||
| 2fe8e07cf3 | |||
| d2c907868e | |||
| a2900a5e09 | |||
| df934bacd9 | |||
| b0f03c278d | |||
| b59b321249 | |||
| 82d6991cf8 | |||
| d693d99379 | |||
| 50c1136be8 | |||
| dd491e516c | |||
| 078aab0d3d | |||
| 89c9f4b428 | |||
| 2148e896e2 | |||
| 7ba49b2e3e | |||
| 54a285f7e3 | |||
| 3ed20d059c | |||
| 92b6800f28 | |||
| 29cfd1a2dc | |||
| 45c09ea0ed | |||
| 424e24d530 | |||
| 26b2e3561a | |||
| 60aea6798d | |||
| fac3fe3f55 | |||
| 17fac0a488 | |||
| 6abc2207b2 | |||
| 885d224c5d | |||
| 12441deab8 | |||
| 8852fd14ce | |||
| e3814e6d9c | |||
| e19eba0942 | |||
| b6e2763731 | |||
| f75a3ee865 | |||
| d707c2f208 | |||
| a43b86d9eb | |||
| 5279d5e913 | |||
| df7fb92e03 | |||
| 95c3418313 | |||
| 67a8be9347 | |||
| 5d7f262f4a | |||
| 23eebc8127 | |||
| 3b435e460e | |||
| b52e9826e7 | |||
| ba49dd0499 | |||
| f9f6f28950 | |||
| f017015d1e | |||
| 29b4ee33bb | |||
| 03dc11c2f6 | |||
| b79ba5098b | |||
| 3c418d82e6 | |||
| 73ede2e344 | |||
| 266d891488 | |||
| c71490b472 | |||
| 07705079e2 | |||
| d88c268426 | |||
| a1b142e885 | |||
| a50d739e50 | |||
| f82bb56d89 | |||
| de593c3b93 | |||
| eedd5d80a0 | |||
| 5bbdd4f41e | |||
| 3fd24d96d3 | |||
| 7bea51fe09 | |||
| cdf0a38145 | |||
| bb2474ccbe | |||
| 01143a6f84 | |||
| b93485c2ed | |||
| 04681690b6 | |||
| 200877d691 | |||
| feb6417f45 | |||
| e7585a4ba2 | |||
| c33ab0f670 | |||
| 78181f66f6 | |||
| 925636be61 | |||
| 6be131d602 | |||
| f950f57eed | |||
| c6369feaea | |||
| 1bdd3f4908 | |||
| 924e095dfc | |||
| 72041a4a21 | |||
| d576446639 | |||
| 3fbec70ed3 | |||
| d177ab5ec2 | |||
| ba08f2c11e | |||
| 13a8aee049 | |||
| e4f5a284a6 | |||
| 6671b266da | |||
| 3728bd8e0f | |||
| c3616edbc8 | |||
| 21143b2693 | |||
| 006f9232cc | |||
| d1b61a34de | |||
| 896317ac97 | |||
| 4fd5c0edd4 | |||
| e2c5d6d857 | |||
| 8057fe4bc2 | |||
| ebc9690301 | |||
| 049ce1845e | |||
| faa6cd7deb | |||
| 1f9362c4e7 | |||
| 36fd18bcc8 | |||
| aa352317cb | |||
| edcd2cb50e | |||
| be8a64e4b8 | |||
| 2336bc0f65 | |||
| da82eecbae | |||
| 4855987ba8 | |||
| a493db1873 | |||
| 4f677a6cc2 | |||
| 228f2deb64 | |||
| 0fadf9a02c | |||
| 2b138ad76b | |||
| e3e4815b55 | |||
| f76f353c32 | |||
| 16b9f54dc3 | |||
| 281166475e | |||
| 23805cb5d6 | |||
| 76d0f9cfc1 |
30
.gitattributes
vendored
30
.gitattributes
vendored
@ -1,16 +1,14 @@
|
|||||||
/art export-ignore
|
/art export-ignore
|
||||||
/docs export-ignore
|
/docs export-ignore
|
||||||
/tests export-ignore
|
/tests export-ignore
|
||||||
/scripts export-ignore
|
/scripts export-ignore
|
||||||
/.github export-ignore
|
/.github export-ignore
|
||||||
/.php_cs export-ignore
|
/.php-cs-fixer.dist.php export-ignore
|
||||||
.editorconfig export-ignore
|
.editorconfig export-ignore
|
||||||
.gitattributes export-ignore
|
.gitattributes export-ignore
|
||||||
.gitignore export-ignore
|
.gitignore export-ignore
|
||||||
.travis.yml export-ignore
|
phpstan.neon export-ignore
|
||||||
phpstan.neon export-ignore
|
phpunit.xml export-ignore
|
||||||
rector.yaml export-ignore
|
CHANGELOG.md export-ignore
|
||||||
phpunit.xml export-ignore
|
CONTRIBUTING.md export-ignore
|
||||||
CHANGELOG.md export-ignore
|
README.md export-ignore
|
||||||
CONTRIBUTING.md export-ignore
|
|
||||||
README.md export-ignore
|
|
||||||
|
|||||||
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@ -1,5 +1,5 @@
|
|||||||
# These are supported funding model platforms
|
# These are supported funding model platforms
|
||||||
|
|
||||||
github: nunomaduro
|
github: [nunomaduro,owenvoke,olivernybroe,octoper]
|
||||||
patreon: nunomaduro
|
patreon: nunomaduro
|
||||||
custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L
|
custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L
|
||||||
|
|||||||
19
.github/workflows/changelog.yml
vendored
19
.github/workflows/changelog.yml
vendored
@ -5,6 +5,7 @@ on:
|
|||||||
branches: [ master ]
|
branches: [ master ]
|
||||||
paths:
|
paths:
|
||||||
- CHANGELOG.md
|
- CHANGELOG.md
|
||||||
|
- .github/workflows/changelog.yml
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [ master ]
|
||||||
paths:
|
paths:
|
||||||
@ -17,17 +18,21 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Checkout website repository
|
- name: Checkout website repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CHANGELOG_KEY }}
|
token: ${{ secrets.CHANGELOG_KEY }}
|
||||||
repository: pestphp/website
|
repository: pestphp/docs
|
||||||
path: pestphp-website
|
path: pestphp-docs
|
||||||
|
ref: master
|
||||||
|
|
||||||
- name: Read CHANGELOG.md
|
- name: Read CHANGELOG.md
|
||||||
id: package
|
id: package
|
||||||
uses: juliangruber/read-file-action@v1
|
uses: juliangruber/read-file-action@v1
|
||||||
with:
|
with:
|
||||||
path: ./CHANGELOG.md
|
path: ./CHANGELOG.md
|
||||||
|
|
||||||
- name: Add file headers
|
- name: Add file headers
|
||||||
uses: DamianReeves/write-file-action@v1.0
|
uses: DamianReeves/write-file-action@v1.0
|
||||||
with:
|
with:
|
||||||
@ -36,8 +41,6 @@ jobs:
|
|||||||
---
|
---
|
||||||
title: Changelog
|
title: Changelog
|
||||||
description: Changelog
|
description: Changelog
|
||||||
extends: _layouts.documentation
|
|
||||||
section: content
|
|
||||||
---
|
---
|
||||||
${{ steps.package.outputs.content }}
|
${{ steps.package.outputs.content }}
|
||||||
|
|
||||||
@ -45,14 +48,16 @@ jobs:
|
|||||||
|
|
||||||
Next section: [Upgrade Guide →](/docs/upgrade-guide)
|
Next section: [Upgrade Guide →](/docs/upgrade-guide)
|
||||||
write-mode: overwrite
|
write-mode: overwrite
|
||||||
|
|
||||||
- name: Copy CHANGELOG to website repository
|
- name: Copy CHANGELOG to website repository
|
||||||
run: cp CHANGELOG.md pestphp-website/source/docs/changelog.md
|
run: cp CHANGELOG.md pestphp-docs/changelog.md
|
||||||
|
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
uses: peter-evans/create-pull-request@v2
|
uses: peter-evans/create-pull-request@v3
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CHANGELOG_KEY }}
|
token: ${{ secrets.CHANGELOG_KEY }}
|
||||||
commit-message: Update changelog.md
|
commit-message: Update changelog.md
|
||||||
committer: GitHub Action <noreply@github.com>
|
committer: GitHub Action <noreply@github.com>
|
||||||
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
|
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
|
||||||
title: 'Update changelog.md'
|
title: 'Update changelog.md'
|
||||||
path: ./pestphp-website
|
path: ./pestphp-docs
|
||||||
|
|||||||
7
.github/workflows/static.yml
vendored
7
.github/workflows/static.yml
vendored
@ -15,16 +15,13 @@ jobs:
|
|||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: 7.4
|
php-version: 8.0
|
||||||
tools: composer:v2
|
tools: composer:v2
|
||||||
coverage: none
|
coverage: none
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: composer update --no-interaction --no-progress
|
run: composer update --no-interaction --no-progress
|
||||||
|
|
||||||
- name: Run Rector
|
|
||||||
run: vendor/bin/rector process src --dry-run
|
|
||||||
|
|
||||||
- name: Run PHP-CS-Fixer
|
- name: Run PHP-CS-Fixer
|
||||||
run: vendor/bin/php-cs-fixer fix -v --allow-risky=yes --dry-run
|
run: vendor/bin/php-cs-fixer fix -v --allow-risky=yes --dry-run
|
||||||
|
|
||||||
@ -43,7 +40,7 @@ jobs:
|
|||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: 7.4
|
php-version: 8.0
|
||||||
tools: composer:v2
|
tools: composer:v2
|
||||||
coverage: none
|
coverage: none
|
||||||
|
|
||||||
|
|||||||
5
.gitignore
vendored
5
.gitignore
vendored
@ -4,8 +4,9 @@ composer.lock
|
|||||||
/vendor/
|
/vendor/
|
||||||
coverage.xml
|
coverage.xml
|
||||||
.phpunit.result.cache
|
.phpunit.result.cache
|
||||||
.php_cs.cache
|
/.php-cs-fixer.php
|
||||||
|
.php-cs-fixer.cache
|
||||||
.temp/coverage.php
|
.temp/coverage.php
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|||||||
@ -6,7 +6,7 @@ $finder = PhpCsFixer\Finder::create()
|
|||||||
->in(__DIR__ . DIRECTORY_SEPARATOR . 'scripts')
|
->in(__DIR__ . DIRECTORY_SEPARATOR . 'scripts')
|
||||||
->in(__DIR__ . DIRECTORY_SEPARATOR . 'stubs')
|
->in(__DIR__ . DIRECTORY_SEPARATOR . 'stubs')
|
||||||
->in(__DIR__ . DIRECTORY_SEPARATOR . 'src')
|
->in(__DIR__ . DIRECTORY_SEPARATOR . 'src')
|
||||||
->append(['.php_cs']);
|
->append(['.php-cs-fixer.dist.php']);
|
||||||
|
|
||||||
$rules = [
|
$rules = [
|
||||||
'@Symfony' => true,
|
'@Symfony' => true,
|
||||||
@ -25,7 +25,7 @@ $rules = [
|
|||||||
|
|
||||||
$rules['increment_style'] = ['style' => 'post'];
|
$rules['increment_style'] = ['style' => 'post'];
|
||||||
|
|
||||||
return PhpCsFixer\Config::create()
|
return (new PhpCsFixer\Config())
|
||||||
->setUsingCache(true)
|
->setUsingCache(true)
|
||||||
->setRules($rules)
|
->setRules($rules)
|
||||||
->setFinder($finder);
|
->setFinder($finder);
|
||||||
116
CHANGELOG.md
116
CHANGELOG.md
@ -4,7 +4,121 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
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]
|
## [v1.2.1 (2021-05-14)](https://github.com/pestphp/pest/compare/v1.2.0...v1.2.1)
|
||||||
|
### Fixed
|
||||||
|
- Laravel commands failing with new `--test-directory` option ([#297](https://github.com/pestphp/pest/pull/297))
|
||||||
|
|
||||||
|
## [v1.2.0 (2021-05-13)](https://github.com/pestphp/pest/compare/v1.1.0...v1.2.0)
|
||||||
|
### Added
|
||||||
|
- Adds JUnit / Infection support ([#291](https://github.com/pestphp/pest/pull/291))
|
||||||
|
- `--test-directory` command line option ([#283](https://github.com/pestphp/pest/pull/283))
|
||||||
|
|
||||||
|
## [v1.1.0 (2021-05-02)](https://github.com/pestphp/pest/compare/v1.0.5...v1.1.0)
|
||||||
|
### Added
|
||||||
|
- Possibility of "hooks" being added using the "uses" function ([#282](https://github.com/pestphp/pest/pull/282))
|
||||||
|
|
||||||
|
## [v1.0.5 (2021-03-31)](https://github.com/pestphp/pest/compare/v1.0.4...v1.0.5)
|
||||||
|
### Added
|
||||||
|
- Add `--browse` option to `pest:dusk` command ([#280](https://github.com/pestphp/pest/pull/280))
|
||||||
|
- Support for PHPUnit 9.5.4 ([#284](https://github.com/pestphp/pest/pull/284))
|
||||||
|
|
||||||
|
## [v1.0.4 (2021-03-17)](https://github.com/pestphp/pest/compare/v1.0.3...v1.0.4)
|
||||||
|
### Added
|
||||||
|
- Support for PHPUnit 9.5.3 ([#278](https://github.com/pestphp/pest/pull/278))
|
||||||
|
|
||||||
|
## [v1.0.3 (2021-03-13)](https://github.com/pestphp/pest/compare/v1.0.2...v1.0.3)
|
||||||
|
### Added
|
||||||
|
- Support for test extensions ([#269](https://github.com/pestphp/pest/pull/269))
|
||||||
|
|
||||||
|
## [v1.0.2 (2021-02-04)](https://github.com/pestphp/pest/compare/v1.0.1...v1.0.2)
|
||||||
|
### Added
|
||||||
|
- Support for PHPUnit 9.5.2 ([#267](https://github.com/pestphp/pest/pull/267))
|
||||||
|
|
||||||
|
## [v1.0.1 (2021-01-18)](https://github.com/pestphp/pest/compare/v1.0.0...v1.0.1)
|
||||||
|
### Added
|
||||||
|
- Support for PHPUnit 9.5.1 ([#261](https://github.com/pestphp/pest/pull/261))
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fix `TestCase@expect` PHPDoc tag ([#251](https://github.com/pestphp/pest/pull/251))
|
||||||
|
|
||||||
|
## [v1.0.0 (2021-01-03)](https://github.com/pestphp/pest/compare/v0.3.19...v1.0.0)
|
||||||
|
### Added
|
||||||
|
- `pest:test --dusk` option ([#245](https://github.com/pestphp/pest/pull/245))
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Stable version
|
||||||
|
- Updates init structure ([#240](https://github.com/pestphp/pest/pull/240))
|
||||||
|
|
||||||
|
## [v0.3.19 (2020-12-27)](https://github.com/pestphp/pest/compare/v0.3.18...v0.3.19)
|
||||||
|
### Fixed
|
||||||
|
- Fix binary path in `pest:dusk` command ([#239](https://github.com/pestphp/pest/pull/239))
|
||||||
|
|
||||||
|
## [v0.3.18 (2020-12-26)](https://github.com/pestphp/pest/compare/v0.3.17...v0.3.18)
|
||||||
|
### Added
|
||||||
|
- `toBeJson()` expectation ([plugin-expectations#2](https://github.com/pestphp/pest-plugin-expectations/pull/2))
|
||||||
|
|
||||||
|
## [v0.3.17 (2020-12-20)](https://github.com/pestphp/pest/compare/v0.3.16...v0.3.17)
|
||||||
|
### Fixed
|
||||||
|
- Class inheritance with `depends()` ([#236](https://github.com/pestphp/pest/pull/236))
|
||||||
|
|
||||||
|
## [v0.3.16 (2020-12-13)](https://github.com/pestphp/pest/compare/v0.3.15...v0.3.16)
|
||||||
|
### Changed
|
||||||
|
- Moves expectation API for external plugin ([5d7f262](https://github.com/pestphp/pest/commit/5d7f262f4ab280a660a85900f402eebb23abfda8))
|
||||||
|
|
||||||
|
## [v0.3.15 (2020-12-04)](https://github.com/pestphp/pest/compare/v0.3.14...v0.3.15)
|
||||||
|
### Added
|
||||||
|
- Support for PHPUnit 9.5.0 ([#234](https://github.com/pestphp/pest/pull/234))
|
||||||
|
- Support for extending expectation API ([#232](https://github.com/pestphp/pest/pull/232))
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Static analysis while using string as key for datasets ([#233](https://github.com/pestphp/pest/pull/233))
|
||||||
|
|
||||||
|
## [v0.3.14 (2020-11-28)](https://github.com/pestphp/pest/compare/v0.3.13...v0.3.14)
|
||||||
|
### Added
|
||||||
|
- `pest:dusk` command ([#223](https://github.com/pestphp/pest/pull/223))
|
||||||
|
- Better feedback on errors in `toMatchArray` and `toMatchObject` ([#231](https://github.com/pestphp/pest/pull/231))
|
||||||
|
|
||||||
|
## [v0.3.13 (2020-11-23)](https://github.com/pestphp/pest/compare/v0.3.12...v0.3.13)
|
||||||
|
### Added
|
||||||
|
- `toMatchArray` expectation ([7bea51f](https://github.com/pestphp/pest/commit/7bea51fe09dd2eca7093e4c34cf2dab2e8d39fa5), [3fd24d9](https://github.com/pestphp/pest/commit/3fd24d96d3145dcebdb0aab40aa8b76faa8b6979))
|
||||||
|
- Add Pest options to `--help` output ([#217](https://github.com/pestphp/pest/pull/217))
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Resolve issue with name resolution in `depends()` ([#216](https://github.com/pestphp/pest/pull/216))
|
||||||
|
|
||||||
|
## [v0.3.12 (2020-11-11)](https://github.com/pestphp/pest/compare/v0.3.11...v0.3.12)
|
||||||
|
### Added
|
||||||
|
- Add support for PHPUnit 9.4.3 ([#219](https://github.com/pestphp/pest/pull/219))
|
||||||
|
|
||||||
|
## [v0.3.11 (2020-11-09)](https://github.com/pestphp/pest/compare/v0.3.10...v0.3.11)
|
||||||
|
### Changed
|
||||||
|
- Improved the exception output for the TeamCity printer (usage with phpstorm plugin) ([#215](https://github.com/pestphp/pest/pull/215))
|
||||||
|
|
||||||
|
## [v0.3.10 (2020-11-01)](https://github.com/pestphp/pest/compare/v0.3.9...v0.3.10)
|
||||||
|
### Added
|
||||||
|
- Add support for PHPUnit 9.4.2 ([d177ab5](https://github.com/pestphp/pest/commit/d177ab5ec2030c5bb8e418d10834c370c94c433d))
|
||||||
|
|
||||||
|
## [v0.3.9 (2020-10-13)](https://github.com/pestphp/pest/compare/v0.3.8...v0.3.9)
|
||||||
|
### Added
|
||||||
|
- Add support for named datasets in description output ([#134](https://github.com/pestphp/pest/pull/134))
|
||||||
|
- Add Pest version to `--help` output ([#203](https://github.com/pestphp/pest/pull/203))
|
||||||
|
- Add support for PHPUnit 9.4.1 ([#207](https://github.com/pestphp/pest/pull/207))
|
||||||
|
|
||||||
|
## [v0.3.8 (2020-10-03)](https://github.com/pestphp/pest/compare/v0.3.7...v0.3.8)
|
||||||
|
### Added
|
||||||
|
- Add support for PHPUnit 9.4.0 ([#199](https://github.com/pestphp/pest/pull/199))
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fix chained higher order assertions returning void ([#196](https://github.com/pestphp/pest/pull/196))
|
||||||
|
|
||||||
|
## [v0.3.7 (2020-09-30)](https://github.com/pestphp/pest/compare/v0.3.6...v0.3.7)
|
||||||
|
### Added
|
||||||
|
- Add support for PHPUnit 9.3.11 ([#193](https://github.com/pestphp/pest/pull/193))
|
||||||
|
|
||||||
|
## [v0.3.6 (2020-09-21)](https://github.com/pestphp/pest/compare/v0.3.5...v0.3.6)
|
||||||
|
### Added
|
||||||
|
- `toMatch` expectation ([#191](https://github.com/pestphp/pest/pull/191))
|
||||||
|
- `toMatchConstraint` expectation ([#190](https://github.com/pestphp/pest/pull/190))
|
||||||
|
|
||||||
## [v0.3.5 (2020-09-16)](https://github.com/pestphp/pest/compare/v0.3.4...v0.3.5)
|
## [v0.3.5 (2020-09-16)](https://github.com/pestphp/pest/compare/v0.3.4...v0.3.5)
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@ -21,6 +21,8 @@ We would like to extend our thanks to the following sponsors for funding Pest de
|
|||||||
|
|
||||||
### Premium Sponsors
|
### Premium Sponsors
|
||||||
|
|
||||||
- **[Scout APM](https://github.com/scoutapp)**
|
- **[Scout APM](https://scoutapm.com)**
|
||||||
|
- **[Akaunting](https://akaunting.com)**
|
||||||
|
- **[Meema](https://meema.io/)**
|
||||||
|
|
||||||
Pest was created by **[Nuno Maduro](https://twitter.com/enunomaduro)** under the **[Sponsorware license](https://github.com/sponsorware/docs)**. It got open-sourced and is now licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.
|
Pest was created by **[Nuno Maduro](https://twitter.com/enunomaduro)** under the **[Sponsorware license](https://github.com/sponsorware/docs)**. It got open-sourced and is now licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.
|
||||||
|
|||||||
16
RELEASE.md
Normal file
16
RELEASE.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Release process
|
||||||
|
|
||||||
|
When releasing a new version of Pest there are some checks and updates that need to be done:
|
||||||
|
|
||||||
|
- Clear your local repository with: `git add . && git reset --hard && git checkout master`
|
||||||
|
- On the GitHub repository, check the contents of [github.com/pestphp/pest/compare/{latest_version}...master](https://github.com/pestphp/pest/compare/{latest_version}...master) and update the [changelog](CHANGELOG.md) file with the main changes for this release
|
||||||
|
- Update the version number in [src/Pest.php](src/Pest.php)
|
||||||
|
- Run the tests locally using: `composer test`
|
||||||
|
- Commit the CHANGELOG and Pest file with the message: `git commit -m "docs: update changelog"`
|
||||||
|
- Push the changes to GitHub
|
||||||
|
- Check that the CI is passing as expected: [github.com/pestphp/pest/actions](https://github.com/pestphp/pest/actions)
|
||||||
|
- Tag and push the tag with `git tag vX.X.X && git push --tags`
|
||||||
|
|
||||||
|
### Plugins
|
||||||
|
|
||||||
|
Plugins should be versioned using the same major (or minor for `0.x` releases) version as Pest core.
|
||||||
19
bin/pest
19
bin/pest
@ -19,17 +19,21 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
|
|
||||||
if (file_exists($vendorPath)) {
|
if (file_exists($vendorPath)) {
|
||||||
include_once $vendorPath;
|
include_once $vendorPath;
|
||||||
|
$autoloadPath = $vendorPath;
|
||||||
} else {
|
} else {
|
||||||
include_once $localPath;
|
include_once $localPath;
|
||||||
|
$autoloadPath = $localPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
(new Provider())->register();
|
(new Provider())->register();
|
||||||
|
|
||||||
$rootPath = getcwd();
|
// get $rootPath based on $autoloadPath
|
||||||
|
$rootPath = dirname($autoloadPath, 2);
|
||||||
|
$argv = new ArgvInput();
|
||||||
|
|
||||||
$testSuite = TestSuite::getInstance($rootPath);
|
$testSuite = TestSuite::getInstance($rootPath, $argv->getParameterOption('--test-directory', 'tests'));
|
||||||
|
|
||||||
$isDecorated = (new ArgvInput())->getParameterOption('--colors', 'always') !== 'never';
|
$isDecorated = $argv->getParameterOption('--colors', 'always') !== 'never';
|
||||||
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, $isDecorated);
|
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, $isDecorated);
|
||||||
|
|
||||||
$container = Container::getInstance();
|
$container = Container::getInstance();
|
||||||
@ -38,5 +42,14 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
|
|
||||||
ValidatesEnvironment::in($testSuite);
|
ValidatesEnvironment::in($testSuite);
|
||||||
|
|
||||||
|
// lets remove any arguments that PHPUnit does not understand
|
||||||
|
if ($argv->hasParameterOption('--test-directory')) {
|
||||||
|
foreach ($_SERVER['argv'] as $key => $value) {
|
||||||
|
if (strpos($value, '--test-directory') !== false) {
|
||||||
|
unset($_SERVER['argv'][$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exit($container->get(Command::class)->run($_SERVER['argv']));
|
exit($container->get(Command::class)->run($_SERVER['argv']));
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -19,17 +19,18 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": "^7.3 || ^8.0",
|
"php": "^7.3 || ^8.0",
|
||||||
"nunomaduro/collision": "^5.0",
|
"nunomaduro/collision": "^5.0",
|
||||||
"pestphp/pest-plugin": "^0.3",
|
"pestphp/pest-plugin": "^1.0",
|
||||||
"pestphp/pest-plugin-coverage": "^0.3",
|
"pestphp/pest-plugin-coverage": "^1.0",
|
||||||
"pestphp/pest-plugin-init": "^0.3",
|
"pestphp/pest-plugin-expectations": "^1.0",
|
||||||
"phpunit/phpunit": "9.3.7 || 9.3.8 || 9.3.9 || 9.3.10"
|
"pestphp/pest-plugin-init": "^1.0",
|
||||||
|
"phpunit/phpunit": ">= 9.3.7 <= 9.5.4"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Pest\\": "src/"
|
"Pest\\": "src/"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src/globals.php",
|
"src/Functions.php",
|
||||||
"src/Pest.php"
|
"src/Pest.php"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -42,9 +43,10 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"illuminate/console": "^7.16.1",
|
"illuminate/console": "^8.32.1",
|
||||||
"illuminate/support": "^7.16.1",
|
"illuminate/support": "^8.32.1",
|
||||||
"mockery/mockery": "^1.4.1",
|
"laravel/dusk": "^6.13.0",
|
||||||
|
"mockery/mockery": "^1.4.3",
|
||||||
"pestphp/pest-dev-tools": "dev-master"
|
"pestphp/pest-dev-tools": "dev-master"
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
@ -57,8 +59,8 @@
|
|||||||
"bin/pest"
|
"bin/pest"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "rector process src && php-cs-fixer fix -v",
|
"lint": "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",
|
||||||
"test:types": "phpstan analyse --ansi --memory-limit=0",
|
"test:types": "phpstan analyse --ansi --memory-limit=0",
|
||||||
"test:unit": "php bin/pest --colors=always --exclude-group=integration",
|
"test:unit": "php bin/pest --colors=always --exclude-group=integration",
|
||||||
"test:integration": "php bin/pest --colors=always --group=integration",
|
"test:integration": "php bin/pest --colors=always --group=integration",
|
||||||
@ -72,7 +74,7 @@
|
|||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "0.4.x-dev"
|
"dev-master": "1.x-dev"
|
||||||
},
|
},
|
||||||
"pest": {
|
"pest": {
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
|||||||
13
phpstan.neon
13
phpstan.neon
@ -7,15 +7,13 @@ parameters:
|
|||||||
level: max
|
level: max
|
||||||
paths:
|
paths:
|
||||||
- src
|
- src
|
||||||
excludes_analyse:
|
|
||||||
- src/globals.php
|
|
||||||
|
|
||||||
checkMissingIterableValueType: true
|
checkMissingIterableValueType: true
|
||||||
checkGenericClassInNonGenericObjectType: false
|
checkGenericClassInNonGenericObjectType: false
|
||||||
reportUnmatchedIgnoredErrors: true
|
reportUnmatchedIgnoredErrors: true
|
||||||
|
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
- "#Undefined variable: \\$this#"
|
- "#type mixed is not subtype of native#"
|
||||||
- "#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#"
|
||||||
@ -24,10 +22,13 @@ parameters:
|
|||||||
- "#Method Pest\\\\Support\\\\Reflection::getParameterClassName\\(\\) has a nullable return type declaration.#"
|
- "#Method Pest\\\\Support\\\\Reflection::getParameterClassName\\(\\) has a nullable return type declaration.#"
|
||||||
-
|
-
|
||||||
message: '#Call to an undefined method PHPUnit\\Framework\\Test::getName\(\)#'
|
message: '#Call to an undefined method PHPUnit\\Framework\\Test::getName\(\)#'
|
||||||
path: src/TeamCity.php
|
path: src/Logging
|
||||||
-
|
-
|
||||||
message: '#invalid typehint type Pest\\Concerns\\TestCase#'
|
message: '#invalid typehint type Pest\\Concerns\\TestCase#'
|
||||||
path: src/TeamCity.php
|
path: src/Logging
|
||||||
-
|
-
|
||||||
message: '#is not subtype of native type PHPUnit\\Framework\\Test#'
|
message: '#is not subtype of native type PHPUnit\\Framework\\Test#'
|
||||||
path: src/TeamCity.php
|
path: src/Logging
|
||||||
|
-
|
||||||
|
message: '#Call to an undefined method PHPUnit\\Framework\\Test::getPrintableTestCaseName\(\)#'
|
||||||
|
path: src/Logging
|
||||||
|
|||||||
35
rector.php
35
rector.php
@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
use Rector\Core\Configuration\Option;
|
|
||||||
use Rector\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector;
|
|
||||||
use Rector\Set\ValueObject\SetList;
|
|
||||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
|
||||||
|
|
||||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
|
||||||
$parameters = $containerConfigurator->parameters();
|
|
||||||
|
|
||||||
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
|
|
||||||
|
|
||||||
$parameters->set(Option::SETS, [
|
|
||||||
SetList::ACTION_INJECTION_TO_CONSTRUCTOR_INJECTION,
|
|
||||||
SetList::ARRAY_STR_FUNCTIONS_TO_STATIC_CALL,
|
|
||||||
SetList::CODE_QUALITY,
|
|
||||||
SetList::PHP_53,
|
|
||||||
SetList::PHP_54,
|
|
||||||
SetList::PHP_56,
|
|
||||||
SetList::PHP_70,
|
|
||||||
SetList::PHP_71,
|
|
||||||
SetList::PHP_72,
|
|
||||||
SetList::PHP_73,
|
|
||||||
SetList::PHPSTAN,
|
|
||||||
SetList::PHPUNIT_CODE_QUALITY,
|
|
||||||
SetList::SOLID,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/tests']);
|
|
||||||
$parameters->set(Option::EXCLUDE_RECTORS, [
|
|
||||||
StaticCallOnNonStaticToInstanceCallRector::class,
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
@ -5,7 +5,8 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Actions;
|
namespace Pest\Actions;
|
||||||
|
|
||||||
use NunoMaduro\Collision\Adapters\Phpunit\Printer;
|
use NunoMaduro\Collision\Adapters\Phpunit\Printer;
|
||||||
use Pest\TeamCity;
|
use Pest\Logging\JUnit;
|
||||||
|
use Pest\Logging\TeamCity;
|
||||||
use PHPUnit\TextUI\DefaultResultPrinter;
|
use PHPUnit\TextUI\DefaultResultPrinter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,6 +33,14 @@ final class AddsDefaults
|
|||||||
$arguments[self::PRINTER] = new TeamCity($arguments['verbose'] ?? false, $arguments['colors'] ?? DefaultResultPrinter::COLOR_ALWAYS);
|
$arguments[self::PRINTER] = new TeamCity($arguments['verbose'] ?? false, $arguments['colors'] ?? DefaultResultPrinter::COLOR_ALWAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load our junit logger instead.
|
||||||
|
if (array_key_exists('junitLogfile', $arguments)) {
|
||||||
|
$arguments['listeners'][] = new JUnit(
|
||||||
|
$arguments['junitLogfile']
|
||||||
|
);
|
||||||
|
unset($arguments['junitLogfile']);
|
||||||
|
}
|
||||||
|
|
||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Actions;
|
namespace Pest\Actions;
|
||||||
|
|
||||||
use Pest\Support\Str;
|
use Pest\Support\Str;
|
||||||
use PHPUnit\TextUI\Configuration\Configuration;
|
use function Pest\testDirectory;
|
||||||
use PHPUnit\Util\FileLoader;
|
use PHPUnit\Util\FileLoader;
|
||||||
use RecursiveDirectoryIterator;
|
use RecursiveDirectoryIterator;
|
||||||
use RecursiveIteratorIterator;
|
use RecursiveIteratorIterator;
|
||||||
@ -21,6 +21,7 @@ final class LoadStructure
|
|||||||
* @var array<int, string>
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
private const STRUCTURE = [
|
private const STRUCTURE = [
|
||||||
|
'Expectations.php',
|
||||||
'Datasets.php',
|
'Datasets.php',
|
||||||
'Helpers.php',
|
'Helpers.php',
|
||||||
'Pest.php',
|
'Pest.php',
|
||||||
@ -32,7 +33,7 @@ final class LoadStructure
|
|||||||
*/
|
*/
|
||||||
public static function in(string $rootPath): void
|
public static function in(string $rootPath): void
|
||||||
{
|
{
|
||||||
$testsPath = $rootPath . DIRECTORY_SEPARATOR . 'tests';
|
$testsPath = $rootPath . DIRECTORY_SEPARATOR . testDirectory();
|
||||||
|
|
||||||
$load = function ($filename): bool {
|
$load = function ($filename): bool {
|
||||||
return file_exists($filename) && (bool) FileLoader::checkAndLoad($filename);
|
return file_exists($filename) && (bool) FileLoader::checkAndLoad($filename);
|
||||||
|
|||||||
@ -5,10 +5,10 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Concerns;
|
namespace Pest\Concerns;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Pest\Expectation;
|
use Pest\Support\ChainableClosure;
|
||||||
use Pest\Support\ExceptionTrace;
|
use Pest\Support\ExceptionTrace;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use PHPUnit\Util\Test;
|
use PHPUnit\Framework\ExecutionOrderDependency;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,6 +34,38 @@ trait TestCase
|
|||||||
*/
|
*/
|
||||||
private $__test;
|
private $__test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds a global/shared beforeEach ("set up") closure if one has been
|
||||||
|
* defined.
|
||||||
|
*
|
||||||
|
* @var Closure|null
|
||||||
|
*/
|
||||||
|
private $beforeEach = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds a global/shared afterEach ("tear down") closure if one has been
|
||||||
|
* defined.
|
||||||
|
*
|
||||||
|
* @var Closure|null
|
||||||
|
*/
|
||||||
|
private $afterEach = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds a global/shared beforeAll ("set up before") closure if one has been
|
||||||
|
* defined.
|
||||||
|
*
|
||||||
|
* @var Closure|null
|
||||||
|
*/
|
||||||
|
private static $beforeAll = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds a global/shared afterAll ("tear down after") closure if one has
|
||||||
|
* been defined.
|
||||||
|
*
|
||||||
|
* @var Closure|null
|
||||||
|
*/
|
||||||
|
private static $afterAll = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of the test case.
|
* Creates a new instance of the test case.
|
||||||
*/
|
*/
|
||||||
@ -55,6 +87,86 @@ trait TestCase
|
|||||||
$this->setGroups($groups);
|
$this->setGroups($groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add dependencies to the test case and map them to instances of ExecutionOrderDependency.
|
||||||
|
*/
|
||||||
|
public function addDependencies(array $tests): void
|
||||||
|
{
|
||||||
|
$className = get_class($this);
|
||||||
|
|
||||||
|
$tests = array_map(function (string $test) use ($className): ExecutionOrderDependency {
|
||||||
|
if (strpos($test, '::') === false) {
|
||||||
|
$test = "{$className}::{$test}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ExecutionOrderDependency($test, null, '');
|
||||||
|
}, $tests);
|
||||||
|
|
||||||
|
$this->setDependencies($tests);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a shared/"global" before all test hook that will execute **before**
|
||||||
|
* the test defined `beforeAll` hook(s).
|
||||||
|
*/
|
||||||
|
public function addBeforeAll(?Closure $hook): void
|
||||||
|
{
|
||||||
|
if (!$hook) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$beforeAll = (self::$beforeAll instanceof Closure)
|
||||||
|
? ChainableClosure::fromStatic(self::$beforeAll, $hook)
|
||||||
|
: $hook;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a shared/"global" after all test hook that will execute **before**
|
||||||
|
* the test defined `afterAll` hook(s).
|
||||||
|
*/
|
||||||
|
public function addAfterAll(?Closure $hook): void
|
||||||
|
{
|
||||||
|
if (!$hook) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$afterAll = (self::$afterAll instanceof Closure)
|
||||||
|
? ChainableClosure::fromStatic(self::$afterAll, $hook)
|
||||||
|
: $hook;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a shared/"global" before each test hook that will execute **before**
|
||||||
|
* the test defined `beforeEach` hook.
|
||||||
|
*/
|
||||||
|
public function addBeforeEach(?Closure $hook): void
|
||||||
|
{
|
||||||
|
$this->addHook('beforeEach', $hook);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a shared/"global" after each test hook that will execute **before**
|
||||||
|
* the test defined `afterEach` hook.
|
||||||
|
*/
|
||||||
|
public function addAfterEach(?Closure $hook): void
|
||||||
|
{
|
||||||
|
$this->addHook('afterEach', $hook);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a shared/global hook and compose them if more than one is passed.
|
||||||
|
*/
|
||||||
|
private function addHook(string $property, ?Closure $hook): void
|
||||||
|
{
|
||||||
|
if (!$hook) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->{$property} = ($this->{$property} instanceof Closure)
|
||||||
|
? ChainableClosure::from($this->{$property}, $hook)
|
||||||
|
: $hook;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the test case name. Note that, in Pest
|
* Returns the test case name. Note that, in Pest
|
||||||
* we ignore withDataset argument as the description
|
* we ignore withDataset argument as the description
|
||||||
@ -79,6 +191,10 @@ trait TestCase
|
|||||||
|
|
||||||
$beforeAll = TestSuite::getInstance()->beforeAll->get(self::$__filename);
|
$beforeAll = TestSuite::getInstance()->beforeAll->get(self::$__filename);
|
||||||
|
|
||||||
|
if (self::$beforeAll instanceof Closure) {
|
||||||
|
$beforeAll = ChainableClosure::fromStatic(self::$beforeAll, $beforeAll);
|
||||||
|
}
|
||||||
|
|
||||||
call_user_func(Closure::bind($beforeAll, null, self::class));
|
call_user_func(Closure::bind($beforeAll, null, self::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,21 +205,15 @@ trait TestCase
|
|||||||
{
|
{
|
||||||
$afterAll = TestSuite::getInstance()->afterAll->get(self::$__filename);
|
$afterAll = TestSuite::getInstance()->afterAll->get(self::$__filename);
|
||||||
|
|
||||||
|
if (self::$afterAll instanceof Closure) {
|
||||||
|
$afterAll = ChainableClosure::fromStatic(self::$afterAll, $afterAll);
|
||||||
|
}
|
||||||
|
|
||||||
call_user_func(Closure::bind($afterAll, null, self::class));
|
call_user_func(Closure::bind($afterAll, null, self::class));
|
||||||
|
|
||||||
parent::tearDownAfterClass();
|
parent::tearDownAfterClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new expectation.
|
|
||||||
*
|
|
||||||
* @param mixed $value
|
|
||||||
*/
|
|
||||||
public function expect($value): Expectation
|
|
||||||
{
|
|
||||||
return new Expectation($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets executed before the test.
|
* Gets executed before the test.
|
||||||
*/
|
*/
|
||||||
@ -115,6 +225,10 @@ trait TestCase
|
|||||||
|
|
||||||
$beforeEach = TestSuite::getInstance()->beforeEach->get(self::$__filename);
|
$beforeEach = TestSuite::getInstance()->beforeEach->get(self::$__filename);
|
||||||
|
|
||||||
|
if ($this->beforeEach instanceof Closure) {
|
||||||
|
$beforeEach = ChainableClosure::from($this->beforeEach, $beforeEach);
|
||||||
|
}
|
||||||
|
|
||||||
$this->__callClosure($beforeEach, func_get_args());
|
$this->__callClosure($beforeEach, func_get_args());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +239,10 @@ trait TestCase
|
|||||||
{
|
{
|
||||||
$afterEach = TestSuite::getInstance()->afterEach->get(self::$__filename);
|
$afterEach = TestSuite::getInstance()->afterEach->get(self::$__filename);
|
||||||
|
|
||||||
|
if ($this->afterEach instanceof Closure) {
|
||||||
|
$afterEach = ChainableClosure::from($this->afterEach, $afterEach);
|
||||||
|
}
|
||||||
|
|
||||||
$this->__callClosure($afterEach, func_get_args());
|
$this->__callClosure($afterEach, func_get_args());
|
||||||
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
|
|||||||
@ -11,6 +11,8 @@ use Pest\Actions\ValidatesConfiguration;
|
|||||||
use Pest\Contracts\Plugins\AddsOutput;
|
use Pest\Contracts\Plugins\AddsOutput;
|
||||||
use Pest\Contracts\Plugins\HandlesArguments;
|
use Pest\Contracts\Plugins\HandlesArguments;
|
||||||
use Pest\Plugin\Loader;
|
use Pest\Plugin\Loader;
|
||||||
|
use Pest\Plugins\Version;
|
||||||
|
use Pest\Support\Container;
|
||||||
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;
|
||||||
@ -88,8 +90,6 @@ 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'];
|
||||||
|
|
||||||
@ -125,6 +125,8 @@ final class Command extends BaseCommand
|
|||||||
*/
|
*/
|
||||||
public function run(array $argv, bool $exit = true): int
|
public function run(array $argv, bool $exit = true): int
|
||||||
{
|
{
|
||||||
|
LoadStructure::in($this->testSuite->rootPath);
|
||||||
|
|
||||||
$result = parent::run($argv, false);
|
$result = parent::run($argv, false);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -139,4 +141,14 @@ final class Command extends BaseCommand
|
|||||||
|
|
||||||
exit($result);
|
exit($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function showHelp(): void
|
||||||
|
{
|
||||||
|
/** @var Version $version */
|
||||||
|
$version = Container::getInstance()->get(Version::class);
|
||||||
|
$version->handleArguments(['--version']);
|
||||||
|
parent::showHelp();
|
||||||
|
|
||||||
|
(new Help($this->output))();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
37
src/Console/Help.php
Normal file
37
src/Console/Help.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest\Console;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class Help
|
||||||
|
{
|
||||||
|
/** @var array<int, string> */
|
||||||
|
private const HELP_MESSAGES = [
|
||||||
|
'<comment>Pest Options:</comment>',
|
||||||
|
' <info>--init</info> Initialise a standard Pest configuration',
|
||||||
|
' <info>--coverage</info> Enable coverage and output to standard output',
|
||||||
|
' <info>--min=<fg=cyan><N></></info> Set the minimum required coverage percentage (<N>), and fail if not met',
|
||||||
|
' <info>--group=<fg=cyan><name></></info> Only runs tests from the specified group(s)',
|
||||||
|
];
|
||||||
|
|
||||||
|
/** @var OutputInterface */
|
||||||
|
private $output;
|
||||||
|
|
||||||
|
public function __construct(OutputInterface $output)
|
||||||
|
{
|
||||||
|
$this->output = $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __invoke(): void
|
||||||
|
{
|
||||||
|
foreach (self::HELP_MESSAGES as $message) {
|
||||||
|
$this->output->writeln($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,14 +18,14 @@ final class Datasets
|
|||||||
/**
|
/**
|
||||||
* Holds the datasets.
|
* Holds the datasets.
|
||||||
*
|
*
|
||||||
* @var array<string, \Closure|iterable<int, mixed>>
|
* @var array<int|string, Closure|iterable<int|string, mixed>>
|
||||||
*/
|
*/
|
||||||
private static $datasets = [];
|
private static $datasets = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the given.
|
* Sets the given.
|
||||||
*
|
*
|
||||||
* @param Closure|iterable<int, mixed> $data
|
* @param Closure|iterable<int|string, mixed> $data
|
||||||
*/
|
*/
|
||||||
public static function set(string $name, $data): void
|
public static function set(string $name, $data): void
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ final class Datasets
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Closure|iterable<int, mixed>
|
* @return Closure|iterable<int|string, mixed>
|
||||||
*/
|
*/
|
||||||
public static function get(string $name)
|
public static function get(string $name)
|
||||||
{
|
{
|
||||||
@ -51,7 +51,7 @@ final class Datasets
|
|||||||
/**
|
/**
|
||||||
* Resolves the current dataset to an array value.
|
* Resolves the current dataset to an array value.
|
||||||
*
|
*
|
||||||
* @param Traversable<int, mixed>|Closure|iterable<int, mixed>|string|null $data
|
* @param Traversable<int|string, mixed>|Closure|iterable<int|string, mixed>|string|null $data
|
||||||
*
|
*
|
||||||
* @return array<string, mixed>
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
@ -77,10 +77,10 @@ final class Datasets
|
|||||||
$dataSetDescriptions = [];
|
$dataSetDescriptions = [];
|
||||||
$dataSetValues = [];
|
$dataSetValues = [];
|
||||||
|
|
||||||
foreach ($data as $values) {
|
foreach ($data as $key => $values) {
|
||||||
$values = is_array($values) ? $values : [$values];
|
$values = is_array($values) ? $values : [$values];
|
||||||
|
|
||||||
$dataSetDescriptions[] = $description . self::getDataSetDescription($values);
|
$dataSetDescriptions[] = $description . self::getDataSetDescription($key, $values);
|
||||||
$dataSetValues[] = $values;
|
$dataSetValues[] = $values;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,12 +104,15 @@ final class Datasets
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param int|string $key
|
||||||
* @param array<int, mixed> $data
|
* @param array<int, mixed> $data
|
||||||
*/
|
*/
|
||||||
private static function getDataSetDescription(array $data): string
|
private static function getDataSetDescription($key, array $data): string
|
||||||
{
|
{
|
||||||
$exporter = new Exporter();
|
$exporter = new Exporter();
|
||||||
|
|
||||||
return \sprintf(' with (%s)', $exporter->shortenedRecursiveExport($data));
|
$nameInsert = is_string($key) ? \sprintf('data set "%s" ', $key) : '';
|
||||||
|
|
||||||
|
return \sprintf(' with %s(%s)', $nameInsert, $exporter->shortenedRecursiveExport($data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Pest\Exceptions;
|
|
||||||
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use NunoMaduro\Collision\Contracts\RenderlessEditor;
|
|
||||||
use NunoMaduro\Collision\Contracts\RenderlessTrace;
|
|
||||||
use Symfony\Component\Console\Exception\ExceptionInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class InvalidUsesPath extends InvalidArgumentException implements ExceptionInterface, RenderlessEditor, RenderlessTrace
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Creates a new instance of invalid uses path.
|
|
||||||
*/
|
|
||||||
public function __construct(string $target)
|
|
||||||
{
|
|
||||||
parent::__construct(sprintf('The path `%s` is not valid.', $target));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,517 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Pest;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* @property Expectation $not Creates the opposite expectation.
|
|
||||||
*/
|
|
||||||
final class Expectation
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The expectation value.
|
|
||||||
*
|
|
||||||
* @readonly
|
|
||||||
*
|
|
||||||
* @var mixed
|
|
||||||
*/
|
|
||||||
public $value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new expectation.
|
|
||||||
*
|
|
||||||
* @param mixed $value
|
|
||||||
*/
|
|
||||||
public function __construct($value)
|
|
||||||
{
|
|
||||||
$this->value = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new expectation.
|
|
||||||
*
|
|
||||||
* @param mixed $value
|
|
||||||
*/
|
|
||||||
public function and($value): Expectation
|
|
||||||
{
|
|
||||||
return new self($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the opposite expectation for the value.
|
|
||||||
*/
|
|
||||||
public function not(): OppositeExpectation
|
|
||||||
{
|
|
||||||
return new OppositeExpectation($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that two variables have the same type and
|
|
||||||
* value. Used on objects, it asserts that two
|
|
||||||
* variables reference the same object.
|
|
||||||
*
|
|
||||||
* @param mixed $expected
|
|
||||||
*/
|
|
||||||
public function toBe($expected): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertSame($expected, $this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is empty.
|
|
||||||
*/
|
|
||||||
public function toBeEmpty(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertEmpty($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is true.
|
|
||||||
*/
|
|
||||||
public function toBeTrue(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertTrue($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is false.
|
|
||||||
*/
|
|
||||||
public function toBeFalse(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertFalse($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is greater than $expected.
|
|
||||||
*
|
|
||||||
* @param int|float $expected
|
|
||||||
*/
|
|
||||||
public function toBeGreaterThan($expected): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertGreaterThan($expected, $this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is greater than or equal to $expected.
|
|
||||||
*
|
|
||||||
* @param int|float $expected
|
|
||||||
*/
|
|
||||||
public function toBeGreaterThanOrEqual($expected): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertGreaterThanOrEqual($expected, $this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is less than or equal to $expected.
|
|
||||||
*
|
|
||||||
* @param int|float $expected
|
|
||||||
*/
|
|
||||||
public function toBeLessThan($expected): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertLessThan($expected, $this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is less than $expected.
|
|
||||||
*
|
|
||||||
* @param int|float $expected
|
|
||||||
*/
|
|
||||||
public function toBeLessThanOrEqual($expected): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertLessThanOrEqual($expected, $this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that $needle is an element of the value.
|
|
||||||
*
|
|
||||||
* @param mixed $needle
|
|
||||||
*/
|
|
||||||
public function toContain($needle): Expectation
|
|
||||||
{
|
|
||||||
if (is_string($this->value)) {
|
|
||||||
Assert::assertStringContainsString($needle, $this->value);
|
|
||||||
} else {
|
|
||||||
Assert::assertContains($needle, $this->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value starts with $expected.
|
|
||||||
*/
|
|
||||||
public function toStartWith(string $expected): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertStringStartsWith($expected, $this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value ends with $expected.
|
|
||||||
*/
|
|
||||||
public function toEndWith(string $expected): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertStringEndsWith($expected, $this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that $count matches the number of elements of the value.
|
|
||||||
*/
|
|
||||||
public function toHaveCount(int $count): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertCount($count, $this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value contains the property $name.
|
|
||||||
*
|
|
||||||
* @param mixed $value
|
|
||||||
*/
|
|
||||||
public function toHaveProperty(string $name, $value = null): Expectation
|
|
||||||
{
|
|
||||||
$this->toBeObject();
|
|
||||||
|
|
||||||
Assert::assertTrue(property_exists($this->value, $name));
|
|
||||||
|
|
||||||
if (func_num_args() > 1) {
|
|
||||||
/* @phpstan-ignore-next-line */
|
|
||||||
Assert::assertEquals($value, $this->value->{$name});
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that two variables have the same value.
|
|
||||||
*
|
|
||||||
* @param mixed $expected
|
|
||||||
*/
|
|
||||||
public function toEqual($expected): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertEquals($expected, $this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that two variables have the same value.
|
|
||||||
* The contents of $expected and the $this->value are
|
|
||||||
* canonicalized before they are compared. For instance, when the two
|
|
||||||
* variables $expected and $this->value are arrays, then these arrays
|
|
||||||
* are sorted before they are compared. When $expected and $this->value
|
|
||||||
* are objects, each object is converted to an array containing all
|
|
||||||
* private, protected and public attributes.
|
|
||||||
*
|
|
||||||
* @param mixed $expected
|
|
||||||
*/
|
|
||||||
public function toEqualCanonicalizing($expected): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertEqualsCanonicalizing($expected, $this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the absolute difference between the value and $expected
|
|
||||||
* is lower than $delta.
|
|
||||||
*
|
|
||||||
* @param mixed $expected
|
|
||||||
*/
|
|
||||||
public function toEqualWithDelta($expected, float $delta): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertEqualsWithDelta($expected, $this->value, $delta);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is infinite.
|
|
||||||
*/
|
|
||||||
public function toBeInfinite(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertInfinite($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is an instance of $class.
|
|
||||||
*
|
|
||||||
* @param string $class
|
|
||||||
*/
|
|
||||||
public function toBeInstanceOf($class): Expectation
|
|
||||||
{
|
|
||||||
/* @phpstan-ignore-next-line */
|
|
||||||
Assert::assertInstanceOf($class, $this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is an array.
|
|
||||||
*/
|
|
||||||
public function toBeArray(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertIsArray($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is of type bool.
|
|
||||||
*/
|
|
||||||
public function toBeBool(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertIsBool($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is of type callable.
|
|
||||||
*/
|
|
||||||
public function toBeCallable(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertIsCallable($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is of type float.
|
|
||||||
*/
|
|
||||||
public function toBeFloat(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertIsFloat($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is of type int.
|
|
||||||
*/
|
|
||||||
public function toBeInt(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertIsInt($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is of type iterable.
|
|
||||||
*/
|
|
||||||
public function toBeIterable(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertIsIterable($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is of type numeric.
|
|
||||||
*/
|
|
||||||
public function toBeNumeric(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertIsNumeric($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is of type object.
|
|
||||||
*/
|
|
||||||
public function toBeObject(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertIsObject($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is of type resource.
|
|
||||||
*/
|
|
||||||
public function toBeResource(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertIsResource($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is of type scalar.
|
|
||||||
*/
|
|
||||||
public function toBeScalar(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertIsScalar($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is of type string.
|
|
||||||
*/
|
|
||||||
public function toBeString(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertIsString($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is NAN.
|
|
||||||
*/
|
|
||||||
public function toBeNan(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertNan($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is null.
|
|
||||||
*/
|
|
||||||
public function toBeNull(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertNull($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value array has the provided $key.
|
|
||||||
*
|
|
||||||
* @param string|int $key
|
|
||||||
*/
|
|
||||||
public function toHaveKey($key): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertArrayHasKey($key, $this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value array has the provided $keys.
|
|
||||||
*
|
|
||||||
* @param array<int, int|string> $keys
|
|
||||||
*/
|
|
||||||
public function toHaveKeys(array $keys): Expectation
|
|
||||||
{
|
|
||||||
foreach ($keys as $key) {
|
|
||||||
$this->toHaveKey($key);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is a directory.
|
|
||||||
*/
|
|
||||||
public function toBeDirectory(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertDirectoryExists($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is a directory and is readable.
|
|
||||||
*/
|
|
||||||
public function toBeReadableDirectory(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertDirectoryIsReadable($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is a directory and is writable.
|
|
||||||
*/
|
|
||||||
public function toBeWritableDirectory(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertDirectoryIsWritable($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is a file.
|
|
||||||
*/
|
|
||||||
public function toBeFile(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertFileExists($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is a file and is readable.
|
|
||||||
*/
|
|
||||||
public function toBeReadableFile(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertFileIsReadable($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value is a file and is writable.
|
|
||||||
*/
|
|
||||||
public function toBeWritableFile(): Expectation
|
|
||||||
{
|
|
||||||
Assert::assertFileIsWritable($this->value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value object matches a subset
|
|
||||||
* of the properties of an given object.
|
|
||||||
*
|
|
||||||
* @param array<string, mixed>|object $object
|
|
||||||
*/
|
|
||||||
public function toMatchObject($object): Expectation
|
|
||||||
{
|
|
||||||
foreach ((array) $object as $property => $value) {
|
|
||||||
$this->toHaveProperty($property, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dynamically calls methods on the class without any arguments.
|
|
||||||
*
|
|
||||||
* @return Expectation
|
|
||||||
*/
|
|
||||||
public function __get(string $name)
|
|
||||||
{
|
|
||||||
/* @phpstan-ignore-next-line */
|
|
||||||
return $this->{$name}();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -5,14 +5,17 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Factories;
|
namespace Pest\Factories;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use ParseError;
|
||||||
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\Exceptions\ShouldNotHappen;
|
||||||
use Pest\Support\HigherOrderMessageCollection;
|
use Pest\Support\HigherOrderMessageCollection;
|
||||||
use Pest\Support\NullClosure;
|
use Pest\Support\NullClosure;
|
||||||
|
use Pest\Support\Str;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -59,7 +62,7 @@ final class TestCaseFactory
|
|||||||
/**
|
/**
|
||||||
* Holds the dataset, if any.
|
* Holds the dataset, if any.
|
||||||
*
|
*
|
||||||
* @var Closure|iterable<int, mixed>|string|null
|
* @var Closure|iterable<int|string, mixed>|string|null
|
||||||
*/
|
*/
|
||||||
public $dataset;
|
public $dataset;
|
||||||
|
|
||||||
@ -139,6 +142,7 @@ final class TestCaseFactory
|
|||||||
$proxies->proxy($this);
|
$proxies->proxy($this);
|
||||||
$chains->chain($this);
|
$chains->chain($this);
|
||||||
|
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
return 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());
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -156,14 +160,6 @@ final class TestCaseFactory
|
|||||||
return array_map($createTest, array_keys($datasets), $datasets);
|
return array_map($createTest, array_keys($datasets), $datasets);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a fully qualified class name from the current filename.
|
|
||||||
*/
|
|
||||||
public function getClassName(): string
|
|
||||||
{
|
|
||||||
return $this->makeClassFromFilename($this->filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes a fully qualified class name from the given filename.
|
* Makes a fully qualified class name from the given filename.
|
||||||
*/
|
*/
|
||||||
@ -176,7 +172,7 @@ final class TestCaseFactory
|
|||||||
}, $filename);
|
}, $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = (string) realpath($filename);
|
$filename = str_replace('\\\\', '\\', addslashes((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 = dirname(ucfirst($relativePath)) . DIRECTORY_SEPARATOR . basename($relativePath, '.php');
|
||||||
@ -184,8 +180,12 @@ final class TestCaseFactory
|
|||||||
|
|
||||||
// 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);
|
||||||
|
// Remove escaped quote sequences (maintain namespace)
|
||||||
|
$relativePath = str_replace(array_map(function (string $quote): string {
|
||||||
|
return sprintf('\\%s', $quote);
|
||||||
|
}, ['\'', '"']), '', $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\\' . $relativePath;
|
$classFQN = 'P\\' . $relativePath;
|
||||||
if (class_exists($classFQN)) {
|
if (class_exists($classFQN)) {
|
||||||
@ -202,15 +202,24 @@ final class TestCaseFactory
|
|||||||
$namespace = implode('\\', $partsFQN);
|
$namespace = implode('\\', $partsFQN);
|
||||||
$baseClass = sprintf('\%s', $this->class);
|
$baseClass = sprintf('\%s', $this->class);
|
||||||
|
|
||||||
eval("
|
if ('' === trim($className)) {
|
||||||
namespace $namespace;
|
$className = 'InvalidTestName' . Str::random();
|
||||||
|
$classFQN .= $className;
|
||||||
|
}
|
||||||
|
|
||||||
final class $className extends $baseClass implements $hasPrintableTestCaseClassFQN {
|
try {
|
||||||
$traitsCode
|
eval("
|
||||||
|
namespace $namespace;
|
||||||
|
|
||||||
private static \$__filename = '$filename';
|
final class $className extends $baseClass implements $hasPrintableTestCaseClassFQN {
|
||||||
}
|
$traitsCode
|
||||||
");
|
|
||||||
|
private static \$__filename = '$filename';
|
||||||
|
}
|
||||||
|
");
|
||||||
|
} catch (ParseError $caught) {
|
||||||
|
throw new RuntimeException(sprintf('Unable to create test case for test file at %s', $filename), 1, $caught);
|
||||||
|
}
|
||||||
|
|
||||||
return $classFQN;
|
return $classFQN;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Pest\Datasets;
|
use Pest\Datasets;
|
||||||
use Pest\Expectation;
|
|
||||||
use Pest\PendingObjects\AfterEachCall;
|
use Pest\PendingObjects\AfterEachCall;
|
||||||
use Pest\PendingObjects\BeforeEachCall;
|
use Pest\PendingObjects\BeforeEachCall;
|
||||||
use Pest\PendingObjects\TestCall;
|
use Pest\PendingObjects\TestCall;
|
||||||
@ -36,7 +35,7 @@ function beforeEach(Closure $closure = null): BeforeEachCall
|
|||||||
/**
|
/**
|
||||||
* Registers the given dataset.
|
* Registers the given dataset.
|
||||||
*
|
*
|
||||||
* @param Closure|iterable $dataset
|
* @param Closure|iterable<int|string, mixed> $dataset
|
||||||
*/
|
*/
|
||||||
function dataset(string $name, $dataset): void
|
function dataset(string $name, $dataset): void
|
||||||
{
|
{
|
||||||
@ -63,7 +62,7 @@ function uses(string ...$classAndTraits): UsesCall
|
|||||||
*/
|
*/
|
||||||
function test(string $description = null, Closure $closure = null)
|
function test(string $description = null, Closure $closure = null)
|
||||||
{
|
{
|
||||||
if ($description === null && TestSuite::getInstance()->test) {
|
if ($description === null && TestSuite::getInstance()->test !== null) {
|
||||||
return new HigherOrderTapProxy(TestSuite::getInstance()->test);
|
return new HigherOrderTapProxy(TestSuite::getInstance()->test);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,19 +100,7 @@ function afterEach(Closure $closure = null): AfterEachCall
|
|||||||
/**
|
/**
|
||||||
* Runs the given closure after all tests in the current file.
|
* Runs the given closure after all tests in the current file.
|
||||||
*/
|
*/
|
||||||
function afterAll(Closure $closure = null): void
|
function afterAll(Closure $closure): void
|
||||||
{
|
{
|
||||||
TestSuite::getInstance()->afterAll->set($closure);
|
TestSuite::getInstance()->afterAll->set($closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new expectation.
|
|
||||||
*
|
|
||||||
* @param mixed $value the Value
|
|
||||||
*
|
|
||||||
* @return Expectation
|
|
||||||
*/
|
|
||||||
function expect($value)
|
|
||||||
{
|
|
||||||
return test()->expect($value);
|
|
||||||
}
|
|
||||||
@ -8,6 +8,8 @@ use Illuminate\Console\Command;
|
|||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Pest\Exceptions\InvalidConsoleArgument;
|
use Pest\Exceptions\InvalidConsoleArgument;
|
||||||
|
use function Pest\testDirectory;
|
||||||
|
use Pest\TestSuite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -19,7 +21,8 @@ final class PestDatasetCommand extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'pest:dataset {name : The name of the dataset}';
|
protected $signature = 'pest:dataset {name : The name of the dataset}
|
||||||
|
{--test-directory=tests : The name of the tests directory}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@ -33,10 +36,13 @@ final class PestDatasetCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
|
TestSuite::getInstance(base_path(), $this->option('test-directory'));
|
||||||
|
|
||||||
/** @var string $name */
|
/** @var string $name */
|
||||||
$name = $this->argument('name');
|
$name = $this->argument('name');
|
||||||
|
|
||||||
$relativePath = sprintf('tests/Datasets/%s.php', ucfirst($name));
|
$relativePath = sprintf(testDirectory('Datasets/%s.php'), ucfirst($name));
|
||||||
|
|
||||||
/* @phpstan-ignore-next-line */
|
/* @phpstan-ignore-next-line */
|
||||||
$target = base_path($relativePath);
|
$target = base_path($relativePath);
|
||||||
|
|||||||
43
src/Laravel/Commands/PestDuskCommand.php
Normal file
43
src/Laravel/Commands/PestDuskCommand.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest\Laravel\Commands;
|
||||||
|
|
||||||
|
use Laravel\Dusk\Console\DuskCommand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class PestDuskCommand extends DuskCommand
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The console command name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'pest:dusk
|
||||||
|
{--browse : Open a browser instead of using headless mode}
|
||||||
|
{--without-tty : Disable output to TTY}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Run the Dusk tests for the application with Pest';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the PHP binary to execute.
|
||||||
|
*
|
||||||
|
* @return array<string>
|
||||||
|
*/
|
||||||
|
protected function binary()
|
||||||
|
{
|
||||||
|
if ('phpdbg' === PHP_SAPI) {
|
||||||
|
return [PHP_BINARY, '-qrr', 'vendor/pestphp/pest/bin/pest'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [PHP_BINARY, 'vendor/pestphp/pest/bin/pest'];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,7 +8,8 @@ use Illuminate\Console\Command;
|
|||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Pest\Console\Thanks;
|
use Pest\Console\Thanks;
|
||||||
use Pest\Exceptions\InvalidConsoleArgument;
|
use Pest\Exceptions\InvalidConsoleArgument;
|
||||||
use Pest\Support\Str;
|
use function Pest\testDirectory;
|
||||||
|
use Pest\TestSuite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -20,7 +21,7 @@ final class PestInstallCommand extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'pest:install';
|
protected $signature = 'pest:install {--test-directory=tests : The name of the tests directory}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@ -35,15 +36,14 @@ final class PestInstallCommand extends Command
|
|||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
/* @phpstan-ignore-next-line */
|
/* @phpstan-ignore-next-line */
|
||||||
$pest = base_path('tests/Pest.php');
|
TestSuite::getInstance(base_path(), $this->option('test-directory'));
|
||||||
/* @phpstan-ignore-next-line */
|
|
||||||
$helpers = base_path('tests/Helpers.php');
|
|
||||||
$stubs = $this->isLumen() ? 'stubs/Lumen' : 'stubs/Laravel';
|
|
||||||
|
|
||||||
foreach ([$pest, $helpers] as $file) {
|
/* @phpstan-ignore-next-line */
|
||||||
if (File::exists($file)) {
|
$pest = base_path(testDirectory('Pest.php'));
|
||||||
throw new InvalidConsoleArgument(sprintf('%s already exist', $file));
|
$stubs = 'stubs/Laravel';
|
||||||
}
|
|
||||||
|
if (File::exists($pest)) {
|
||||||
|
throw new InvalidConsoleArgument(sprintf('%s already exist', $pest));
|
||||||
}
|
}
|
||||||
|
|
||||||
File::copy(implode(DIRECTORY_SEPARATOR, [
|
File::copy(implode(DIRECTORY_SEPARATOR, [
|
||||||
@ -52,26 +52,10 @@ final class PestInstallCommand extends Command
|
|||||||
'Pest.php',
|
'Pest.php',
|
||||||
]), $pest);
|
]), $pest);
|
||||||
|
|
||||||
File::copy(implode(DIRECTORY_SEPARATOR, [
|
|
||||||
dirname(__DIR__, 3),
|
|
||||||
$stubs,
|
|
||||||
'Helpers.php',
|
|
||||||
]), $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.');
|
|
||||||
|
|
||||||
if (!(bool) $this->option('no-interaction')) {
|
if (!(bool) $this->option('no-interaction')) {
|
||||||
(new Thanks($this->output))();
|
(new Thanks($this->output))();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if this is a Lumen application.
|
|
||||||
*/
|
|
||||||
private function isLumen(): bool
|
|
||||||
{
|
|
||||||
/* @phpstan-ignore-next-line */
|
|
||||||
return Str::startsWith(app()->version(), 'Lumen');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,8 @@ 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;
|
use Pest\Support\Str;
|
||||||
|
use function Pest\testDirectory;
|
||||||
|
use Pest\TestSuite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -19,7 +21,7 @@ final class PestTestCommand extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'pest:test {name : The name of the file} {--unit : Create a unit test}';
|
protected $signature = 'pest:test {name : The name of the file} {--unit : Create a unit test} {--dusk : Create a Dusk test} {--test-directory=tests : The name of the tests directory}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@ -33,12 +35,16 @@ final class PestTestCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
|
TestSuite::getInstance(base_path(), $this->option('test-directory'));
|
||||||
|
|
||||||
/** @var string $name */
|
/** @var string $name */
|
||||||
$name = $this->argument('name');
|
$name = $this->argument('name');
|
||||||
|
|
||||||
$type = ((bool) $this->option('unit')) ? 'Unit' : 'Feature';
|
$type = ((bool) $this->option('unit')) ? 'Unit' : (((bool) $this->option('dusk')) ? 'Browser' : 'Feature');
|
||||||
|
|
||||||
$relativePath = sprintf('tests/%s/%s.php',
|
$relativePath = sprintf(
|
||||||
|
testDirectory('%s/%s.php'),
|
||||||
$type,
|
$type,
|
||||||
ucfirst($name)
|
ucfirst($name)
|
||||||
);
|
);
|
||||||
|
|||||||
@ -5,7 +5,9 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Laravel;
|
namespace Pest\Laravel;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Laravel\Dusk\Console\DuskCommand;
|
||||||
use Pest\Laravel\Commands\PestDatasetCommand;
|
use Pest\Laravel\Commands\PestDatasetCommand;
|
||||||
|
use Pest\Laravel\Commands\PestDuskCommand;
|
||||||
use Pest\Laravel\Commands\PestInstallCommand;
|
use Pest\Laravel\Commands\PestInstallCommand;
|
||||||
use Pest\Laravel\Commands\PestTestCommand;
|
use Pest\Laravel\Commands\PestTestCommand;
|
||||||
|
|
||||||
@ -22,6 +24,12 @@ final class PestServiceProvider extends ServiceProvider
|
|||||||
PestTestCommand::class,
|
PestTestCommand::class,
|
||||||
PestDatasetCommand::class,
|
PestDatasetCommand::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (class_exists(DuskCommand::class)) {
|
||||||
|
$this->commands([
|
||||||
|
PestDuskCommand::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
430
src/Logging/JUnit.php
Normal file
430
src/Logging/JUnit.php
Normal file
@ -0,0 +1,430 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
/*
|
||||||
|
* This file is part of PHPUnit.
|
||||||
|
*
|
||||||
|
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Pest\Logging;
|
||||||
|
|
||||||
|
use function class_exists;
|
||||||
|
use DOMDocument;
|
||||||
|
use DOMElement;
|
||||||
|
use Exception;
|
||||||
|
use function get_class;
|
||||||
|
use function method_exists;
|
||||||
|
use Pest\Concerns\TestCase;
|
||||||
|
use PHPUnit\Framework\AssertionFailedError;
|
||||||
|
use PHPUnit\Framework\ExceptionWrapper;
|
||||||
|
use PHPUnit\Framework\SelfDescribing;
|
||||||
|
use PHPUnit\Framework\Test;
|
||||||
|
use PHPUnit\Framework\TestFailure;
|
||||||
|
use PHPUnit\Framework\TestListener;
|
||||||
|
use PHPUnit\Framework\TestSuite;
|
||||||
|
use PHPUnit\Framework\Warning;
|
||||||
|
use PHPUnit\Util\Filter;
|
||||||
|
use PHPUnit\Util\Printer;
|
||||||
|
use PHPUnit\Util\Xml;
|
||||||
|
use ReflectionClass;
|
||||||
|
use ReflectionException;
|
||||||
|
use function sprintf;
|
||||||
|
use function str_replace;
|
||||||
|
use Throwable;
|
||||||
|
use function trim;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal This class is not covered by the backward compatibility promise for PHPUnit
|
||||||
|
*/
|
||||||
|
final class JUnit extends Printer implements TestListener
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var DOMDocument
|
||||||
|
*/
|
||||||
|
private $document;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DOMElement
|
||||||
|
*/
|
||||||
|
private $root;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DOMElement[]
|
||||||
|
*/
|
||||||
|
private $testSuites = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int[]
|
||||||
|
*/
|
||||||
|
private $testSuiteTests = [0];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int[]
|
||||||
|
*/
|
||||||
|
private $testSuiteAssertions = [0];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int[]
|
||||||
|
*/
|
||||||
|
private $testSuiteErrors = [0];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int[]
|
||||||
|
*/
|
||||||
|
private $testSuiteWarnings = [0];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int[]
|
||||||
|
*/
|
||||||
|
private $testSuiteFailures = [0];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int[]
|
||||||
|
*/
|
||||||
|
private $testSuiteSkipped = [0];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int[]|float[]
|
||||||
|
*/
|
||||||
|
private $testSuiteTimes = [0];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $testSuiteLevel = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DOMElement|null
|
||||||
|
*/
|
||||||
|
private $currentTestCase;
|
||||||
|
|
||||||
|
public function __construct(string $out)
|
||||||
|
{
|
||||||
|
$this->document = new DOMDocument('1.0', 'UTF-8');
|
||||||
|
$this->document->formatOutput = true;
|
||||||
|
|
||||||
|
$this->root = $this->document->createElement('testsuites');
|
||||||
|
$this->document->appendChild($this->root);
|
||||||
|
|
||||||
|
parent::__construct($out);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flush buffer and close output.
|
||||||
|
*/
|
||||||
|
public function flush(): void
|
||||||
|
{
|
||||||
|
$this->write($this->getXML());
|
||||||
|
|
||||||
|
parent::flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An error occurred.
|
||||||
|
*/
|
||||||
|
public function addError(Test $test, Throwable $t, float $time): void
|
||||||
|
{
|
||||||
|
$this->doAddFault($test, $t, 'error');
|
||||||
|
$this->testSuiteErrors[$this->testSuiteLevel]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A warning occurred.
|
||||||
|
*/
|
||||||
|
public function addWarning(Test $test, Warning $e, float $time): void
|
||||||
|
{
|
||||||
|
$this->doAddFault($test, $e, 'warning');
|
||||||
|
$this->testSuiteWarnings[$this->testSuiteLevel]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A failure occurred.
|
||||||
|
*/
|
||||||
|
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
|
||||||
|
{
|
||||||
|
$this->doAddFault($test, $e, 'failure');
|
||||||
|
$this->testSuiteFailures[$this->testSuiteLevel]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Incomplete test.
|
||||||
|
*/
|
||||||
|
public function addIncompleteTest(Test $test, Throwable $t, float $time): void
|
||||||
|
{
|
||||||
|
$this->doAddSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Risky test.
|
||||||
|
*/
|
||||||
|
public function addRiskyTest(Test $test, Throwable $t, float $time): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Skipped test.
|
||||||
|
*/
|
||||||
|
public function addSkippedTest(Test $test, Throwable $t, float $time): void
|
||||||
|
{
|
||||||
|
$this->doAddSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
|
public function startTestSuite(TestSuite $suite): void
|
||||||
|
{
|
||||||
|
$testSuite = $this->document->createElement('testsuite');
|
||||||
|
$testSuite->setAttribute('name', $suite->getName());
|
||||||
|
|
||||||
|
if (class_exists($suite->getName(), false)) {
|
||||||
|
try {
|
||||||
|
$class = new ReflectionClass($suite->getName());
|
||||||
|
|
||||||
|
if ($class->hasMethod('__getFileName')) {
|
||||||
|
$fileName = $class->getMethod('__getFileName')->invoke(null);
|
||||||
|
} else {
|
||||||
|
$fileName = $class->getFileName();
|
||||||
|
}
|
||||||
|
|
||||||
|
$testSuite->setAttribute('file', $fileName);
|
||||||
|
} catch (ReflectionException $e) {
|
||||||
|
// @ignoreException
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->testSuiteLevel > 0) {
|
||||||
|
$this->testSuites[$this->testSuiteLevel]->appendChild($testSuite);
|
||||||
|
} else {
|
||||||
|
$this->root->appendChild($testSuite);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->testSuiteLevel++;
|
||||||
|
$this->testSuites[$this->testSuiteLevel] = $testSuite;
|
||||||
|
$this->testSuiteTests[$this->testSuiteLevel] = 0;
|
||||||
|
$this->testSuiteAssertions[$this->testSuiteLevel] = 0;
|
||||||
|
$this->testSuiteErrors[$this->testSuiteLevel] = 0;
|
||||||
|
$this->testSuiteWarnings[$this->testSuiteLevel] = 0;
|
||||||
|
$this->testSuiteFailures[$this->testSuiteLevel] = 0;
|
||||||
|
$this->testSuiteSkipped[$this->testSuiteLevel] = 0;
|
||||||
|
$this->testSuiteTimes[$this->testSuiteLevel] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
|
public function endTestSuite(TestSuite $suite): void
|
||||||
|
{
|
||||||
|
$this->testSuites[$this->testSuiteLevel]->setAttribute(
|
||||||
|
'tests',
|
||||||
|
(string) $this->testSuiteTests[$this->testSuiteLevel]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->testSuites[$this->testSuiteLevel]->setAttribute(
|
||||||
|
'assertions',
|
||||||
|
(string) $this->testSuiteAssertions[$this->testSuiteLevel]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->testSuites[$this->testSuiteLevel]->setAttribute(
|
||||||
|
'errors',
|
||||||
|
(string) $this->testSuiteErrors[$this->testSuiteLevel]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->testSuites[$this->testSuiteLevel]->setAttribute(
|
||||||
|
'warnings',
|
||||||
|
(string) $this->testSuiteWarnings[$this->testSuiteLevel]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->testSuites[$this->testSuiteLevel]->setAttribute(
|
||||||
|
'failures',
|
||||||
|
(string) $this->testSuiteFailures[$this->testSuiteLevel]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->testSuites[$this->testSuiteLevel]->setAttribute(
|
||||||
|
'skipped',
|
||||||
|
(string) $this->testSuiteSkipped[$this->testSuiteLevel]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->testSuites[$this->testSuiteLevel]->setAttribute(
|
||||||
|
'time',
|
||||||
|
sprintf('%F', $this->testSuiteTimes[$this->testSuiteLevel])
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($this->testSuiteLevel > 1) {
|
||||||
|
$this->testSuiteTests[$this->testSuiteLevel - 1] += $this->testSuiteTests[$this->testSuiteLevel];
|
||||||
|
$this->testSuiteAssertions[$this->testSuiteLevel - 1] += $this->testSuiteAssertions[$this->testSuiteLevel];
|
||||||
|
$this->testSuiteErrors[$this->testSuiteLevel - 1] += $this->testSuiteErrors[$this->testSuiteLevel];
|
||||||
|
$this->testSuiteWarnings[$this->testSuiteLevel - 1] += $this->testSuiteWarnings[$this->testSuiteLevel];
|
||||||
|
$this->testSuiteFailures[$this->testSuiteLevel - 1] += $this->testSuiteFailures[$this->testSuiteLevel];
|
||||||
|
$this->testSuiteSkipped[$this->testSuiteLevel - 1] += $this->testSuiteSkipped[$this->testSuiteLevel];
|
||||||
|
$this->testSuiteTimes[$this->testSuiteLevel - 1] += $this->testSuiteTimes[$this->testSuiteLevel];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->testSuiteLevel--;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A test started.
|
||||||
|
*
|
||||||
|
* @param Test|TestCase $test
|
||||||
|
*/
|
||||||
|
public function startTest(Test $test): void
|
||||||
|
{
|
||||||
|
$usesDataprovider = false;
|
||||||
|
|
||||||
|
if (method_exists($test, 'usesDataProvider')) {
|
||||||
|
$usesDataprovider = $test->usesDataProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
$testCase = $this->document->createElement('testcase');
|
||||||
|
$testCase->setAttribute('name', $test->getName());
|
||||||
|
|
||||||
|
try {
|
||||||
|
$class = new ReflectionClass($test);
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
|
} catch (ReflectionException $e) {
|
||||||
|
// @phpstan-ignore-next-line
|
||||||
|
throw new Exception($e->getMessage(), (int) $e->getCode(), $e);
|
||||||
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
|
$methodName = $test->getName(!$usesDataprovider);
|
||||||
|
|
||||||
|
if ($class->hasMethod($methodName)) {
|
||||||
|
try {
|
||||||
|
$method = $class->getMethod($methodName);
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
|
} catch (ReflectionException $e) {
|
||||||
|
// @phpstan-ignore-next-line
|
||||||
|
throw new Exception($e->getMessage(), (int) $e->getCode(), $e);
|
||||||
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
|
$testCase->setAttribute('class', $class->getName());
|
||||||
|
$testCase->setAttribute('classname', str_replace('\\', '.', $class->getName()));
|
||||||
|
$fileName = $class->getFileName();
|
||||||
|
if ($fileName !== false) {
|
||||||
|
$testCase->setAttribute('file', $fileName);
|
||||||
|
}
|
||||||
|
$testCase->setAttribute('line', (string) $method->getStartLine());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TeamCity::isPestTest($test)) {
|
||||||
|
$testCase->setAttribute('class', $test->getPrintableTestCaseName());
|
||||||
|
$testCase->setAttribute('classname', str_replace('\\', '.', $test->getPrintableTestCaseName()));
|
||||||
|
// @phpstan-ignore-next-line
|
||||||
|
$testCase->setAttribute('file', $test->__getFileName());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->currentTestCase = $testCase;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A test ended.
|
||||||
|
*/
|
||||||
|
public function endTest(Test $test, float $time): void
|
||||||
|
{
|
||||||
|
$numAssertions = 0;
|
||||||
|
|
||||||
|
if (method_exists($test, 'getNumAssertions')) {
|
||||||
|
$numAssertions = $test->getNumAssertions();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;
|
||||||
|
|
||||||
|
if ($this->currentTestCase !== null) {
|
||||||
|
$this->currentTestCase->setAttribute(
|
||||||
|
'assertions',
|
||||||
|
(string) $numAssertions
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->currentTestCase->setAttribute(
|
||||||
|
'time',
|
||||||
|
sprintf('%F', $time)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->testSuites[$this->testSuiteLevel]->appendChild(
|
||||||
|
$this->currentTestCase
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->testSuiteTests[$this->testSuiteLevel]++;
|
||||||
|
$this->testSuiteTimes[$this->testSuiteLevel] += $time;
|
||||||
|
|
||||||
|
$testOutput = '';
|
||||||
|
|
||||||
|
if (method_exists($test, 'hasOutput') && method_exists($test, 'getActualOutput')) {
|
||||||
|
$testOutput = $test->hasOutput() ? $test->getActualOutput() : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($testOutput !== '') {
|
||||||
|
$systemOut = $this->document->createElement(
|
||||||
|
'system-out',
|
||||||
|
Xml::prepareString($testOutput)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($this->currentTestCase !== null) {
|
||||||
|
$this->currentTestCase->appendChild($systemOut);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->currentTestCase = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the XML as a string.
|
||||||
|
*/
|
||||||
|
public function getXML(): string
|
||||||
|
{
|
||||||
|
$xml = $this->document->saveXML();
|
||||||
|
if ($xml === false) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $xml;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function doAddFault(Test $test, Throwable $t, string $type): void
|
||||||
|
{
|
||||||
|
if ($this->currentTestCase === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($test instanceof SelfDescribing) {
|
||||||
|
$buffer = $test->toString() . "\n";
|
||||||
|
} else {
|
||||||
|
$buffer = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$buffer .= trim(
|
||||||
|
TestFailure::exceptionToString($t) . "\n" .
|
||||||
|
Filter::getFilteredStacktrace($t)
|
||||||
|
);
|
||||||
|
|
||||||
|
$fault = $this->document->createElement(
|
||||||
|
$type,
|
||||||
|
Xml::prepareString($buffer)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($t instanceof ExceptionWrapper) {
|
||||||
|
$fault->setAttribute('type', $t->getClassName());
|
||||||
|
} else {
|
||||||
|
$fault->setAttribute('type', get_class($t));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->currentTestCase->appendChild($fault);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function doAddSkipped(): void
|
||||||
|
{
|
||||||
|
if ($this->currentTestCase === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$skipped = $this->document->createElement('skipped');
|
||||||
|
|
||||||
|
$this->currentTestCase->appendChild($skipped);
|
||||||
|
|
||||||
|
$this->testSuiteSkipped[$this->testSuiteLevel]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Pest;
|
namespace Pest\Logging;
|
||||||
|
|
||||||
use function getmypid;
|
use function getmypid;
|
||||||
use Pest\Concerns\TestCase;
|
use Pest\Concerns\TestCase;
|
||||||
@ -24,7 +24,6 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
private const DURATION = 'duration';
|
private const DURATION = 'duration';
|
||||||
private const TEST_SUITE_STARTED = 'testSuiteStarted';
|
private const TEST_SUITE_STARTED = 'testSuiteStarted';
|
||||||
private const TEST_SUITE_FINISHED = 'testSuiteFinished';
|
private const TEST_SUITE_FINISHED = 'testSuiteFinished';
|
||||||
private const TEST_FAILED = 'testFailed';
|
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $flowId;
|
private $flowId;
|
||||||
@ -57,7 +56,7 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
/** @phpstan-ignore-next-line */
|
/** @phpstan-ignore-next-line */
|
||||||
public function startTestSuite(TestSuite $suite): void
|
public function startTestSuite(TestSuite $suite): void
|
||||||
{
|
{
|
||||||
$this->flowId = getmypid();
|
$this->flowId = (int) getmypid();
|
||||||
|
|
||||||
if (!$this->isSummaryTestCountPrinted) {
|
if (!$this->isSummaryTestCountPrinted) {
|
||||||
$this->printEvent(
|
$this->printEvent(
|
||||||
@ -122,7 +121,7 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
|
|
||||||
$this->printEvent('testStarted', [
|
$this->printEvent('testStarted', [
|
||||||
self::NAME => $test->getName(),
|
self::NAME => $test->getName(),
|
||||||
/* @phpstan-ignore-next-line */
|
// @phpstan-ignore-next-line
|
||||||
self::LOCATION_HINT => self::PROTOCOL . $test->toString(),
|
self::LOCATION_HINT => self::PROTOCOL . $test->toString(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -149,19 +148,7 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
*/
|
*/
|
||||||
public function addError(Test $test, Throwable $t, float $time): void
|
public function addError(Test $test, Throwable $t, float $time): void
|
||||||
{
|
{
|
||||||
if (!TeamCity::isPestTest($test)) {
|
$this->phpunitTeamCity->addError($test, $t, $time);
|
||||||
$this->phpunitTeamCity->addError($test, $t, $time);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->printEvent(
|
|
||||||
self::TEST_FAILED, [
|
|
||||||
self::NAME => $test->getName(),
|
|
||||||
'message' => $t->getMessage(),
|
|
||||||
'details' => $t->getTraceAsString(),
|
|
||||||
self::DURATION => self::toMilliseconds($time),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -171,19 +158,7 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
*/
|
*/
|
||||||
public function addWarning(Test $test, Warning $e, float $time): void
|
public function addWarning(Test $test, Warning $e, float $time): void
|
||||||
{
|
{
|
||||||
if (!TeamCity::isPestTest($test)) {
|
$this->phpunitTeamCity->addWarning($test, $e, $time);
|
||||||
$this->phpunitTeamCity->addWarning($test, $e, $time);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->printEvent(
|
|
||||||
self::TEST_FAILED, [
|
|
||||||
self::NAME => $test->getName(),
|
|
||||||
'message' => $e->getMessage(),
|
|
||||||
'details' => $e->getTraceAsString(),
|
|
||||||
self::DURATION => self::toMilliseconds($time),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
|
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
|
||||||
@ -228,8 +203,11 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
return (int) round($time * 1000);
|
return (int) round($time * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function isPestTest(Test $test): bool
|
public static function isPestTest(Test $test): bool
|
||||||
{
|
{
|
||||||
return in_array(TestCase::class, class_uses($test), true);
|
/** @var array<string, string> $uses */
|
||||||
|
$uses = class_uses($test);
|
||||||
|
|
||||||
|
return in_array(TestCase::class, $uses, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,100 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Pest;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
use SebastianBergmann\Exporter\Exporter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* @mixin Expectation
|
|
||||||
*/
|
|
||||||
final class OppositeExpectation
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Expectation
|
|
||||||
*/
|
|
||||||
private $original;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new opposite expectation.
|
|
||||||
*/
|
|
||||||
public function __construct(Expectation $original)
|
|
||||||
{
|
|
||||||
$this->original = $original;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the value array not has the provided $keys.
|
|
||||||
*
|
|
||||||
* @param array<int, int|string> $keys
|
|
||||||
*/
|
|
||||||
public function toHaveKeys(array $keys): Expectation
|
|
||||||
{
|
|
||||||
foreach ($keys as $key) {
|
|
||||||
try {
|
|
||||||
$this->original->toHaveKey($key);
|
|
||||||
} catch (ExpectationFailedException $e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->throwExpectationFailedExpection('toHaveKey', [$key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->original;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle dynamic method calls into the original expectation.
|
|
||||||
*
|
|
||||||
* @param array<int, mixed> $arguments
|
|
||||||
*/
|
|
||||||
public function __call(string $name, array $arguments): Expectation
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
/* @phpstan-ignore-next-line */
|
|
||||||
$this->original->{$name}(...$arguments);
|
|
||||||
} catch (ExpectationFailedException $e) {
|
|
||||||
return $this->original;
|
|
||||||
}
|
|
||||||
|
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
$this->throwExpectationFailedExpection($name, $arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle dynamic properties gets into the original expectation.
|
|
||||||
*/
|
|
||||||
public function __get(string $name): Expectation
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
/* @phpstan-ignore-next-line */
|
|
||||||
$this->original->{$name};
|
|
||||||
} catch (ExpectationFailedException $e) {
|
|
||||||
return $this->original;
|
|
||||||
}
|
|
||||||
|
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
$this->throwExpectationFailedExpection($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new expectation failed exception
|
|
||||||
* with a nice readable message.
|
|
||||||
*
|
|
||||||
* @param array<int, mixed> $arguments
|
|
||||||
*/
|
|
||||||
private function throwExpectationFailedExpection(string $name, array $arguments = []): void
|
|
||||||
{
|
|
||||||
$exporter = new Exporter();
|
|
||||||
|
|
||||||
$toString = function ($argument) use ($exporter): string {
|
|
||||||
return $exporter->shortenedExport($argument);
|
|
||||||
};
|
|
||||||
|
|
||||||
throw new ExpectationFailedException(sprintf('Expecting %s not %s %s.', $toString($this->original->value), strtolower((string) preg_replace('/(?<!\ )[A-Z]/', ' $0', $name)), implode(' ', array_map(function ($argument) use ($toString): string { return $toString($argument); }, $arguments))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -9,11 +9,10 @@ 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 PHPUnit\Framework\ExecutionOrderDependency;
|
|
||||||
use SebastianBergmann\Exporter\Exporter;
|
use SebastianBergmann\Exporter\Exporter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method \Pest\Expectation expect(mixed $value)
|
* @method \Pest\Expectations\Expectation expect(mixed $value)
|
||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@ -78,7 +77,7 @@ final class TestCall
|
|||||||
* Runs the current test multiple times with
|
* Runs the current test multiple times with
|
||||||
* each item of the given `iterable`.
|
* each item of the given `iterable`.
|
||||||
*
|
*
|
||||||
* @param \Closure|iterable<int, mixed>|string $data
|
* @param \Closure|iterable<int|string, mixed>|string $data
|
||||||
*/
|
*/
|
||||||
public function with($data): TestCall
|
public function with($data): TestCall
|
||||||
{
|
{
|
||||||
@ -92,15 +91,9 @@ final class TestCall
|
|||||||
*/
|
*/
|
||||||
public function depends(string ...$tests): TestCall
|
public function depends(string ...$tests): TestCall
|
||||||
{
|
{
|
||||||
$className = $this->testCaseFactory->getClassName();
|
|
||||||
|
|
||||||
$tests = array_map(function (string $test) use ($className): ExecutionOrderDependency {
|
|
||||||
return ExecutionOrderDependency::createFromDependsAnnotation($className, $test);
|
|
||||||
}, $tests);
|
|
||||||
|
|
||||||
$this->testCaseFactory
|
$this->testCaseFactory
|
||||||
->factoryProxies
|
->factoryProxies
|
||||||
->add(Backtrace::file(), Backtrace::line(), 'setDependencies', [$tests]);
|
->add(Backtrace::file(), Backtrace::line(), 'addDependencies', [$tests]);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\PendingObjects;
|
namespace Pest\PendingObjects;
|
||||||
|
|
||||||
use Pest\Exceptions\InvalidUsesPath;
|
use Closure;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,6 +12,20 @@ use Pest\TestSuite;
|
|||||||
*/
|
*/
|
||||||
final class UsesCall
|
final class UsesCall
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Contains a global before each hook closure to be executed.
|
||||||
|
*
|
||||||
|
* Array indices here matter. They are mapped as follows:
|
||||||
|
*
|
||||||
|
* - `0` => `beforeAll`
|
||||||
|
* - `1` => `beforeEach`
|
||||||
|
* - `2` => `afterEach`
|
||||||
|
* - `3` => `afterAll`
|
||||||
|
*
|
||||||
|
* @var array<int, Closure>
|
||||||
|
*/
|
||||||
|
private $hooks = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the class and traits.
|
* Holds the class and traits.
|
||||||
*
|
*
|
||||||
@ -77,14 +91,13 @@ final class UsesCall
|
|||||||
]);
|
]);
|
||||||
}, $targets);
|
}, $targets);
|
||||||
|
|
||||||
$this->targets = array_map(function ($target): string {
|
$this->targets = array_reduce($targets, function (array $accumulator, string $target): array {
|
||||||
$isValid = is_dir($target) || file_exists($target);
|
if (is_dir($target) || file_exists($target)) {
|
||||||
if (!$isValid) {
|
$accumulator[] = (string) realpath($target);
|
||||||
throw new InvalidUsesPath($target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) realpath($target);
|
return $accumulator;
|
||||||
}, $targets);
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,11 +110,56 @@ final class UsesCall
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the global beforeAll test hook.
|
||||||
|
*/
|
||||||
|
public function beforeAll(Closure $hook): UsesCall
|
||||||
|
{
|
||||||
|
$this->hooks[0] = $hook;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the global beforeEach test hook.
|
||||||
|
*/
|
||||||
|
public function beforeEach(Closure $hook): UsesCall
|
||||||
|
{
|
||||||
|
$this->hooks[1] = $hook;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the global afterEach test hook.
|
||||||
|
*/
|
||||||
|
public function afterEach(Closure $hook): UsesCall
|
||||||
|
{
|
||||||
|
$this->hooks[2] = $hook;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the global afterAll test hook.
|
||||||
|
*/
|
||||||
|
public function afterAll(Closure $hook): UsesCall
|
||||||
|
{
|
||||||
|
$this->hooks[3] = $hook;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatch the creation of uses.
|
* Dispatch the creation of uses.
|
||||||
*/
|
*/
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
TestSuite::getInstance()->tests->use($this->classAndTraits, $this->groups, $this->targets);
|
TestSuite::getInstance()->tests->use(
|
||||||
|
$this->classAndTraits,
|
||||||
|
$this->groups,
|
||||||
|
$this->targets,
|
||||||
|
$this->hooks,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,5 +6,10 @@ namespace Pest;
|
|||||||
|
|
||||||
function version(): string
|
function version(): string
|
||||||
{
|
{
|
||||||
return '0.3.1';
|
return '1.2.1';
|
||||||
|
}
|
||||||
|
|
||||||
|
function testDirectory(string $file = ''): string
|
||||||
|
{
|
||||||
|
return TestSuite::getInstance()->testPath . '/' . $file;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ final class Plugin
|
|||||||
public static function uses(string ...$traits): void
|
public static function uses(string ...$traits): void
|
||||||
{
|
{
|
||||||
self::$callables[] = function () use ($traits): void {
|
self::$callables[] = function () use ($traits): void {
|
||||||
uses(...$traits)->in(TestSuite::getInstance()->rootPath . DIRECTORY_SEPARATOR . 'tests');
|
uses(...$traits)->in(TestSuite::getInstance()->rootPath . DIRECTORY_SEPARATOR . testDirectory());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Repositories;
|
namespace Pest\Repositories;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
use Pest\Exceptions\ShouldNotHappen;
|
use Pest\Exceptions\ShouldNotHappen;
|
||||||
use Pest\Exceptions\TestAlreadyExist;
|
use Pest\Exceptions\TestAlreadyExist;
|
||||||
use Pest\Exceptions\TestCaseAlreadyInUse;
|
use Pest\Exceptions\TestCaseAlreadyInUse;
|
||||||
@ -24,7 +25,7 @@ final class TestRepository
|
|||||||
private $state = [];
|
private $state = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array<string, array<int, array<int, string>>>
|
* @var array<string, array<int, array<int, string|Closure>>>
|
||||||
*/
|
*/
|
||||||
private $uses = [];
|
private $uses = [];
|
||||||
|
|
||||||
@ -46,12 +47,13 @@ final class TestRepository
|
|||||||
};
|
};
|
||||||
|
|
||||||
foreach ($this->uses as $path => $uses) {
|
foreach ($this->uses as $path => $uses) {
|
||||||
[$classOrTraits, $groups] = $uses;
|
[$classOrTraits, $groups, $hooks] = $uses;
|
||||||
$setClassName = function (TestCaseFactory $testCase, string $key) use ($path, $classOrTraits, $groups, $startsWith): void {
|
|
||||||
|
$setClassName = function (TestCaseFactory $testCase, string $key) use ($path, $classOrTraits, $groups, $startsWith, $hooks): void {
|
||||||
[$filename] = explode('@', $key);
|
[$filename] = explode('@', $key);
|
||||||
|
|
||||||
if ((!is_dir($path) && $filename === $path) || (is_dir($path) && $startsWith($filename, $path))) {
|
if ((!is_dir($path) && $filename === $path) || (is_dir($path) && $startsWith($filename, $path))) {
|
||||||
foreach ($classOrTraits as $class) {
|
foreach ($classOrTraits as $class) { /** @var string $class */
|
||||||
if (class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
if ($testCase->class !== TestCase::class) {
|
if ($testCase->class !== TestCase::class) {
|
||||||
throw new TestCaseAlreadyInUse($testCase->class, $class, $filename);
|
throw new TestCaseAlreadyInUse($testCase->class, $class, $filename);
|
||||||
@ -62,10 +64,12 @@ final class TestRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$testCase
|
// IDEA: Consider set the real lines on these.
|
||||||
->factoryProxies
|
$testCase->factoryProxies->add($filename, 0, 'addGroups', [$groups]);
|
||||||
// Consider set the real line here.
|
$testCase->factoryProxies->add($filename, 0, 'addBeforeAll', [$hooks[0] ?? null]);
|
||||||
->add($filename, 0, 'addGroups', [$groups]);
|
$testCase->factoryProxies->add($filename, 0, 'addBeforeEach', [$hooks[1] ?? null]);
|
||||||
|
$testCase->factoryProxies->add($filename, 0, 'addAfterEach', [$hooks[2] ?? null]);
|
||||||
|
$testCase->factoryProxies->add($filename, 0, 'addAfterAll', [$hooks[3] ?? null]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -81,7 +85,7 @@ final class TestRepository
|
|||||||
$state = count($onlyState) > 0 ? $onlyState : $this->state;
|
$state = count($onlyState) > 0 ? $onlyState : $this->state;
|
||||||
|
|
||||||
foreach ($state as $testFactory) {
|
foreach ($state as $testFactory) {
|
||||||
/* @var TestCaseFactory $testFactory */
|
/** @var TestCaseFactory $testFactory */
|
||||||
$tests = $testFactory->build($testSuite);
|
$tests = $testFactory->build($testSuite);
|
||||||
foreach ($tests as $test) {
|
foreach ($tests as $test) {
|
||||||
$each($test);
|
$each($test);
|
||||||
@ -92,11 +96,12 @@ final class TestRepository
|
|||||||
/**
|
/**
|
||||||
* Uses the given `$testCaseClass` on the given `$paths`.
|
* Uses the given `$testCaseClass` on the given `$paths`.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $classOrTraits
|
* @param array<int, string> $classOrTraits
|
||||||
* @param array<int, string> $groups
|
* @param array<int, string> $groups
|
||||||
* @param array<int, string> $paths
|
* @param array<int, string> $paths
|
||||||
|
* @param array<int, Closure> $hooks
|
||||||
*/
|
*/
|
||||||
public function use(array $classOrTraits, array $groups, array $paths): void
|
public function use(array $classOrTraits, array $groups, array $paths, array $hooks): void
|
||||||
{
|
{
|
||||||
foreach ($classOrTraits as $classOrTrait) {
|
foreach ($classOrTraits as $classOrTrait) {
|
||||||
if (!class_exists($classOrTrait) && !trait_exists($classOrTrait)) {
|
if (!class_exists($classOrTrait) && !trait_exists($classOrTrait)) {
|
||||||
@ -109,9 +114,10 @@ final class TestRepository
|
|||||||
$this->uses[$path] = [
|
$this->uses[$path] = [
|
||||||
array_merge($this->uses[$path][0], $classOrTraits),
|
array_merge($this->uses[$path][0], $classOrTraits),
|
||||||
array_merge($this->uses[$path][1], $groups),
|
array_merge($this->uses[$path][1], $groups),
|
||||||
|
$this->uses[$path][2] + $hooks, // NOTE: array_merge will destroy numeric indices
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
$this->uses[$path] = [$classOrTraits, $groups];
|
$this->uses[$path] = [$classOrTraits, $groups, $hooks];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,13 +12,28 @@ use Closure;
|
|||||||
final class ChainableClosure
|
final class ChainableClosure
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Calls the given `$closure` and chains the the `$next` closure.
|
* Calls the given `$closure` and chains the `$next` closure.
|
||||||
*/
|
*/
|
||||||
public static function from(Closure $closure, Closure $next): Closure
|
public static function from(Closure $closure, Closure $next): Closure
|
||||||
{
|
{
|
||||||
return function () use ($closure, $next): void {
|
return function () use ($closure, $next): void {
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
call_user_func_array(Closure::bind($closure, $this, get_class($this)), func_get_args());
|
call_user_func_array(Closure::bind($closure, $this, get_class($this)), func_get_args());
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
call_user_func_array(Closure::bind($next, $this, get_class($this)), func_get_args());
|
call_user_func_array(Closure::bind($next, $this, get_class($this)), func_get_args());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call the given static `$closure` and chains the `$next` closure.
|
||||||
|
*/
|
||||||
|
public static function fromStatic(Closure $closure, Closure $next): Closure
|
||||||
|
{
|
||||||
|
return static function () use ($closure, $next): void {
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
|
call_user_func_array(Closure::bind($closure, null, self::class), func_get_args());
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
|
call_user_func_array(Closure::bind($next, null, self::class), func_get_args());
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,6 +79,7 @@ final class Container
|
|||||||
|
|
||||||
if ($candidate === null) {
|
if ($candidate === null) {
|
||||||
$type = $param->getType();
|
$type = $param->getType();
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
if ($type !== null && $type->isBuiltin()) {
|
if ($type !== null && $type->isBuiltin()) {
|
||||||
$candidate = $param->getName();
|
$candidate = $param->getName();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -30,7 +30,7 @@ final class HigherOrderMessageCollection
|
|||||||
public function chain(object $target): void
|
public function chain(object $target): void
|
||||||
{
|
{
|
||||||
foreach ($this->messages as $message) {
|
foreach ($this->messages as $message) {
|
||||||
$target = $message->call($target);
|
$target = $message->call($target) ?? $target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,6 @@ use ReflectionException;
|
|||||||
use ReflectionFunction;
|
use ReflectionFunction;
|
||||||
use ReflectionNamedType;
|
use ReflectionNamedType;
|
||||||
use ReflectionParameter;
|
use ReflectionParameter;
|
||||||
use ReflectionProperty;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
|||||||
@ -9,6 +9,25 @@ namespace Pest\Support;
|
|||||||
*/
|
*/
|
||||||
final class Str
|
final class Str
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Pool of alpha-numeric characters for generating (unsafe) random strings
|
||||||
|
* from.
|
||||||
|
*/
|
||||||
|
private const POOL = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a (unsecure & non-cryptographically safe) random alpha-numeric
|
||||||
|
* string value.
|
||||||
|
*
|
||||||
|
* @param int $length the length of the resulting randomized string
|
||||||
|
*
|
||||||
|
* @see https://github.com/laravel/framework/blob/4.2/src/Illuminate/Support/Str.php#L240-L242
|
||||||
|
*/
|
||||||
|
public static function random(int $length = 16): string
|
||||||
|
{
|
||||||
|
return substr(str_shuffle(str_repeat(self::POOL, 5)), 0, $length);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the given `$target` starts with the given `$search`.
|
* Checks if the given `$target` starts with the given `$search`.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -66,6 +66,13 @@ final class TestSuite
|
|||||||
*/
|
*/
|
||||||
public $rootPath;
|
public $rootPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds the test path.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $testPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds an instance of the test suite.
|
* Holds an instance of the test suite.
|
||||||
*
|
*
|
||||||
@ -76,7 +83,7 @@ final class TestSuite
|
|||||||
/**
|
/**
|
||||||
* Creates a new instance of the test suite.
|
* Creates a new instance of the test suite.
|
||||||
*/
|
*/
|
||||||
public function __construct(string $rootPath)
|
public function __construct(string $rootPath, string $testPath)
|
||||||
{
|
{
|
||||||
$this->beforeAll = new BeforeAllRepository();
|
$this->beforeAll = new BeforeAllRepository();
|
||||||
$this->beforeEach = new BeforeEachRepository();
|
$this->beforeEach = new BeforeEachRepository();
|
||||||
@ -85,15 +92,16 @@ final class TestSuite
|
|||||||
$this->afterAll = new AfterAllRepository();
|
$this->afterAll = new AfterAllRepository();
|
||||||
|
|
||||||
$this->rootPath = (string) realpath($rootPath);
|
$this->rootPath = (string) realpath($rootPath);
|
||||||
|
$this->testPath = $testPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current instance of the test suite.
|
* Returns the current instance of the test suite.
|
||||||
*/
|
*/
|
||||||
public static function getInstance(string $rootPath = null): TestSuite
|
public static function getInstance(string $rootPath = null, string $testPath = null): TestSuite
|
||||||
{
|
{
|
||||||
if (is_string($rootPath)) {
|
if (is_string($rootPath) && is_string($testPath)) {
|
||||||
self::$instance = new TestSuite($rootPath);
|
self::$instance = new TestSuite($rootPath, $testPath);
|
||||||
|
|
||||||
foreach (Plugin::$callables as $callable) {
|
foreach (Plugin::$callables as $callable) {
|
||||||
$callable();
|
$callable();
|
||||||
|
|||||||
10
stubs/Browser.php
Normal file
10
stubs/Browser.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Laravel\Dusk\Browser;
|
||||||
|
|
||||||
|
it('has {name} page', function () {
|
||||||
|
$this->browse(function (Browser $browser) {
|
||||||
|
$browser->visit('/{name}')
|
||||||
|
->assertSee('{name}');
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A basic assert example.
|
|
||||||
*/
|
|
||||||
function assertExample(): void
|
|
||||||
{
|
|
||||||
test()->assertTrue(true);
|
|
||||||
}
|
|
||||||
@ -1,3 +1,45 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Test Case
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
|
||||||
|
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
|
||||||
|
| need to change it using the "uses()" function to bind a different classes or traits.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
uses(Tests\TestCase::class)->in('Feature');
|
uses(Tests\TestCase::class)->in('Feature');
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Expectations
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| When you're writing tests, you often need to check that values meet certain conditions. The
|
||||||
|
| "expect()" function gives you access to a set of "expectations" methods that you can use
|
||||||
|
| to assert different things. Of course, you may extend the Expectation API at any time.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
expect()->extend('toBeOne', function () {
|
||||||
|
return $this->toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Functions
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
|
||||||
|
| project that you don't want to repeat in every file. Here you can also expose helpers as
|
||||||
|
| global functions to help you to reduce the number of lines of code in your test files.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
function something()
|
||||||
|
{
|
||||||
|
// ..
|
||||||
|
}
|
||||||
|
|||||||
@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A basic assert example.
|
|
||||||
*/
|
|
||||||
function assertExample(): void
|
|
||||||
{
|
|
||||||
test()->assertTrue(true);
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
uses(TestCase::class)->in(__DIR__);
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
<?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>
|
|
||||||
<coverage processUncoveredFiles="true">
|
|
||||||
<include>
|
|
||||||
<directory suffix=".php">./app</directory>
|
|
||||||
</include>
|
|
||||||
</coverage>
|
|
||||||
</phpunit>
|
|
||||||
5
tests/.snapshots/help-command.txt
Normal file
5
tests/.snapshots/help-command.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Pest Options:
|
||||||
|
--init Initialise a standard Pest configuration
|
||||||
|
--coverage Enable coverage and output to standard output
|
||||||
|
--min=<N> Set the minimum required coverage percentage (<N>), and fail if not met
|
||||||
|
--group=<name> Only runs tests from the specified group(s)
|
||||||
@ -2,211 +2,6 @@
|
|||||||
PASS Tests\CustomTestCase\ExecutedTest
|
PASS Tests\CustomTestCase\ExecutedTest
|
||||||
✓ that gets executed
|
✓ that gets executed
|
||||||
|
|
||||||
PASS Tests\Expect\not
|
|
||||||
✓ not property calls
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBe
|
|
||||||
✓ expect true → toBeTrue → and false → toBeFalse
|
|
||||||
✓ strict comparisons
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeArray
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeBool
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeCallable
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeDirectory
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeEmpty
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeFalse
|
|
||||||
✓ strict comparisons
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeFile
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeFloat
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeGreatherThan
|
|
||||||
✓ passes
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeGreatherThanOrEqual
|
|
||||||
✓ passes
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeInfinite
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeInstanceOf
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeInt
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeIterable
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeLessThan
|
|
||||||
✓ passes
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeLessThanOrEqual
|
|
||||||
✓ passes
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeNAN
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeNull
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeNumeric
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeObject
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeReadableDirectory
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeReadableFile
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeResource
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeScalar
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeString
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeTrue
|
|
||||||
✓ strict comparisons
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeWritableDirectory
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toBeWritableFile
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toContain
|
|
||||||
✓ passes strings
|
|
||||||
✓ passes arrays
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toEndWith
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toEqual
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toEqualCanonicalizing
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toEqualWithDelta
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toHaveCount
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toHaveKey
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toHaveKeys
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toHaveProperty
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toMatchObject
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Expect\toStartWith
|
|
||||||
✓ pass
|
|
||||||
✓ failures
|
|
||||||
✓ not failures
|
|
||||||
|
|
||||||
PASS Tests\Features\AfterAll
|
PASS Tests\Features\AfterAll
|
||||||
✓ deletes file after all
|
✓ deletes file after all
|
||||||
|
|
||||||
@ -245,6 +40,9 @@
|
|||||||
✓ 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
|
||||||
|
✓ named datasets with data set "one" (1)
|
||||||
|
✓ named datasets with data set "two" (2)
|
||||||
|
✓ named 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) #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 (), true) #2
|
||||||
@ -268,6 +66,7 @@
|
|||||||
|
|
||||||
PASS Tests\Features\HigherOrderTests
|
PASS Tests\Features\HigherOrderTests
|
||||||
✓ it proxies calls to object
|
✓ it proxies calls to object
|
||||||
|
✓ it is capable doing multiple assertions
|
||||||
|
|
||||||
PASS Tests\Features\It
|
PASS Tests\Features\It
|
||||||
✓ it is a test
|
✓ it is a test
|
||||||
@ -292,6 +91,7 @@
|
|||||||
- 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
|
||||||
- it skips with condition and message → skipped because foo
|
- it skips with condition and message → skipped because foo
|
||||||
|
- it skips when skip after assertion
|
||||||
|
|
||||||
PASS Tests\Features\Test
|
PASS Tests\Features\Test
|
||||||
✓ a test
|
✓ a test
|
||||||
@ -303,6 +103,39 @@
|
|||||||
PASS Tests\Fixtures\ExampleTest
|
PASS Tests\Fixtures\ExampleTest
|
||||||
✓ it example 2
|
✓ it example 2
|
||||||
|
|
||||||
|
PASS Tests\Hooks\AfterAllTest
|
||||||
|
✓ global afterAll execution order
|
||||||
|
|
||||||
|
PASS Tests\Hooks\AfterEachTest
|
||||||
|
✓ global afterEach execution order
|
||||||
|
|
||||||
|
PASS Tests\Hooks\BeforeAllTest
|
||||||
|
✓ global beforeAll execution order
|
||||||
|
|
||||||
|
PASS Tests\Hooks\BeforeEachTest
|
||||||
|
✓ global beforeEach execution order
|
||||||
|
|
||||||
|
PASS Tests\PHPUnit\CustomAffixes\InvalidTestName
|
||||||
|
✓ it runs file names like `@#$%^&()-_=+.php`
|
||||||
|
|
||||||
|
PASS Tests\PHPUnit\CustomAffixes\ATestWithSpaces
|
||||||
|
✓ it runs file names like `A Test With Spaces.php`
|
||||||
|
|
||||||
|
PASS Tests\PHPUnit\CustomAffixes\AdditionalFileExtensionspec
|
||||||
|
✓ it runs file names like `AdditionalFileExtension.spec.php`
|
||||||
|
|
||||||
|
PASS Tests\PHPUnit\CustomAffixes\ManyExtensionsclasstest
|
||||||
|
✓ it runs file names like `ManyExtensions.class.test.php`
|
||||||
|
|
||||||
|
PASS Tests\PHPUnit\CustomAffixes\TestCaseWithQuotes
|
||||||
|
✓ it runs file names like `Test 'Case' With Quotes.php`
|
||||||
|
|
||||||
|
PASS Tests\PHPUnit\CustomAffixes\kebabcasespec
|
||||||
|
✓ it runs file names like `kebab-case-spec.php`
|
||||||
|
|
||||||
|
PASS Tests\PHPUnit\CustomAffixes\snakecasespec
|
||||||
|
✓ it runs file names like `snake_case_spec.php`
|
||||||
|
|
||||||
PASS Tests\PHPUnit\CustomTestCase\UsesPerDirectory
|
PASS Tests\PHPUnit\CustomTestCase\UsesPerDirectory
|
||||||
✓ closure was bound to CustomTestCase
|
✓ closure was bound to CustomTestCase
|
||||||
|
|
||||||
@ -333,6 +166,12 @@
|
|||||||
✓ 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\Help
|
||||||
|
✓ it outputs the help information when --help is used
|
||||||
|
|
||||||
|
PASS Tests\Unit\Datasets
|
||||||
|
✓ it show the names of named datasets in their description
|
||||||
|
|
||||||
PASS Tests\Unit\Plugins\Version
|
PASS Tests\Unit\Plugins\Version
|
||||||
✓ it outputs the version when --version is used
|
✓ it outputs the version when --version is used
|
||||||
✓ it do not outputs version when --version is not used
|
✓ it do not outputs version when --version is not used
|
||||||
@ -356,6 +195,9 @@
|
|||||||
PASS Tests\Unit\TestSuite
|
PASS Tests\Unit\TestSuite
|
||||||
✓ it does not allow to add the same test description twice
|
✓ it does not allow to add the same test description twice
|
||||||
|
|
||||||
|
PASS Tests\Visual\Help
|
||||||
|
✓ visual snapshot of help command output
|
||||||
|
|
||||||
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
|
||||||
@ -368,10 +210,16 @@
|
|||||||
PASS Tests\Features\Depends
|
PASS Tests\Features\Depends
|
||||||
✓ first
|
✓ first
|
||||||
✓ second
|
✓ second
|
||||||
|
✓ it asserts true is true
|
||||||
✓ depends
|
✓ depends
|
||||||
✓ depends with ...params
|
✓ depends with ...params
|
||||||
✓ depends with defined arguments
|
✓ depends with defined arguments
|
||||||
✓ depends run test only once
|
✓ depends run test only once
|
||||||
|
✓ depends works with the correct test name
|
||||||
|
|
||||||
Tests: 6 skipped, 220 passed
|
PASS Tests\Features\DependsInheritance
|
||||||
|
✓ it is a test
|
||||||
|
✓ it uses correct parent class
|
||||||
|
|
||||||
|
Tests: 7 skipped, 119 passed
|
||||||
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
test('not property calls', function () {
|
|
||||||
expect(true)
|
|
||||||
->toBeTrue()
|
|
||||||
->not()->toBeFalse()
|
|
||||||
->not->toBeFalse
|
|
||||||
->and(false)
|
|
||||||
->toBeFalse();
|
|
||||||
});
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
expect(true)->toBeTrue()->and(false)->toBeFalse();
|
|
||||||
|
|
||||||
test('strict comparisons', function () {
|
|
||||||
$nuno = new stdClass();
|
|
||||||
$dries = new stdClass();
|
|
||||||
|
|
||||||
expect($nuno)->toBe($nuno)->not->toBe($dries);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(1)->toBe(2);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(1)->not->toBe(1);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect([1, 2, 3])->toBeArray();
|
|
||||||
expect('1, 2, 3')->not->toBeArray();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(null)->toBeArray();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(['a', 'b', 'c'])->not->toBeArray();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(true)->toBeBool();
|
|
||||||
expect(0)->not->toBeBool();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(null)->toBeBool();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(false)->not->toBeBool();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(function () {})->toBeCallable();
|
|
||||||
expect(null)->not->toBeCallable();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
$hello = 5;
|
|
||||||
|
|
||||||
expect($hello)->toBeCallable();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(function () { return 42; })->not->toBeCallable();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
$temp = sys_get_temp_dir();
|
|
||||||
|
|
||||||
expect($temp)->toBeDirectory();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect('/random/path/whatever')->toBeDirectory();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect('.')->not->toBeDirectory();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect([])->toBeEmpty();
|
|
||||||
expect(null)->toBeEmpty();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect([1, 2])->toBeEmpty();
|
|
||||||
expect(' ')->toBeEmpty();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect([])->not->toBeEmpty();
|
|
||||||
expect(null)->not->toBeEmpty();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('strict comparisons', function () {
|
|
||||||
expect(false)->toBeFalse();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect('')->toBeFalse();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(false)->not->toBe(false);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
touch($this->tempFile = sys_get_temp_dir() . '/fake.file');
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function () {
|
|
||||||
unlink($this->tempFile);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect($this->tempFile)->toBeFile();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect('/random/path/whatever.file')->toBeFile();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect($this->tempFile)->not->toBeFile();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(1.0)->toBeFloat();
|
|
||||||
expect(1)->not->toBeFloat();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(42)->toBeFloat();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(log(3))->not->toBeFloat();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('passes', function () {
|
|
||||||
expect(42)->toBeGreaterThan(41);
|
|
||||||
expect(4)->toBeGreaterThan(3.9);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(4)->toBeGreaterThan(4);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(5)->not->toBeGreaterThan(4);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('passes', function () {
|
|
||||||
expect(42)->toBeGreaterThanOrEqual(41);
|
|
||||||
expect(4)->toBeGreaterThanOrEqual(4);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(4)->toBeGreaterThanOrEqual(4.1);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(5)->not->toBeGreaterThanOrEqual(5);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(log(0))->toBeInfinite();
|
|
||||||
expect(log(1))->not->toBeInfinite();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(asin(2))->toBeInfinite();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(INF)->not->toBeInfinite();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(new Exception())->toBeInstanceOf(Exception::class);
|
|
||||||
expect(new Exception())->not->toBeInstanceOf(RuntimeException::class);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(new Exception())->toBeInstanceOf(RuntimeException::class);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(new Exception())->not->toBeInstanceOf(Exception::class);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(42)->toBeInt();
|
|
||||||
expect(42.0)->not->toBeInt();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(42.0)->toBeInt();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(6 * 7)->not->toBeInt();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect([])->toBeIterable();
|
|
||||||
expect(null)->not->toBeIterable();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(42)->toBeIterable();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
function gen(): iterable
|
|
||||||
{
|
|
||||||
yield 1;
|
|
||||||
yield 2;
|
|
||||||
yield 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(gen())->not->toBeIterable();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('passes', function () {
|
|
||||||
expect(41)->toBeLessThan(42);
|
|
||||||
expect(4)->toBeLessThan(5);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(4)->toBeLessThan(4);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(5)->not->toBeLessThan(6);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('passes', function () {
|
|
||||||
expect(41)->toBeLessThanOrEqual(42);
|
|
||||||
expect(4)->toBeLessThanOrEqual(4);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(4)->toBeLessThanOrEqual(3.9);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(5)->not->toBeLessThanOrEqual(5);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(asin(2))->toBeNan();
|
|
||||||
expect(log(0))->not->toBeNan();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(1)->toBeNan();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(acos(1.5))->not->toBeNan();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(null)->toBeNull();
|
|
||||||
expect('')->not->toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect('hello')->toBeNull();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(null)->not->toBeNull();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(42)->toBeNumeric();
|
|
||||||
expect('A')->not->toBeNumeric();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(null)->toBeNumeric();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(6 * 7)->not->toBeNumeric();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect((object) ['a' => 1])->toBeObject();
|
|
||||||
expect(['a' => 1])->not->toBeObject();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(null)->toBeObject();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect((object) 'ciao')->not->toBeObject();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(sys_get_temp_dir())->toBeReadableDirectory();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect('/random/path/whatever')->toBeReadableDirectory();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(sys_get_temp_dir())->not->toBeReadableDirectory();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
touch($this->tempFile = sys_get_temp_dir() . '/fake.file');
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function () {
|
|
||||||
unlink($this->tempFile);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect($this->tempFile)->toBeReadableFile();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect('/random/path/whatever.file')->toBeReadableFile();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect($this->tempFile)->not->toBeReadableFile();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
$resource = tmpfile();
|
|
||||||
|
|
||||||
afterAll(function () use ($resource) {
|
|
||||||
fclose($resource);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('pass', function () use ($resource) {
|
|
||||||
expect($resource)->toBeResource();
|
|
||||||
expect(null)->not->toBeResource();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(null)->toBeResource();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () use ($resource) {
|
|
||||||
expect($resource)->not->toBeResource();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(1.1)->toBeScalar();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(null)->toBeScalar();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(42)->not->toBeScalar();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect('1.1')->toBeString();
|
|
||||||
expect(1.1)->not->toBeString();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(null)->toBeString();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect('42')->not->toBeString();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('strict comparisons', function () {
|
|
||||||
expect(true)->toBeTrue();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect('')->toBeTrue();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(false)->not->toBe(false);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(sys_get_temp_dir())->toBeWritableDirectory();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect('/random/path/whatever')->toBeWritableDirectory();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(sys_get_temp_dir())->not->toBeWritableDirectory();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
touch($this->tempFile = sys_get_temp_dir() . '/fake.file');
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function () {
|
|
||||||
unlink($this->tempFile);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect($this->tempFile)->toBeWritableFile();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect('/random/path/whatever.file')->toBeWritableFile();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect($this->tempFile)->not->toBeWritableFile();
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('passes strings', function () {
|
|
||||||
expect([1, 2, 42])->toContain(42);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('passes arrays', function () {
|
|
||||||
expect('Nuno')->toContain('Nu');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect([1, 2, 42])->toContain(3);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect([1, 2, 42])->not->toContain(42);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect('username')->toEndWith('name');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect('username')->toEndWith('password');
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect('username')->not->toEndWith('name');
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect('00123')->toEqual(123);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(['a', 'b', 'c'])->toEqual(['a', 'b']);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect('042')->not->toEqual(42);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect([1, 2, 3])->toEqualCanonicalizing([3, 1, 2]);
|
|
||||||
expect(['g', 'a', 'z'])->not->toEqualCanonicalizing(['a', 'z']);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect([3, 2, 1])->toEqualCanonicalizing([1, 2]);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(['a', 'b', 'c'])->not->toEqualCanonicalizing(['b', 'a', 'c']);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(1.0)->toEqualWithDelta(1.3, .4);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(1.0)->toEqualWithDelta(1.5, .1);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(1.0)->not->toEqualWithDelta(1.6, .7);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect([1, 2, 3])->toHaveCount(3);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect([1, 2, 3])->toHaveCount(4);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect([1, 2, 3])->not->toHaveCount(3);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKey('c');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKey('hello');
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(['a' => 1, 'hello' => 'world', 'c'])->not->toHaveKey('hello');
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKeys(['a', 'c']);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKeys(['a', 'd']);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect(['a' => 1, 'hello' => 'world', 'c'])->not->toHaveKeys(['hello', 'c']);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
$obj = new stdClass();
|
|
||||||
$obj->foo = 'bar';
|
|
||||||
$obj->fooNull = null;
|
|
||||||
|
|
||||||
test('pass', function () use ($obj) {
|
|
||||||
expect($obj)->toHaveProperty('foo');
|
|
||||||
expect($obj)->toHaveProperty('foo', 'bar');
|
|
||||||
expect($obj)->toHaveProperty('fooNull');
|
|
||||||
expect($obj)->toHaveProperty('fooNull', null);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () use ($obj) {
|
|
||||||
expect($obj)->toHaveProperty('bar');
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () use ($obj) {
|
|
||||||
expect($obj)->not->toHaveProperty('foo');
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
$this->user = (object) [
|
|
||||||
'id' => 1,
|
|
||||||
'name' => 'Nuno',
|
|
||||||
'email' => 'enunomaduro@gmail.com',
|
|
||||||
];
|
|
||||||
});
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect($this->user)->toMatchObject([
|
|
||||||
'name' => 'Nuno',
|
|
||||||
'email' => 'enunomaduro@gmail.com',
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect($this->user)->toMatchObject([
|
|
||||||
'name' => 'Not the same name',
|
|
||||||
'email' => 'enunomaduro@gmail.com',
|
|
||||||
]);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect($this->user)->not->toMatchObject([
|
|
||||||
'id' => 1,
|
|
||||||
]);
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
|
||||||
|
|
||||||
test('pass', function () {
|
|
||||||
expect('username')->toStartWith('user');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () {
|
|
||||||
expect('username')->toStartWith('password');
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
|
|
||||||
test('not failures', function () {
|
|
||||||
expect('username')->not->toStartWith('user');
|
|
||||||
})->throws(ExpectationFailedException::class);
|
|
||||||
@ -6,7 +6,7 @@ beforeEach(function () use ($state) {
|
|||||||
$this->state = $state;
|
$this->state = $state;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () use ($state) {
|
afterEach(function () {
|
||||||
$this->state->bar = 2;
|
$this->state->bar = 2;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -95,6 +95,18 @@ test('eager registered wrapped datasets did the job right', function () use ($st
|
|||||||
expect($state->text)->toBe('1212121212');
|
expect($state->text)->toBe('1212121212');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('named datasets', function ($text) use ($state, $datasets) {
|
||||||
|
$state->text .= $text;
|
||||||
|
expect($datasets)->toContain([$text]);
|
||||||
|
})->with([
|
||||||
|
'one' => [1],
|
||||||
|
'two' => [2],
|
||||||
|
]);
|
||||||
|
|
||||||
|
test('named datasets did the job right', function () use ($state) {
|
||||||
|
expect($state->text)->toBe('121212121212');
|
||||||
|
});
|
||||||
|
|
||||||
class Bar
|
class Bar
|
||||||
{
|
{
|
||||||
public $name = 1;
|
public $name = 1;
|
||||||
@ -104,7 +116,7 @@ $namedDatasets = [
|
|||||||
new Bar(),
|
new Bar(),
|
||||||
];
|
];
|
||||||
|
|
||||||
test('lazy named datasets', function ($text) use ($state, $datasets) {
|
test('lazy named datasets', function ($text) {
|
||||||
expect(true)->toBeTrue();
|
expect(true)->toBeTrue();
|
||||||
})->with($namedDatasets);
|
})->with($namedDatasets);
|
||||||
|
|
||||||
|
|||||||
@ -32,3 +32,7 @@ test('depends with defined arguments', function (string $first, string $second)
|
|||||||
test('depends run test only once', function () use (&$runCounter) {
|
test('depends run test only once', function () use (&$runCounter) {
|
||||||
expect($runCounter)->toBe(2);
|
expect($runCounter)->toBe(2);
|
||||||
})->depends('first', 'second');
|
})->depends('first', 'second');
|
||||||
|
|
||||||
|
// Regression tests. See https://github.com/pestphp/pest/pull/216
|
||||||
|
it('asserts true is true')->assertTrue(true);
|
||||||
|
test('depends works with the correct test name')->assertTrue(true)->depends('it asserts true is true');
|
||||||
|
|||||||
22
tests/Features/DependsInheritance.php
Normal file
22
tests/Features/DependsInheritance.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class InheritanceTest extends TestCase
|
||||||
|
{
|
||||||
|
public function foo()
|
||||||
|
{
|
||||||
|
return 'bar';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uses(InheritanceTest::class);
|
||||||
|
|
||||||
|
it('is a test', function () {
|
||||||
|
expect(true)->toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses correct parent class', function () {
|
||||||
|
expect(get_parent_class($this))->toEqual(InheritanceTest::class);
|
||||||
|
expect($this->foo())->toEqual('bar');
|
||||||
|
})->depends('it is a test');
|
||||||
@ -4,4 +4,8 @@ beforeEach()->assertTrue(true);
|
|||||||
|
|
||||||
it('proxies calls to object')->assertTrue(true);
|
it('proxies calls to object')->assertTrue(true);
|
||||||
|
|
||||||
|
it('is capable doing multiple assertions')
|
||||||
|
->assertTrue(true)
|
||||||
|
->assertFalse(false);
|
||||||
|
|
||||||
afterEach()->assertTrue(true);
|
afterEach()->assertTrue(true);
|
||||||
|
|||||||
@ -27,3 +27,7 @@ it('do not skips with falsy closure condition')
|
|||||||
it('skips with condition and message')
|
it('skips with condition and message')
|
||||||
->skip(true, 'skipped because foo')
|
->skip(true, 'skipped because foo')
|
||||||
->assertTrue(false);
|
->assertTrue(false);
|
||||||
|
|
||||||
|
it('skips when skip after assertion')
|
||||||
|
->assertTrue(true)
|
||||||
|
->skip();
|
||||||
|
|||||||
27
tests/Hooks/AfterAllTest.php
Normal file
27
tests/Hooks/AfterAllTest.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
global $globalHook;
|
||||||
|
|
||||||
|
uses()->afterAll(function () use ($globalHook) {
|
||||||
|
expect($globalHook)
|
||||||
|
->toHaveProperty('afterAll')
|
||||||
|
->and($globalHook->afterAll)
|
||||||
|
->toBe(0);
|
||||||
|
|
||||||
|
$globalHook->afterAll = 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(function () use ($globalHook) {
|
||||||
|
expect($globalHook)
|
||||||
|
->toHaveProperty('afterAll')
|
||||||
|
->and($globalHook->afterAll)
|
||||||
|
->toBe(1);
|
||||||
|
|
||||||
|
$globalHook->afterAll = 2;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('global afterAll execution order', function () use ($globalHook) {
|
||||||
|
expect($globalHook)
|
||||||
|
->not()
|
||||||
|
->toHaveProperty('afterAll');
|
||||||
|
});
|
||||||
23
tests/Hooks/AfterEachTest.php
Normal file
23
tests/Hooks/AfterEachTest.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
uses()->afterEach(function () {
|
||||||
|
expect($this)
|
||||||
|
->toHaveProperty('ith')
|
||||||
|
->and($this->ith)
|
||||||
|
->toBe(0);
|
||||||
|
|
||||||
|
$this->ith = 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
expect($this)
|
||||||
|
->toHaveProperty('ith')
|
||||||
|
->and($this->ith)
|
||||||
|
->toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('global afterEach execution order', function () {
|
||||||
|
expect($this)
|
||||||
|
->not()
|
||||||
|
->toHaveProperty('ith');
|
||||||
|
});
|
||||||
28
tests/Hooks/BeforeAllTest.php
Normal file
28
tests/Hooks/BeforeAllTest.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
global $globalHook;
|
||||||
|
|
||||||
|
uses()->beforeAll(function () use ($globalHook) {
|
||||||
|
expect($globalHook)
|
||||||
|
->toHaveProperty('beforeAll')
|
||||||
|
->and($globalHook->beforeAll)
|
||||||
|
->toBe(0);
|
||||||
|
|
||||||
|
$globalHook->beforeAll = 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeAll(function () use ($globalHook) {
|
||||||
|
expect($globalHook)
|
||||||
|
->toHaveProperty('beforeAll')
|
||||||
|
->and($globalHook->beforeAll)
|
||||||
|
->toBe(1);
|
||||||
|
|
||||||
|
$globalHook->beforeAll = 2;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('global beforeAll execution order', function () use ($globalHook) {
|
||||||
|
expect($globalHook)
|
||||||
|
->toHaveProperty('beforeAll')
|
||||||
|
->and($globalHook->beforeAll)
|
||||||
|
->toBe(2);
|
||||||
|
});
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user