Compare commits

...

197 Commits

Author SHA1 Message Date
fac3fe3f55 docs: updates changelog 2020-12-26 21:31:38 +01:00
17fac0a488 Update composer.json 2020-12-26 21:19:28 +01:00
885d224c5d docs: updates changelog 2020-12-20 17:22:40 +01:00
12441deab8 chore: upgrades version 2020-12-20 17:22:33 +01:00
8852fd14ce Merge pull request #236 from avrahamappel/master
Add test for inheritance with depends
2020-12-20 17:18:53 +01:00
e3814e6d9c chore: fixes static analsysis on uses_classs 2020-12-20 17:12:08 +01:00
e19eba0942 Rebuild snapshots 2020-12-17 23:24:29 -05:00
b6e2763731 Move dependency mapping to TestCase
The `TestCaseFactory::getClassName` was removed since it can have
unexpected results when called too early, as it builds up the test class
prematurely. It is not currently used anywhere else.
2020-12-17 23:24:11 -05:00
f75a3ee865 Add test for inheritance with depends 2020-12-15 22:29:37 -05:00
d707c2f208 Merge pull request #209 from NickSdot/make-root-path-working-in-subdirectory-structures
Get root path based on composer autoloader
2020-12-15 01:58:05 +01:00
a43b86d9eb chore: removes rector 2020-12-13 23:11:50 +01:00
5279d5e913 chore: pin expectations plugin version 2020-12-13 23:09:32 +01:00
df7fb92e03 chore: removes rector 2020-12-13 22:55:09 +01:00
95c3418313 docs: updates changelog 2020-12-13 22:52:06 +01:00
67a8be9347 chore: fixes snapshots 2020-12-13 22:50:13 +01:00
5d7f262f4a feat: removes expectation api for a plugin 2020-12-13 22:35:30 +01:00
23eebc8127 docs: updates changelog 2020-12-04 21:19:40 +01:00
3b435e460e chore: increases version 2020-12-04 21:19:32 +01:00
b52e9826e7 Merge pull request #234 from soilSpoon/feature/phpunit
Update PHPUnit dependency version
2020-12-04 09:16:27 +01:00
ba49dd0499 Update PHPUnit dependency version 2020-12-04 15:46:25 +09:00
f9f6f28950 Merge pull request #233 from misaert/feat-authorize-associative-array-for-with
fix: authorize string as key for datasets
2020-11-30 16:42:35 +01:00
f017015d1e fix: authorize string as key for datasets 2020-11-30 14:50:40 +01:00
29b4ee33bb Merge pull request #232 from pestphp/feat/expect-extend
feat: makes expect extendable
2020-11-29 18:25:21 +01:00
03dc11c2f6 Adds expect extend 2020-11-29 16:30:57 +01:00
b79ba5098b docs: updates changelog 2020-11-28 18:55:22 +01:00
3c418d82e6 chore: increases version 2020-11-28 18:55:14 +01:00
73ede2e344 Merge pull request #223 from clmntgr/support-pest-command
Add a dusk command for Laravel
2020-11-28 18:46:51 +01:00
266d891488 Merge pull request #231 from pestphp/feat/feedback-on-to-match
feat: adds key/value context when toMatchObject or toMatchArray fails
2020-11-28 18:21:52 +01:00
c71490b472 feat(feedback-on-to-match): uses contextual messages inside expectations 2020-11-27 21:52:44 +01:00
07705079e2 Merge pull request #229 from owenvoke/feature/release-guide
docs: add release guide
2020-11-27 11:42:46 +01:00
d88c268426 docs: use docs prefix in release commit message 2020-11-27 09:13:38 +00:00
a1b142e885 docs: add details on plugin versioning 2020-11-26 19:55:42 +00:00
a50d739e50 docs: add release guide 2020-11-26 19:55:11 +00:00
f82bb56d89 chore: update changelog 2020-11-24 09:12:43 +00:00
de593c3b93 Add a dusk command for Laravel.
This new command will replicate Dusk behavior with .env.dusk files
2020-11-24 10:07:06 +01:00
eedd5d80a0 chore: updates version 2020-11-23 22:01:06 +01:00
5bbdd4f41e docs: updates changelog 2020-11-23 21:43:58 +01:00
3fd24d96d3 feat: casts to array using toArray 2020-11-23 21:37:35 +01:00
7bea51fe09 feat: adds toMatchArray 2020-11-23 21:26:02 +01:00
cdf0a38145 Merge pull request #216 from owenvoke/bugfix/depends
fix(depends): resolve issue with dependency names
2020-11-23 08:43:58 +00:00
bb2474ccbe tests: add regression tests for depends 2020-11-13 11:14:17 +00:00
01143a6f84 fix(depends): resolve issue with dependency names 2020-11-13 11:08:35 +00:00
b93485c2ed Merge pull request #217 from owenvoke/feature/help
feat: add Pest options to help output
2020-11-12 14:59:50 +00:00
04681690b6 tests: update help snapshot to only include Pest options 2020-11-12 09:53:40 +00:00
200877d691 tests: update to use snapshot for help output 2020-11-12 09:44:26 +00:00
feb6417f45 tests: add visual test for help output 2020-11-12 09:11:51 +00:00
e7585a4ba2 tests: update snapshots 2020-11-12 09:03:44 +00:00
c33ab0f670 tests: add test for help output 2020-11-12 09:03:44 +00:00
78181f66f6 feat: add Pest options to help output 2020-11-12 09:03:43 +00:00
925636be61 docs: add missing bracket 2020-11-11 23:31:19 +00:00
6be131d602 chore: update changelog 2020-11-11 23:29:18 +00:00
f950f57eed Merge pull request #219 from owenvoke/feature/phpunit
chore(deps): add support for PHPUnit 9.4.3
2020-11-11 22:35:26 +00:00
c6369feaea chore(deps): add support for PHPUnit 9.4.3 2020-11-11 22:26:53 +00:00
1bdd3f4908 Update Pest.php 2020-11-09 10:56:14 +01:00
924e095dfc chore: updates changelog 2020-11-09 10:55:22 +01:00
72041a4a21 Merge pull request #215 from olivernybroe/teamcity-exception
Improve exception output in teamcity printer
2020-11-09 10:52:08 +01:00
d576446639 Improve exception output in teamcity printer 2020-11-04 09:17:57 +01:00
3fbec70ed3 chore: updates changelog 2020-11-01 23:22:18 +01:00
d177ab5ec2 feat: support to phpunit v9.4.2 2020-10-20 19:40:38 +02:00
ba08f2c11e Changes based on feedback https://github.com/pestphp/pest-intellij/issues/73#issuecomment-709201510 2020-10-15 19:46:16 +08:00
13a8aee049 Get root path from already available and correct path of autoloader 2020-10-14 21:31:28 +08:00
e4f5a284a6 Merge pull request #208 from owenvoke/bugfix/changelog-action
ci(changelog): fix changelog action
2020-10-13 11:16:15 +01:00
6671b266da ci(changelog): fix issue with branch and update to v3 2020-10-13 11:12:34 +01:00
3728bd8e0f ci(changelog): update formatting and run on change 2020-10-13 11:12:06 +01:00
c3616edbc8 docs: update changelog 2020-10-13 10:56:33 +01:00
21143b2693 Merge pull request #207 from fetzi/master
Update phpunit dependency constraint
2020-10-13 10:45:18 +01:00
006f9232cc Update phpunit dependency constraint
allow all versions greater 9.3.7

fixes #205
2020-10-13 11:24:25 +02:00
d1b61a34de Merge pull request #203 from olivernybroe/HelpCommand
Add Pest version to help command
2020-10-08 14:47:19 +02:00
896317ac97 Add Pest version to help command 2020-10-08 11:52:10 +02:00
4fd5c0edd4 Merge pull request #201 from octoper/changelog-action
Update Changelog action
2020-10-06 09:21:42 +02:00
e2c5d6d857 Update Changelog action to point to pestphp/docs 2020-10-06 08:36:41 +02:00
8057fe4bc2 Update Changelog Action 2020-10-06 08:10:57 +02:00
ebc9690301 Merge pull request #134 from sshead/adds-dataset-names
Add name to description for named datasets
2020-10-03 17:39:26 +02:00
049ce1845e chore: update changelog 2020-10-03 12:27:01 +01:00
faa6cd7deb Merge pull request #199 from owenvoke/feature/phpunit-9.4
feat: adds support to PHPUnit 9.4
2020-10-03 12:16:36 +01:00
1f9362c4e7 chore(composer): update to support PHPUnit 9.4 2020-10-02 11:18:10 +01:00
36fd18bcc8 Use Expectation API 2020-10-01 13:59:26 +10:00
aa352317cb Add a named dataset test to output to snapshot 2020-10-01 13:54:17 +10:00
edcd2cb50e Add name to description for named datasets 2020-10-01 13:23:23 +10:00
be8a64e4b8 Merge pull request #196 from DannyvdSluijs/feature-fix-skip-on-higher-order-test
Revert to original target if new target is null
2020-09-30 21:41:59 +02:00
2336bc0f65 Update snapshots 2020-09-30 21:36:05 +02:00
da82eecbae Add tests to ensure working. 2020-09-30 21:32:31 +02:00
4855987ba8 chore: update changelog 2020-09-30 13:03:23 +01:00
a493db1873 Revert to original target if new target is null 2020-09-29 21:51:28 +02:00
4f677a6cc2 Merge pull request #193 from owenvoke/feature/dependencies
chore(composer): add support for PHPUnit 9.3.11
2020-09-24 12:12:03 +01:00
228f2deb64 chore(composer): add support for PHPUnit 9.3.11 2020-09-24 10:45:19 +01:00
0fadf9a02c chore: update changelog 2020-09-21 20:31:32 +01:00
2b138ad76b Merge pull request #191 from owenvoke/feature/assert-regex
feat(expectations): add toMatch
2020-09-21 20:28:42 +01:00
e3e4815b55 chore(expectations): rename 'toMatchRegEx' to 'toMatch' 2020-09-21 20:20:21 +01:00
f76f353c32 chore: update snapshots 2020-09-21 20:19:01 +01:00
16b9f54dc3 feat(expectations): add toMatchRegEx 2020-09-21 20:18:58 +01:00
281166475e Merge pull request #190 from owenvoke/feature/assert-constraint
feat(expectations): add toMatchConstraint
2020-09-21 20:14:39 +01:00
23805cb5d6 chore: update snapshots 2020-09-16 19:03:21 +01:00
76d0f9cfc1 feat(expectations): add toMatchConstraint 2020-09-16 19:02:33 +01:00
5b083e4eb1 chore: update changelog 2020-09-16 10:35:43 +01:00
f48694b18a Merge pull request #187 from owenvoke/feature/assert-string
feat: add 'toStartWith' and 'toEndWith' expectations
2020-09-16 10:33:00 +01:00
8fa59ddbf0 Merge pull request #189 from owenvoke/feature/changelog-workflow
chore: don't run changelog workflow on forks
2020-09-16 09:26:17 +01:00
2619db4026 chore: don't run changelog workflow on forks 2020-09-16 08:26:49 +01:00
f3a71fb100 chore: update snapshots 2020-09-16 08:22:35 +01:00
04fafe742c feat(expectations): add toEndWith 2020-09-16 08:21:46 +01:00
cad8a41e6d feat(expectations): add toStartWith 2020-09-16 08:20:00 +01:00
1567923cda docs: updates changelog 2020-09-15 21:57:50 +02:00
c7116afcae tests: updates snapshots 2020-09-15 21:56:39 +02:00
4e184b2f90 Adds toMatchObject 2020-09-15 21:53:25 +02:00
9b5f664f00 Merge pull request #185 from owenvoke/feature/stubs
chore: update PHPUnit config stubs
2020-09-15 13:06:33 +02:00
0e89525ea8 chore: fix PHPUnit config 2020-09-15 10:45:17 +01:00
0b6cdf8f02 chore: fix PHPUnit config stubs 2020-09-15 10:44:59 +01:00
5f63d959e1 docs: updates changelog 2020-09-13 15:35:49 +02:00
be7fe41179 docs: updates changelog 2020-09-13 15:16:38 +02:00
204f343831 feat: adds toHaveKeys expectation 2020-09-13 15:15:37 +02:00
aa230a1716 docs: updates changelog 2020-09-12 23:46:45 +02:00
97f98569bc feat: adds support to PHPUnit 9.3.9 || 9.3.10 2020-09-12 23:45:22 +02:00
1318bf9830 Merge pull request #141 from olivernybroe/feat-teamcity
feat(teamcity): Add basic teamcity output format
2020-09-11 09:14:33 +01:00
3b58f946f1 Adds Scout APM as premium sponsor 2020-09-11 00:19:43 +02:00
dfc2470764 Merge pull request #179 from owenvoke/feature/badge
docs: fix GitHub Actions badge in README
2020-09-07 12:15:42 +02:00
f650978dd0 docs: fix GitHub Actions badge in README 2020-09-07 11:12:20 +01:00
c6ba469e68 release: version 2020-08-29 23:55:28 +02:00
3a9997f9af docs: updates changelog 2020-08-29 23:55:05 +02:00
fb6cb891be Merge pull request #174 from pestphp/phpunit-upgrade
Allow phpunit 9.3.8 too
2020-08-29 22:59:51 +02:00
76beda74c9 Allow phpunit 9.3.8 too 2020-08-28 16:40:17 +01:00
0398d4223b docs: updates changelog 2020-08-27 22:47:10 +02:00
360eeb4c7d Merge pull request #173 from owenvoke/feature/collision-stable
chore: update to use stable Collision 5
2020-08-26 11:00:43 +01:00
79b4224a35 chore: update to use stable Collision 5 2020-08-26 10:49:46 +01:00
3c79c893c9 Merge pull request #169 from felixdorn/forwards-calls-to-helpers
Forward TestCase bad method calls to global functions
2020-08-25 22:44:57 +02:00
a11f507191 Merge pull request #172 from owenvoke/feature/phpunit-9.3
chore: update PHPUnit configuration for coverage
2020-08-25 22:44:38 +02:00
6413f7040f chore: update PHPUnit configuration for coverage 2020-08-25 21:41:05 +01:00
278af4b835 forward bad TestCase method calls to global functions 2020-08-25 13:45:55 +02:00
fe885fbfb6 Merge pull request #170 from owenvoke/bugfix/snapshot-time
fix: update snapshot generation to strip time
2020-08-25 10:25:23 +02:00
61b2c426e4 fix: update snapshot generation to strip time 2020-08-24 21:29:56 +01:00
4272d49fb7 Merge pull request #165 from owenvoke/bugfix/decoration
fix: don't decorate output if --colors=never is set
2020-08-19 20:28:57 +01:00
014ab3b957 Merge pull request #166 from owenvoke/feature/version
chore: indicate 0.3 dev in version
2020-08-19 20:27:51 +01:00
09a0a64f20 tests: update to use version() in test 2020-08-19 16:56:40 +01:00
bf79f7c63f chore: indicate 0.3 dev in version 2020-08-19 16:48:20 +01:00
36b879f97d fix: don't decorate output if --colors=never is set 2020-08-19 13:46:07 +01:00
bcc206d183 chore(teamcity): static analysis fix 2020-08-18 14:10:32 +02:00
1e7b6a0396 Merge branch 'master' of https://github.com/pestphp/pest into feat-teamcity
 Conflicts:
	phpstan.neon
2020-08-15 08:30:46 +02:00
57a1ccd213 Merge pull request #162 from owenvoke/feature/file-expectations
feat(expectations): add file assertions
2020-08-13 10:15:37 +01:00
708b4b1d49 tests: fix snapshots 2020-08-13 10:03:23 +01:00
3695736b3a tests: update snapshots 2020-08-13 10:03:23 +01:00
8cc9580253 tests(expectations): add tests for file assertions 2020-08-13 10:03:23 +01:00
e1fbf56f3d tests(expectations): fix method in test file 2020-08-13 10:03:23 +01:00
50cd1056eb feat(expectations): add file assertions 2020-08-13 10:03:23 +01:00
cfe6a6728f Merge pull request #163 from owenvoke/feature/rector-php
build: update Rector config to PHP
2020-08-12 15:29:15 +01:00
38344c99f1 style: apply Rector changes 2020-08-12 14:45:55 +01:00
98ed779424 build: update Rector config to PHP 2020-08-12 13:03:15 +01:00
943707cbcd Merge pull request #161 from pestphp/phpunit
Require PHPUnit 9.3.7
2020-08-12 12:13:23 +01:00
940e246f27 Require PHPUnit 7.3.7 2020-08-12 11:39:57 +01:00
439ebcdcaf feat(expectation-api): adds failed assertations on not methods 2020-08-09 19:08:27 +01:00
d2db71bb78 tests: update snapshots 2020-08-09 18:31:08 +01:00
d85432933c Merge pull request #128 from GrahamCampbell/php8
feat: adds support to phpunit 9.3 and php 8.0
2020-08-08 22:53:24 +01:00
3cfadee2bb PHP 8 and PHPUnit 9.3 support 2020-08-07 11:23:45 +01:00
051ca73cae Merge pull request #156 from voyula/patch-2
Add yaml file extension support
2020-08-04 11:19:41 +01:00
50a273f1f1 Add Yaml Support
For: https://github.com/pestphp/pest/blob/master/rector.yaml
2020-08-04 12:54:49 +03:00
ffe5dde7f0 Merge pull request #151 from GrahamCampbell/patch-1
Added additional rector sets
2020-08-04 07:33:54 +01:00
7e1747a364 Merge pull request #150 from innocenzi/fix/command-interactions
Avoid command interactions when the `--no-interaction` flag is given
2020-08-03 21:26:11 +01:00
356b9c01c7 Added additional rector sets 2020-08-03 21:03:17 +01:00
4009177e56 style: fix unary_operator_space 2020-08-03 21:49:09 +02:00
46d1d46384 Merge branch 'master' of https://github.com/pestphp/pest 2020-08-03 20:48:52 +01:00
128ff1006f chore: removes broken rector set 2020-08-03 20:48:45 +01:00
64bb853720 fix: correctly avoid interactions 2020-08-03 21:39:58 +02:00
330dafa294 Merge pull request #145 from AlexMartinFR/patch-2
Update globals.php
2020-08-02 22:53:32 +01:00
a51c354268 Update globals.php
Typo.
2020-08-02 19:25:54 +02:00
cc1abe7f06 fix(teamcity): Fixed a bug when running phpunit tests together with pest tests 2020-07-31 10:25:23 +02:00
0c16942d37 refactor(teamcity): Small cleanup 2020-07-28 11:14:10 +02:00
fa413aafbb style(teamcity): fix styling 2020-07-28 10:51:57 +02:00
75f17bb118 feat(teamcity): Add basic team city output format 2020-07-28 09:11:30 +02:00
19ce733207 Merge pull request #139 from AlexMartinFR/expectations
Polishing Expectation API
2020-07-27 08:47:33 +02:00
7529d44f81 Polishing Expectation API 2020-07-26 17:20:58 +02:00
e4e4eb0a57 chore: bumps deps 2020-07-24 21:54:00 +02:00
c8eb1397b4 Merge pull request #123 from pestphp/feat/expect
feat: add `expect` function
2020-07-18 19:04:37 +02:00
c4c768dcaa tests: update snapshots 2020-07-18 18:57:14 +02:00
8c60a9fff5 Merge pull request #129 from ceceppa/feat/expect
Feat/expect
2020-07-18 18:29:32 +02:00
206e613711 Merge pull request #130 from GrahamCampbell/patch-1
Cleanup actions static analysis
2020-07-16 19:40:49 +02:00
5fb81e9eb4 Update static.yml 2020-07-16 18:36:58 +01:00
d130a1aea0 Cleanup actions static analysis 2020-07-16 18:22:17 +01:00
03201cb8b7 feat(expect): add more methods 2020-07-16 07:57:05 +01:00
46e900e8d2 feat(expect): add more methods 2020-07-16 07:35:31 +01:00
f0f79ab244 feat(expect): add more methods 2020-07-16 07:34:43 +01:00
1e61144cd2 feat(expect): handle property calls to opposite expectations 2020-07-15 01:05:36 +02:00
2751bc9674 feat(expect): fixes to contain with strings 2020-07-15 00:57:31 +02:00
e2deaae6c9 feat(expect): makes expect work with pending higher order tests 2020-07-15 00:34:59 +02:00
1aec8bac55 feat(expect): adds toHaveProperty 2020-07-14 23:37:02 +02:00
32ef377284 feat(expect): removes ignore cases related assertions 2020-07-14 23:21:51 +02:00
ab017e17e2 feat(expect): removes assertions api 2020-07-14 23:15:29 +02:00
832882160f feat(expect): updates test suite to use expectation api 2020-07-14 23:15:14 +02:00
e03d015120 Merge pull request #125 from ceceppa/feat/expect
Feat/expect
2020-07-14 21:13:42 +02:00
819825bdd2 feat(expect): add more methods 2020-07-14 08:08:13 +01:00
d29c789788 feat(expect): add more methods 2020-07-13 17:57:18 +01:00
b4c45af785 feat(expect): add more methods 2020-07-13 17:49:19 +01:00
b4bf799d75 feat(expect): add more methods 2020-07-13 17:38:09 +01:00
9f62f2d483 feat(expect): add more methods 2020-07-13 17:27:55 +01:00
679082e805 feat(expect): add more methods 2020-07-10 07:53:45 +01:00
42f0bd052e feat(expect): add more methods 2020-07-10 07:47:34 +01:00
01b9bab55f feat(expect): adds toBe 2020-07-06 00:32:12 +02:00
3eb0a95955 Merge pull request #121 from owenvoke/feature/changelog-hr
Add 'hr' tag to separate link
2020-07-02 11:20:32 +02:00
d11157f7b2 Add 'hr' tag to separate link 2020-07-02 10:15:48 +01:00
1f2ec74d6c docs: updates changelog 2020-07-02 10:04:29 +01:00
76 changed files with 928 additions and 2211 deletions

View File

@ -14,5 +14,5 @@ trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.yml]
[*.{yml,yaml}]
indent_size = 2

View File

@ -5,6 +5,7 @@ on:
branches: [ master ]
paths:
- CHANGELOG.md
- .github/workflows/changelog.yml
pull_request:
branches: [ master ]
paths:
@ -13,19 +14,25 @@ jobs:
build:
runs-on: ubuntu-latest
if: github.repository == 'pestphp/pest'
steps:
- uses: actions/checkout@v2
- name: Checkout website repository
uses: actions/checkout@v2
with:
token: ${{ secrets.CHANGELOG_KEY }}
repository: pestphp/website
path: pestphp-website
repository: pestphp/docs
path: pestphp-docs
ref: master
- name: Read CHANGELOG.md
id: package
uses: juliangruber/read-file-action@v1
with:
path: ./CHANGELOG.md
- name: Add file headers
uses: DamianReeves/write-file-action@v1.0
with:
@ -34,21 +41,23 @@ jobs:
---
title: Changelog
description: Changelog
extends: _layouts.documentation
section: content
---
${{ steps.package.outputs.content }}
----
Next section: [Upgrade Guide →](/docs/upgrade-guide)
write-mode: overwrite
- name: Copy CHANGELOG to website repository
run: cp CHANGELOG.md pestphp-website/source/docs/changelog.md
run: cp CHANGELOG.md pestphp-docs/changelog.md
- name: Create Pull Request
uses: peter-evans/create-pull-request@v2
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.CHANGELOG_KEY }}
commit-message: Update changelog.md
committer: GitHub Action <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
title: 'Update changelog.md'
path: ./pestphp-website
path: ./pestphp-docs

View File

@ -1,46 +0,0 @@
name: Formats
on: ['push', 'pull_request']
jobs:
ci:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [7.4]
dependency-version: [prefer-lowest, prefer-stable]
name: Formats P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, mbstring, zip
tools: prestissimo
coverage: pcov
- name: Install Composer dependencies
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist
- name: Coding Style Checks
run: |
vendor/bin/rector process src --dry-run
vendor/bin/php-cs-fixer fix -v --dry-run
- name: Type Checks
run: vendor/bin/phpstan analyse --ansi

51
.github/workflows/static.yml vendored Normal file
View File

@ -0,0 +1,51 @@
name: Static Analysis
on: ['push', 'pull_request']
jobs:
cs:
runs-on: ubuntu-latest
name: Code Style
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer:v2
coverage: none
- name: Install Dependencies
run: composer update --no-interaction --no-progress
- name: Run PHP-CS-Fixer
run: vendor/bin/php-cs-fixer fix -v --allow-risky=yes --dry-run
phpstan:
runs-on: ubuntu-latest
strategy:
matrix:
dependency-version: [prefer-lowest, prefer-stable]
name: PHPStan ${{ matrix.dependency-version }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer:v2
coverage: none
- name: Install Dependencies
run: composer update --prefer-stable --no-interaction --no-progress
- name: Run PHPStan
run: vendor/bin/phpstan analyse --no-progress

View File

@ -6,43 +6,39 @@ jobs:
ci:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
php: [7.3, 7.4]
php: ['7.3', '7.4', '8.0']
dependency-version: [prefer-lowest, prefer-stable]
name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, mbstring, zip
tools: composer:v2
coverage: none
- name: Install Composer dependencies
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist
- name: Setup Problem Matches
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install PHP 7 dependencies
run: composer update --${{ matrix.dependency-version }} --no-interaction --no-progress
if: "matrix.php < 8"
- name: Install PHP 8 dependencies
run: composer update --${{ matrix.dependency-version }} --ignore-platform-req=php --no-interaction --no-progress
if: "matrix.php >= 8"
- name: Unit Tests
run: php bin/pest --colors=always --exclude-group=integration
- name: Integration Tests
run: php bin/pest --colors=always --group=integration
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Setup problem matchers for Pest
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

View File

@ -3,7 +3,6 @@
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . DIRECTORY_SEPARATOR . 'tests')
->in(__DIR__ . DIRECTORY_SEPARATOR . 'bin')
->in(__DIR__ . DIRECTORY_SEPARATOR . 'compiled')
->in(__DIR__ . DIRECTORY_SEPARATOR . 'scripts')
->in(__DIR__ . DIRECTORY_SEPARATOR . 'stubs')
->in(__DIR__ . DIRECTORY_SEPARATOR . 'src')

View File

@ -4,7 +4,103 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
## [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)
### Added
- `toStartWith` and `toEndWith` expectations ([#187](https://github.com/pestphp/pest/pull/187))
## [v0.3.4 (2020-09-15)](https://github.com/pestphp/pest/compare/v0.3.3...v0.3.4)
### Added
- `toMatchObject` expectation ([4e184b2](https://github.com/pestphp/pest/commit/4e184b2f906c318a5e9cd38fe693cdab5c48d8a2))
## [v0.3.3 (2020-09-13)](https://github.com/pestphp/pest/compare/v0.3.2...v0.3.3)
### Added
- `toHaveKeys` expectation ([204f343](https://github.com/pestphp/pest/commit/204f343831adc17bb3734553c24fac92d02f27c7))
## [v0.3.2 (2020-09-12)](https://github.com/pestphp/pest/compare/v0.3.1...v0.3.2)
### Added
- Support to PHPUnit 9.3.9, and 9.3.10 ([1318bf9](https://github.com/pestphp/pest/commit/97f98569bc86e8b87f8cde963fe7b4bf5399623b))
## [v0.3.1 (2020-08-29)](https://github.com/pestphp/pest/compare/v0.3.0...v0.3.1)
### Added
- Support to PHPUnit 9.3.8 ([#174](https://github.com/pestphp/pest/pull/174))
## [v0.3.0 (2020-08-27)](https://github.com/pestphp/pest/compare/v0.2.3...v0.3.0)
### Added
- Expectation API (TODO)
- PHPUnit 9.3 and PHP 8 support ([#128](https://github.com/pestphp/pest/pull/128))
- Fowards `$this` calls to globals ([#169](https://github.com/pestphp/pest/pull/169))
### Fixed
- don't decorate output if --colors=never is set ([36b879f](https://github.com/pestphp/pest/commit/36b879f97d7b187c87a94eb60af5b7d3b7253d56))
## [v0.2.3 (2020-07-01)](https://github.com/pestphp/pest/compare/v0.2.2...v0.2.3)
### Added
- `--init` and `pest:install` artisan command output changes ([#118](https://github.com/pestphp/pest/pull/118), [db7c4b1](https://github.com/pestphp/pest/commit/db7c4b174f0974969450dda71dcd649ef0c073a3))
- `--version` option to view the current version of Pest ([9ea51ca](https://github.com/pestphp/pest/commit/9ea51caf3f74569debb1e465992e9ea916cb80fe))

View File

@ -1,7 +1,7 @@
<p align="center">
<img src="https://raw.githubusercontent.com/pestphp/art/master/readme.png" width="600" alt="PEST">
<p align="center">
<a href="https://github.com/pestphp/pest/actions"><img alt="GitHub Workflow Status (master)" src="https://img.shields.io/github/workflow/status/pestphp/pest/Continuous Integration/master"></a>
<a href="https://github.com/pestphp/pest/actions"><img alt="GitHub Workflow Status (master)" src="https://img.shields.io/github/workflow/status/pestphp/pest/Tests/master"></a>
<a href="https://packagist.org/packages/pestphp/pest"><img alt="Total Downloads" src="https://img.shields.io/packagist/dt/pestphp/pest"></a>
<a href="https://packagist.org/packages/pestphp/pest"><img alt="Latest Version" src="https://img.shields.io/packagist/v/pestphp/pest"></a>
<a href="https://packagist.org/packages/pestphp/pest"><img alt="License" src="https://img.shields.io/packagist/l/pestphp/pest"></a>
@ -15,4 +15,12 @@
- Follow us on Twitter: **[@pestphp »](https://twitter.com/pestphp)**
- Join us on the Discord Server: **[discord.gg/bMAJv82 »](https://discord.gg/bMAJv82)**
## Pest Sponsors
We would like to extend our thanks to the following sponsors for funding Pest development. If you are interested in becoming a sponsor, please visit the Nuno Maduro's [Sponsors page](https://github.com/sponsors/nunomaduro).
### Premium Sponsors
- **[Scout APM](https://github.com/scoutapp)**
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
View 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.

View File

@ -6,6 +6,7 @@ use Pest\Actions\ValidatesEnvironment;
use Pest\Console\Command;
use Pest\Support\Container;
use Pest\TestSuite;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
@ -18,16 +19,21 @@ use Symfony\Component\Console\Output\OutputInterface;
if (file_exists($vendorPath)) {
include_once $vendorPath;
$autoloadPath = $vendorPath;
} else {
include_once $localPath;
$autoloadPath = $localPath;
}
(new Provider())->register();
$rootPath = getcwd();
// get $rootPath based on $autoloadPath
$rootPath = dirname($autoloadPath, 2);
$testSuite = TestSuite::getInstance($rootPath);
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, true);
$isDecorated = (new ArgvInput())->getParameterOption('--colors', 'always') !== 'never';
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, $isDecorated);
$container = Container::getInstance();
$container->add(TestSuite::class, $testSuite);

View File

File diff suppressed because it is too large Load Diff

View File

@ -17,22 +17,21 @@
}
],
"require": {
"php": "^7.3",
"nunomaduro/collision": "^5.0.0-BETA3",
"pestphp/pest-plugin": "^0.2",
"pestphp/pest-plugin-coverage": "^0.2",
"pestphp/pest-plugin-init": "^0.2",
"phpunit/phpunit": "^9.1.4",
"sebastian/environment": "^5.1"
"php": "^7.3 || ^8.0",
"nunomaduro/collision": "^5.0",
"pestphp/pest-plugin": "^0.3",
"pestphp/pest-plugin-coverage": "^0.3",
"pestphp/pest-plugin-expectations": "^0.3.3",
"pestphp/pest-plugin-init": "^0.3",
"phpunit/phpunit": ">= 9.3.7 <= 9.5.0"
},
"autoload": {
"psr-4": {
"Pest\\": "src/"
},
"files": [
"src/globals.php",
"src/Pest.php",
"compiled/globals.php"
"src/Functions.php",
"src/Pest.php"
]
},
"autoload-dev": {
@ -44,16 +43,11 @@
]
},
"require-dev": {
"ergebnis/phpstan-rules": "^0.15.0",
"friendsofphp/php-cs-fixer": "^2.16.3",
"illuminate/console": "^7.16.1",
"illuminate/support": "^7.16.1",
"mockery/mockery": "^1.4.0",
"phpstan/phpstan": "^0.12.30",
"phpstan/phpstan-strict-rules": "^0.12.2",
"rector/rector": "^0.7.37",
"symfony/var-dumper": "^5.1.2",
"thecodingmachine/phpstan-strict-rules": "^0.12.0"
"laravel/dusk": "^6.9.1",
"mockery/mockery": "^1.4.1",
"pestphp/pest-dev-tools": "dev-master"
},
"minimum-stability": "dev",
"prefer-stable": true,
@ -65,9 +59,8 @@
"bin/pest"
],
"scripts": {
"compile": "@php ./scripts/compile.php",
"lint": "rector process src && php-cs-fixer fix -v",
"test:lint": "php-cs-fixer fix -v --dry-run && rector process src --dry-run",
"lint": "php-cs-fixer fix -v",
"test:lint": "php-cs-fixer fix -v --dry-run",
"test:types": "phpstan analyse --ansi --memory-limit=0",
"test:unit": "php bin/pest --colors=always --exclude-group=integration",
"test:integration": "php bin/pest --colors=always --group=integration",
@ -81,7 +74,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "0.2.x-dev"
"dev-master": "0.3.x-dev"
},
"pest": {
"plugins": [

View File

@ -7,17 +7,26 @@ parameters:
level: max
paths:
- src
excludes_analyse:
- src/globals.php
checkMissingIterableValueType: true
checkGenericClassInNonGenericObjectType: false
reportUnmatchedIgnoredErrors: true
ignoreErrors:
- "#type mixed is not subtype of native#"
- "#Undefined variable: \\$this#"
- "#is not allowed to extend#"
- "#Language construct eval#"
- "# with null as default value#"
- "#has parameter \\$closure with default value.#"
- "#has parameter \\$description with default value.#"
- "#Method Pest\\\\Support\\\\Reflection::getParameterClassName\\(\\) has a nullable return type declaration.#"
-
message: '#Call to an undefined method PHPUnit\\Framework\\Test::getName\(\)#'
path: src/TeamCity.php
-
message: '#invalid typehint type Pest\\Concerns\\TestCase#'
path: src/TeamCity.php
-
message: '#is not subtype of native type PHPUnit\\Framework\\Test#'
path: src/TeamCity.php

View File

@ -8,9 +8,9 @@
<directory suffix=".php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>

View File

@ -1,16 +0,0 @@
# rector.yaml
parameters:
sets:
- 'action-injection-to-constructor-injection'
- 'array-str-functions-to-static-call'
- 'celebrity'
- 'doctrine'
- 'phpstan'
- 'phpunit-code-quality'
- 'solid'
- 'early-return'
- 'doctrine-code-quality'
- 'code-quality'
- 'php71'
- 'php72'
- 'php73'

View File

@ -5,12 +5,16 @@ declare(strict_types=1);
namespace Pest\Actions;
use NunoMaduro\Collision\Adapters\Phpunit\Printer;
use Pest\TeamCity;
use PHPUnit\TextUI\DefaultResultPrinter;
/**
* @internal
*/
final class AddsDefaults
{
private const PRINTER = 'printer';
/**
* Adds default arguments to the given `arguments` array.
*
@ -20,8 +24,12 @@ final class AddsDefaults
*/
public static function to(array $arguments): array
{
if (!array_key_exists('printer', $arguments)) {
$arguments['printer'] = new Printer(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? 'always');
if (!array_key_exists(self::PRINTER, $arguments)) {
$arguments[self::PRINTER] = new Printer(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? DefaultResultPrinter::COLOR_ALWAYS);
}
if ($arguments[self::PRINTER] === \PHPUnit\Util\Log\TeamCity::class) {
$arguments[self::PRINTER] = new TeamCity($arguments['verbose'] ?? false, $arguments['colors'] ?? DefaultResultPrinter::COLOR_ALWAYS);
}
return $arguments;

View File

@ -21,6 +21,7 @@ final class LoadStructure
* @var array<int, string>
*/
private const STRUCTURE = [
'Expectations.php',
'Datasets.php',
'Helpers.php',
'Pest.php',

View File

@ -6,8 +6,7 @@ namespace Pest\Actions;
use Pest\Exceptions\AttributeNotSupportedYet;
use Pest\Exceptions\FileOrFolderNotFound;
use PHPUnit\TextUI\Configuration\Configuration;
use PHPUnit\TextUI\Configuration\Registry;
use PHPUnit\TextUI\XmlConfiguration\Loader;
/**
* @internal
@ -30,9 +29,7 @@ final class ValidatesConfiguration
throw new FileOrFolderNotFound('phpunit.xml');
}
$configuration = Registry::getInstance()
->get($arguments[self::CONFIGURATION_KEY])
->phpunit();
$configuration = (new Loader())->load($arguments[self::CONFIGURATION_KEY])->phpunit();
if ($configuration->processIsolation()) {
throw new AttributeNotSupportedYet('processIsolation', 'true');

View File

@ -7,7 +7,9 @@ namespace Pest\Concerns;
use Closure;
use Pest\Support\ExceptionTrace;
use Pest\TestSuite;
use PHPUnit\Framework\ExecutionOrderDependency;
use PHPUnit\Util\Test;
use Throwable;
/**
* To avoid inheritance conflicts, all the fields related
@ -53,6 +55,24 @@ trait TestCase
$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);
}
/**
* Returns the test case name. Note that, in Pest
* we ignore withDataset argument as the description
@ -63,6 +83,11 @@ trait TestCase
return $this->__description;
}
public static function __getFileName(): string
{
return self::$__filename;
}
/**
* This method is called before the first test of this test class is run.
*/
@ -132,7 +157,7 @@ trait TestCase
*
* @return mixed
*
* @throws \Throwable
* @throws Throwable
*/
public function __test()
{
@ -142,7 +167,7 @@ trait TestCase
/**
* @return mixed
*
* @throws \Throwable
* @throws Throwable
*/
private function __callClosure(Closure $closure, array $arguments)
{

View File

@ -11,6 +11,8 @@ use Pest\Actions\ValidatesConfiguration;
use Pest\Contracts\Plugins\AddsOutput;
use Pest\Contracts\Plugins\HandlesArguments;
use Pest\Plugin\Loader;
use Pest\Plugins\Version;
use Pest\Support\Container;
use Pest\TestSuite;
use PHPUnit\Framework\TestSuite as BaseTestSuite;
use PHPUnit\TextUI\Command as BaseCommand;
@ -139,4 +141,14 @@ final class Command extends BaseCommand
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
View 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);
}
}
}

View File

@ -18,14 +18,14 @@ final class Datasets
/**
* Holds the datasets.
*
* @var array<string, \Closure|iterable<int, mixed>>
* @var array<int|string, Closure|iterable<int|string, mixed>>
*/
private static $datasets = [];
/**
* Sets the given.
*
* @param Closure|iterable<int, mixed> $data
* @param Closure|iterable<int|string, mixed> $data
*/
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)
{
@ -51,7 +51,7 @@ final class Datasets
/**
* 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>
*/
@ -77,10 +77,10 @@ final class Datasets
$dataSetDescriptions = [];
$dataSetValues = [];
foreach ($data as $values) {
foreach ($data as $key => $values) {
$values = is_array($values) ? $values : [$values];
$dataSetDescriptions[] = $description . self::getDataSetDescription($values);
$dataSetDescriptions[] = $description . self::getDataSetDescription($key, $values);
$dataSetValues[] = $values;
}
@ -104,12 +104,15 @@ final class Datasets
}
/**
* @param int|string $key
* @param array<int, mixed> $data
*/
private static function getDataSetDescription(array $data): string
private static function getDataSetDescription($key, array $data): string
{
$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));
}
}

View File

@ -59,7 +59,7 @@ final class TestCaseFactory
/**
* Holds the dataset, if any.
*
* @var Closure|iterable<int, mixed>|string|null
* @var Closure|iterable<int|string, mixed>|string|null
*/
public $dataset;
@ -157,8 +157,7 @@ final class TestCaseFactory
}
/**
* Makes a fully qualified class name
* from the given filename.
* Makes a fully qualified class name from the given filename.
*/
public function makeClassFromFilename(string $filename): string
{

View File

@ -35,7 +35,7 @@ function beforeEach(Closure $closure = null): BeforeEachCall
/**
* Registers the given dataset.
*
* @param Closure|iterable $dataset
* @param Closure|iterable<int|string, mixed> $dataset
*/
function dataset(string $name, $dataset): void
{
@ -43,8 +43,8 @@ function dataset(string $name, $dataset): void
}
/**
* The uses function adds the binds the
* given arguments to test closures.
* The uses function binds the given
* arguments to test closures.
*/
function uses(string ...$classAndTraits): UsesCall
{
@ -62,7 +62,7 @@ function uses(string ...$classAndTraits): UsesCall
*/
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);
}
@ -100,7 +100,7 @@ function afterEach(Closure $closure = null): AfterEachCall
/**
* 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);
}

View File

@ -61,7 +61,8 @@ final class PestDatasetCommand extends Command
$element = Str::singular($name);
$contents = str_replace('{dataset_element}', $element, $contents);
File::put($target, str_replace('{dataset_name}', $name, $contents));
$message = sprintf('`%s` created successfully.', $relativePath);
$this->output->success(sprintf('`%s` created successfully.', $relativePath));
$this->output->success($message);
}
}

View File

@ -0,0 +1,41 @@
<?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 {--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/bin/pest'];
}
return [PHP_BINARY, 'vendor/bin/pest'];
}
}

View File

@ -6,6 +6,7 @@ namespace Pest\Laravel\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Pest\Console\Thanks;
use Pest\Exceptions\InvalidConsoleArgument;
use Pest\Support\Str;
@ -60,7 +61,9 @@ final class PestInstallCommand extends Command
$this->output->success('`tests/Pest.php` created successfully.');
$this->output->success('`tests/Helpers.php` created successfully.');
(new \Pest\Console\Thanks($this->output))();
if (!(bool) $this->option('no-interaction')) {
(new Thanks($this->output))();
}
}
/**

View File

@ -64,7 +64,8 @@ final class PestTestCommand extends Command
$name = Str::endsWith($name, 'test') ? mb_substr($name, 0, -4) : $name;
File::put($target, str_replace('{name}', $name, $contents));
$message = sprintf('`%s` created successfully.', $relativePath);
$this->output->success(sprintf('`%s` created successfully.', $relativePath));
$this->output->success($message);
}
}

View File

@ -5,7 +5,9 @@ declare(strict_types=1);
namespace Pest\Laravel;
use Illuminate\Support\ServiceProvider;
use Laravel\Dusk\Console\DuskCommand;
use Pest\Laravel\Commands\PestDatasetCommand;
use Pest\Laravel\Commands\PestDuskCommand;
use Pest\Laravel\Commands\PestInstallCommand;
use Pest\Laravel\Commands\PestTestCommand;
@ -22,6 +24,12 @@ final class PestServiceProvider extends ServiceProvider
PestTestCommand::class,
PestDatasetCommand::class,
]);
if (class_exists(DuskCommand::class)) {
$this->commands([
PestDuskCommand::class,
]);
}
}
}
}

View File

@ -12,6 +12,8 @@ use Pest\TestSuite;
use SebastianBergmann\Exporter\Exporter;
/**
* @method \Pest\Expectation expect(mixed $value)
*
* @internal
*/
final class TestCall
@ -75,7 +77,7 @@ final class TestCall
* Runs the current test multiple times with
* 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
{
@ -91,7 +93,7 @@ final class TestCall
{
$this->testCaseFactory
->factoryProxies
->add(Backtrace::file(), Backtrace::line(), 'setDependencies', [$tests]);
->add(Backtrace::file(), Backtrace::line(), 'addDependencies', [$tests]);
return $this;
}

View File

@ -6,5 +6,5 @@ namespace Pest;
function version(): string
{
return '0.2.2';
return '0.3.18';
}

View File

@ -11,6 +11,7 @@ use Pest\Exceptions\TestCaseClassOrTraitNotFound;
use Pest\Factories\TestCaseFactory;
use Pest\Support\Str;
use Pest\TestSuite;
use PHPUnit\Framework\TestCase;
/**
* @internal
@ -52,7 +53,7 @@ final class TestRepository
if ((!is_dir($path) && $filename === $path) || (is_dir($path) && $startsWith($filename, $path))) {
foreach ($classOrTraits as $class) {
if (class_exists($class)) {
if ($testCase->class !== \PHPUnit\Framework\TestCase::class) {
if ($testCase->class !== TestCase::class) {
throw new TestCaseAlreadyInUse($testCase->class, $class, $filename);
}
$testCase->class = $class;

View File

@ -75,14 +75,15 @@ final class Container
if ($constructor !== null) {
$params = array_map(
function (ReflectionParameter $param) use ($id) {
$candidate = null;
$candidate = Reflection::getParameterClassName($param);
if ($param->getType() !== null && $param->getType()->isBuiltin()) {
$candidate = $param->getName();
} elseif ($param->getClass() !== null) {
$candidate = $param->getClass()->getName();
} else {
throw ShouldNotHappen::fromMessage(sprintf('The type of `$%s` in `%s` cannot be determined.', $id, $param->getName()));
if ($candidate === null) {
$type = $param->getType();
if ($type !== null && $type->isBuiltin()) {
$candidate = $param->getName();
} else {
throw ShouldNotHappen::fromMessage(sprintf('The type of `$%s` in `%s` cannot be determined.', $id, $param->getName()));
}
}
return $this->get($candidate);

View File

@ -20,7 +20,7 @@ final class ExceptionTrace
*
* @return mixed
*
* @throws \Throwable
* @throws Throwable
*/
public static function ensure(Closure $closure)
{

View File

@ -76,8 +76,8 @@ final class HigherOrderMessage
Reflection::setPropertyValue($throwable, 'file', $this->filename);
Reflection::setPropertyValue($throwable, 'line', $this->line);
if ($throwable->getMessage() === sprintf(self::UNDEFINED_METHOD, $this->methodName)) {
/** @var \ReflectionClass $reflection */
if ($throwable->getMessage() === self::getUndefinedMethodMessage($target, $this->methodName)) {
/** @var ReflectionClass $reflection */
$reflection = new ReflectionClass($target);
/* @phpstan-ignore-next-line */
$reflection = $reflection->getParentClass() ?: $reflection;
@ -87,4 +87,13 @@ final class HigherOrderMessage
throw $throwable;
}
}
private static function getUndefinedMethodMessage(object $target, string $methodName): string
{
if (\PHP_MAJOR_VERSION >= 8) {
return sprintf(sprintf(self::UNDEFINED_METHOD, sprintf('%s::%s()', get_class($target), $methodName)));
}
return sprintf(self::UNDEFINED_METHOD, $methodName);
}
}

View File

@ -30,7 +30,7 @@ final class HigherOrderMessageCollection
public function chain(object $target): void
{
foreach ($this->messages as $message) {
$target = $message->call($target);
$target = $message->call($target) ?? $target;
}
}

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Pest\Support;
use ReflectionClass;
use Throwable;
/**
* @internal
@ -51,12 +52,12 @@ final class HigherOrderTapProxy
try {
// @phpstan-ignore-next-line
return $this->target->{$property};
} catch (\Throwable $throwable) {
} catch (Throwable $throwable) {
Reflection::setPropertyValue($throwable, 'file', Backtrace::file());
Reflection::setPropertyValue($throwable, 'line', Backtrace::line());
if (Str::startsWith($message = $throwable->getMessage(), self::UNDEFINED_PROPERTY)) {
/** @var \ReflectionClass $reflection */
/** @var ReflectionClass $reflection */
$reflection = (new ReflectionClass($this->target))->getParentClass();
Reflection::setPropertyValue($throwable, 'message', sprintf('Undefined property %s::$%s', $reflection->getName(), $property));
}

View File

@ -6,9 +6,12 @@ namespace Pest\Support;
use Closure;
use Pest\Exceptions\ShouldNotHappen;
use Pest\TestSuite;
use ReflectionClass;
use ReflectionException;
use ReflectionFunction;
use ReflectionNamedType;
use ReflectionParameter;
use ReflectionProperty;
/**
@ -38,6 +41,12 @@ final class Reflection
return $object->__call($method, $args);
}
if (is_callable($method)) {
return Closure::fromCallable($method)->bindTo(
TestSuite::getInstance()->test
)(...$args);
}
throw $exception;
}
}
@ -117,4 +126,32 @@ final class Reflection
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($object, $value);
}
/**
* Get the class name of the given parameter's type, if possible.
*
* @see https://github.com/laravel/framework/blob/v6.18.25/src/Illuminate/Support/Reflector.php
*/
public static function getParameterClassName(ReflectionParameter $parameter): ?string
{
$type = $parameter->getType();
if (!$type instanceof ReflectionNamedType || $type->isBuiltin()) {
return null;
}
$name = $type->getName();
if (($class = $parameter->getDeclaringClass()) instanceof ReflectionClass) {
if ($name === 'self') {
return $class->getName();
}
if ($name === 'parent' && ($parent = $class->getParentClass()) instanceof ReflectionClass) {
return $parent->getName();
}
}
return $name;
}
}

213
src/TeamCity.php Normal file
View File

@ -0,0 +1,213 @@
<?php
declare(strict_types=1);
namespace Pest;
use function getmypid;
use Pest\Concerns\TestCase;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestResult;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;
use PHPUnit\TextUI\DefaultResultPrinter;
use function round;
use function str_replace;
use Throwable;
final class TeamCity extends DefaultResultPrinter
{
private const PROTOCOL = 'pest_qn://';
private const NAME = 'name';
private const LOCATION_HINT = 'locationHint';
private const DURATION = 'duration';
private const TEST_SUITE_STARTED = 'testSuiteStarted';
private const TEST_SUITE_FINISHED = 'testSuiteFinished';
/** @var int */
private $flowId;
/** @var bool */
private $isSummaryTestCountPrinted = false;
/** @var \PHPUnit\Util\Log\TeamCity */
private $phpunitTeamCity;
public function __construct(bool $verbose, string $colors)
{
parent::__construct(null, $verbose, $colors, false, 80, false);
$this->phpunitTeamCity = new \PHPUnit\Util\Log\TeamCity(
null,
$verbose,
$colors,
false,
80,
false
);
}
public function printResult(TestResult $result): void
{
$this->printHeader($result);
$this->printFooter($result);
}
/** @phpstan-ignore-next-line */
public function startTestSuite(TestSuite $suite): void
{
$this->flowId = (int) getmypid();
if (!$this->isSummaryTestCountPrinted) {
$this->printEvent(
'testCount',
['count' => $suite->count()]
);
$this->isSummaryTestCountPrinted = true;
}
$suiteName = $suite->getName();
if (file_exists($suiteName) || !method_exists($suiteName, '__getFileName')) {
$this->printEvent(
self::TEST_SUITE_STARTED, [
self::NAME => $suiteName,
self::LOCATION_HINT => self::PROTOCOL . $suiteName,
]);
return;
}
$fileName = $suiteName::__getFileName();
$this->printEvent(
self::TEST_SUITE_STARTED, [
self::NAME => substr($suiteName, 2),
self::LOCATION_HINT => self::PROTOCOL . $fileName,
]);
}
/** @phpstan-ignore-next-line */
public function endTestSuite(TestSuite $suite): void
{
$suiteName = $suite->getName();
if (file_exists($suiteName) || !method_exists($suiteName, '__getFileName')) {
$this->printEvent(
self::TEST_SUITE_FINISHED, [
self::NAME => $suiteName,
self::LOCATION_HINT => self::PROTOCOL . $suiteName,
]);
return;
}
$this->printEvent(
self::TEST_SUITE_FINISHED, [
self::NAME => substr($suiteName, 2),
]);
}
/**
* @param Test|TestCase $test
*/
public function startTest(Test $test): void
{
if (!TeamCity::isPestTest($test)) {
$this->phpunitTeamCity->startTest($test);
return;
}
$this->printEvent('testStarted', [
self::NAME => $test->getName(),
/* @phpstan-ignore-next-line */
self::LOCATION_HINT => self::PROTOCOL . $test->toString(),
]);
}
/**
* @param Test|TestCase $test
*/
public function endTest(Test $test, float $time): void
{
if (!TeamCity::isPestTest($test)) {
$this->phpunitTeamCity->endTest($test, $time);
return;
}
$this->printEvent('testFinished', [
self::NAME => $test->getName(),
self::DURATION => self::toMilliseconds($time),
]);
}
/**
* @param Test|TestCase $test
*/
public function addError(Test $test, Throwable $t, float $time): void
{
$this->phpunitTeamCity->addError($test, $t, $time);
}
/**
* @phpstan-ignore-next-line
*
* @param Test|TestCase $test
*/
public function addWarning(Test $test, Warning $e, float $time): void
{
$this->phpunitTeamCity->addWarning($test, $e, $time);
}
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
{
$this->phpunitTeamCity->addFailure($test, $e, $time);
}
protected function writeProgress(string $progress): void
{
}
/**
* @param array<string, string|int> $params
*/
private function printEvent(string $eventName, array $params = []): void
{
$this->write("\n##teamcity[{$eventName}");
if ($this->flowId !== 0) {
$params['flowId'] = $this->flowId;
}
foreach ($params as $key => $value) {
$escapedValue = self::escapeValue((string) $value);
$this->write(" {$key}='{$escapedValue}'");
}
$this->write("]\n");
}
private static function escapeValue(string $text): string
{
return str_replace(
['|', "'", "\n", "\r", ']', '['],
['||', "|'", '|n', '|r', '|]', '|['],
$text
);
}
private static function toMilliseconds(float $time): int
{
return (int) round($time * 1000);
}
private static function isPestTest(Test $test): bool
{
/** @var array<string, string> $uses */
$uses = class_uses($test);
return in_array(TestCase::class, $uses, true);
}
}

View File

@ -10,6 +10,7 @@ use Pest\Repositories\AfterEachRepository;
use Pest\Repositories\BeforeAllRepository;
use Pest\Repositories\BeforeEachRepository;
use Pest\Repositories\TestRepository;
use PHPUnit\Framework\TestCase;
/**
* @internal
@ -19,7 +20,7 @@ final class TestSuite
/**
* Holds the current test case.
*
* @var \PHPUnit\Framework\TestCase|null
* @var TestCase|null
*/
public $test;

View File

@ -12,10 +12,10 @@
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./app</directory>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>

View File

@ -9,9 +9,9 @@
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>

View 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)

View File

@ -40,6 +40,9 @@
✓ eager wrapped registered datasets with (1)
✓ eager wrapped registered datasets with (2)
✓ 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 (...))
✓ 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
@ -49,14 +52,6 @@
✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #3
✓ it creates unique test case names - count
PASS Tests\Features\Depends
✓ first
✓ second
✓ depends
✓ depends with ...params
✓ depends with defined arguments
✓ depends run test only once
PASS Tests\Features\Exceptions
✓ it gives access the the underlying expectException
✓ it catch exceptions
@ -67,9 +62,11 @@
✓ it throws error if property do not exist
✓ it allows to call underlying protected/private methods
✓ it throws error if method do not exist
✓ it can forward unexpected calls to any global function
PASS Tests\Features\HigherOrderTests
✓ it proxies calls to object
✓ it is capable doing multiple assertions
PASS Tests\Features\It
✓ it is a test
@ -83,8 +80,8 @@
✓ it has bar
PASS Tests\Features\PendingHigherOrderTests
✓ get 'foo' → get 'bar' → assertTrue true
✓ get 'foo' → assertTrue true
✓ get 'foo' → get 'bar' → expect true → toBeTrue
✓ get 'foo' → expect true → toBeTrue
WARN Tests\Features\Skip
✓ it do not skips
@ -94,6 +91,7 @@
- it skips with truthy closure condition
✓ it do not skips with falsy closure condition
- it skips with condition and message → skipped because foo
- it skips when skip after assertion
PASS Tests\Features\Test
✓ a test
@ -135,6 +133,12 @@
✓ it throws exception when `process isolation` is true
✓ 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
✓ it outputs the version when --version is used
✓ it do not outputs version when --version is not used
@ -158,6 +162,9 @@
PASS Tests\Unit\TestSuite
✓ 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
✓ allows to run a single test
✓ allows to run a directory
@ -167,5 +174,19 @@
WARN Tests\Visual\Success
- visual snapshot of test suite on success
Tests: 6 skipped, 96 passed
Time: 3.43s
PASS Tests\Features\Depends
✓ first
✓ second
✓ it asserts true is true
✓ depends
✓ depends with ...params
✓ depends with defined arguments
✓ depends run test only once
✓ depends works with the correct test name
PASS Tests\Features\DependsInheritance
✓ it is a test
✓ it uses correct parent class
Tests: 7 skipped, 108 passed

View File

@ -8,7 +8,7 @@ trait PluginTrait
{
public function assertPluginTraitGotRegistered(): void
{
assertTrue(true);
$this->assertTrue(true);
}
}
@ -16,9 +16,14 @@ trait SecondPluginTrait
{
public function assertSecondPluginTraitGotRegistered(): void
{
assertTrue(true);
$this->assertTrue(true);
}
}
Pest\Plugin::uses(PluginTrait::class);
Pest\Plugin::uses(SecondPluginTrait::class);
function _assertThat()
{
expect(true)->toBeTrue();
}

View File

@ -8,8 +8,8 @@ afterAll(function () use ($file) {
test('deletes file after all', function () use ($file) {
file_put_contents($file, 'foo');
assertFileExists($file);
$this->assertFileExists($file);
register_shutdown_function(function () use ($file) {
assertFileNotExists($file);
$this->assertFileNotExists($file);
});
});

View File

@ -6,15 +6,15 @@ beforeEach(function () use ($state) {
$this->state = $state;
});
afterEach(function () use ($state) {
afterEach(function () {
$this->state->bar = 2;
});
it('does not get executed before the test', function () {
assertFalse(property_exists($this->state, 'bar'));
expect($this->state)->not->toHaveProperty('bar');
});
it('gets executed after the test', function () {
assertTrue(property_exists($this->state, 'bar'));
assertEquals(2, $this->state->bar);
expect($this->state)->toHaveProperty('bar');
expect($this->state->bar)->toBe(2);
});

View File

@ -8,11 +8,11 @@ beforeAll(function () use ($foo) {
});
it('gets executed before tests', function () use ($foo) {
assertEquals($foo->bar, 1);
expect($foo->bar)->toBe(1);
$foo->bar = 'changed';
});
it('do not get executed before each test', function () use ($foo) {
assertEquals($foo->bar, 'changed');
expect($foo->bar)->toBe('changed');
});

View File

@ -5,11 +5,11 @@ beforeEach(function () {
});
it('gets executed before each test', function () {
assertEquals($this->bar, 2);
expect($this->bar)->toBe(2);
$this->bar = 'changed';
});
it('gets executed before each test once again', function () {
assertEquals($this->bar, 2);
expect($this->bar)->toBe(2);
});

View File

@ -23,13 +23,13 @@ it('sets closures', function () {
yield [1];
});
assertEquals([[1]], iterator_to_array(Datasets::get('foo')()));
expect(iterator_to_array(Datasets::get('foo')()))->toBe([[1]]);
});
it('sets arrays', function () {
Datasets::set('bar', [[2]]);
assertEquals([[2]], Datasets::get('bar'));
expect(Datasets::get('bar'))->toBe([[2]]);
});
it('gets bound to test case object', function () {
@ -37,7 +37,7 @@ it('gets bound to test case object', function () {
})->with([['a'], ['b']]);
test('it truncates the description', function () {
assertTrue(true);
expect(true)->toBe(true);
// it gets tested by the integration test
})->with([str_repeat('Fooo', 10000000)]);
@ -48,51 +48,63 @@ $datasets = [[1], [2]];
test('lazy datasets', function ($text) use ($state, $datasets) {
$state->text .= $text;
assertTrue(in_array([$text], $datasets));
expect(in_array([$text], $datasets))->toBe(true);
})->with($datasets);
test('lazy datasets did the job right', function () use ($state) {
assertEquals('12', $state->text);
expect($state->text)->toBe('12');
});
$state->text = '';
test('eager datasets', function ($text) use ($state, $datasets) {
$state->text .= $text;
assertTrue(in_array([$text], $datasets));
expect($datasets)->toContain([$text]);
})->with(function () use ($datasets) {
return $datasets;
});
test('eager datasets did the job right', function () use ($state) {
assertEquals('1212', $state->text);
expect($state->text)->toBe('1212');
});
test('lazy registered datasets', function ($text) use ($state, $datasets) {
$state->text .= $text;
assertTrue(in_array([$text], $datasets));
expect($datasets)->toContain([$text]);
})->with('numbers.array');
test('lazy registered datasets did the job right', function () use ($state) {
assertEquals('121212', $state->text);
expect($state->text)->toBe('121212');
});
test('eager registered datasets', function ($text) use ($state, $datasets) {
$state->text .= $text;
assertTrue(in_array([$text], $datasets));
expect($datasets)->toContain([$text]);
})->with('numbers.closure');
test('eager registered datasets did the job right', function () use ($state) {
assertEquals('12121212', $state->text);
expect($state->text)->toBe('12121212');
});
test('eager wrapped registered datasets', function ($text) use ($state, $datasets) {
$state->text .= $text;
assertTrue(in_array([$text], $datasets));
expect($datasets)->toContain([$text]);
})->with('numbers.closure.wrapped');
test('eager registered wrapped datasets did the job right', function () use ($state) {
assertEquals('1212121212', $state->text);
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
@ -104,14 +116,14 @@ $namedDatasets = [
new Bar(),
];
test('lazy named datasets', function ($text) use ($state, $datasets) {
assertTrue(true);
test('lazy named datasets', function ($text) {
expect(true)->toBeTrue();
})->with($namedDatasets);
$counter = 0;
it('creates unique test case names', function (string $name, Plugin $plugin, bool $bool) use (&$counter) {
assertTrue(true);
expect(true)->toBeTrue();
$counter++;
})->with([
['Name 1', new Plugin(), true],
@ -123,5 +135,5 @@ it('creates unique test case names', function (string $name, Plugin $plugin, boo
]);
it('creates unique test case names - count', function () use (&$counter) {
assertEquals(6, $counter);
expect($counter)->toBe(6);
});

View File

@ -3,38 +3,36 @@
$runCounter = 0;
test('first', function () use (&$runCounter) {
assertTrue(true);
expect(true)->toBeTrue();
$runCounter++;
return 'first';
});
test('second', function () use (&$runCounter) {
assertTrue(true);
expect(true)->toBeTrue();
$runCounter++;
return 'second';
});
test('depends', function () {
assertEquals(
['first', 'second'],
func_get_args()
);
expect(func_get_args())->toBe(['first', 'second']);
})->depends('first', 'second');
test('depends with ...params', function (string ...$params) {
assertEquals(
['first', 'second'],
$params
);
expect(func_get_args())->toBe($params);
})->depends('first', 'second');
test('depends with defined arguments', function (string $first, string $second) {
assertEquals('first', $first);
assertEquals('second', $second);
expect($first)->toBe('first');
expect($second)->toBe('second');
})->depends('first', 'second');
test('depends run test only once', function () use (&$runCounter) {
assertEquals(2, $runCounter);
expect($runCounter)->toBe(2);
})->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');

View 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');

View File

@ -7,7 +7,7 @@ function addUser()
it('can set/get properties on $this', function () {
addUser();
assertEquals('nuno', $this->user);
expect($this->user)->toBe('nuno');
});
it('throws error if property do not exist', function () {
@ -27,17 +27,18 @@ function mockUser()
$mock = test()->createMock(User::class);
$mock->method('getName')
->willReturn('maduro');
->willReturn('maduro');
return $mock;
}
it('allows to call underlying protected/private methods', function () {
$user = mockUser();
assertEquals('maduro', $user->getName());
expect($user->getName())->toBe('maduro');
});
it('throws error if method do not exist', function () {
test()->name();
})->throws(\ReflectionException::class, 'Call to undefined method PHPUnit\Framework\TestCase::name()');
it('can forward unexpected calls to any global function')->_assertThat();

View File

@ -4,4 +4,8 @@ beforeEach()->assertTrue(true);
it('proxies calls to object')->assertTrue(true);
it('is capable doing multiple assertions')
->assertTrue(true)
->assertFalse(false);
afterEach()->assertTrue(true);

View File

@ -1,7 +1,7 @@
<?php
it('is a test', function () {
assertArrayHasKey('key', ['key' => 'foo']);
$this->assertArrayHasKey('key', ['key' => 'foo']);
});
it('is a higher order message test')->assertTrue(true);
it('is a higher order message test')->expect(true)->toBeTrue();

View File

@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase;
uses(Macroable::class);
beforeEach()->macro('bar', function () {
assertInstanceOf(TestCase::class, $this);
expect($this)->toBeInstanceOf(TestCase::class);
});
it('can call chained macro method')->bar();

View File

@ -1,11 +1,12 @@
<?php
use Pest\PendingObjects\TestCall;
use PHPUnit\Framework\TestCase;
uses(Gettable::class);
/**
* @return TestCase|Gettable
* @return TestCase|TestCall|Gettable
*/
function get(string $route)
{
@ -15,15 +16,15 @@ function get(string $route)
trait Gettable
{
/**
* @return TestCase|Gettable
* @return TestCase|TestCall|Gettable
*/
public function get(string $route)
{
assertNotEmpty($route);
expect($route)->not->toBeEmpty();
return $this;
}
}
get('foo')->get('bar')->assertTrue(true);
get('foo')->assertTrue(true);
get('foo')->get('bar')->expect(true)->toBeTrue();
get('foo')->expect(true)->toBeTrue();

View File

@ -27,3 +27,7 @@ it('do not skips with falsy closure condition')
it('skips with condition and message')
->skip(true, 'skipped because foo')
->assertTrue(false);
it('skips when skip after assertion')
->assertTrue(true)
->skip();

View File

@ -1,7 +1,7 @@
<?php
test('a test', function () {
assertArrayHasKey('key', ['key' => 'foo']);
$this->assertArrayHasKey('key', ['key' => 'foo']);
});
test('higher order message test')->assertTrue(true);
test('higher order message test')->expect(true)->toBeTrue();

View File

@ -1,5 +1,7 @@
<?php
use function PHPUnit\Framework\assertFalse;
$foo = new stdClass();
$foo->beforeAll = false;
$foo->beforeEach = false;

View File

@ -10,6 +10,6 @@ class CustomTestCaseInSubFolder extends TestCase
{
public function assertCustomInSubFolderTrue()
{
assertTrue(true);
$this->assertTrue(true);
}
}

View File

@ -12,7 +12,7 @@ class MyCustomClass extends PHPUnit\Framework\TestCase
{
public function assertTrueIsTrue()
{
assertTrue(true);
$this->assertTrue(true);
}
}

View File

@ -1,5 +1,5 @@
<?php
test('basic', function () {
assertTrue(true);
expect(true)->toBeTrue();
});

View File

@ -7,14 +7,14 @@ use PHPUnit\TextUI\DefaultResultPrinter;
it('sets defaults', function () {
$arguments = AddsDefaults::to(['bar' => 'foo']);
assertInstanceOf(Printer::class, $arguments['printer']);
assertEquals($arguments['bar'], 'foo');
expect($arguments['printer'])->toBeInstanceOf(Printer::class);
expect($arguments['bar'])->toBe('foo');
});
it('does not override options', function () {
$defaultResultPrinter = new DefaultResultPrinter();
assertEquals(AddsDefaults::to(['printer' => $defaultResultPrinter]), [
expect(AddsDefaults::to(['printer' => $defaultResultPrinter]))->tobe([
'printer' => $defaultResultPrinter,
]);
});

View File

@ -16,17 +16,17 @@ test('default php unit tests', function () {
$phpUnitTestCase = new class() extends PhpUnitTestCase {
};
$testSuite->addTest($phpUnitTestCase);
assertCount(1, $testSuite->tests());
expect($testSuite->tests())->toHaveCount(1);
AddsTests::to($testSuite, new \Pest\TestSuite(getcwd()));
assertCount(1, $testSuite->tests());
expect($testSuite->tests())->toHaveCount(1);
});
it('removes warnings', function () use ($pestTestCase) {
it('removes warnings', function () {
$testSuite = new TestSuite();
$warningTestCase = new WarningTestCase('No tests found in class "Pest\TestCase".');
$testSuite->addTest($warningTestCase);
AddsTests::to($testSuite, new \Pest\TestSuite(getcwd()));
assertCount(0, $testSuite->tests());
expect($testSuite->tests())->toHaveCount(0);
});

View File

@ -38,5 +38,5 @@ it('do not throws exception when `process isolation` is false', function () {
'configuration' => $filename,
]);
assertTrue(true);
expect(true)->toBeTrue();
});

View File

@ -0,0 +1,12 @@
<?php
use Pest\Console\Help;
use Symfony\Component\Console\Output\BufferedOutput;
it('outputs the help information when --help is used', function () {
$output = new BufferedOutput();
$plugin = new Help($output);
$plugin();
expect($output->fetch())->toContain('Pest Options:');
});

13
tests/Unit/Datasets.php Normal file
View File

@ -0,0 +1,13 @@
<?php
use Pest\Datasets;
it('show the names of named datasets in their description', function () {
$descriptions = array_keys(Datasets::resolve('test description', [
'one' => [1],
'two' => [[2]],
]));
expect($descriptions[0])->toBe('test description with data set "one" (1)');
expect($descriptions[1])->toBe('test description with data set "two" (array(2))');
});

View File

@ -1,6 +1,7 @@
<?php
use Pest\Plugins\Version;
use function Pest\version;
use Symfony\Component\Console\Output\BufferedOutput;
it('outputs the version when --version is used', function () {
@ -8,7 +9,7 @@ it('outputs the version when --version is used', function () {
$plugin = new Version($output);
$plugin->handleArguments(['foo', '--version']);
assertStringContainsString('Pest 0.2.2', $output->fetch());
expect($output->fetch())->toContain('Pest ' . version());
});
it('do not outputs version when --version is not used', function () {
@ -16,5 +17,5 @@ it('do not outputs version when --version is not used', function () {
$plugin = new Version($output);
$plugin->handleArguments(['foo', 'bar']);
assertEquals('', $output->fetch());
expect($output->fetch())->toBe('');
});

View File

@ -7,5 +7,5 @@ it('gets file name from called file', function () {
return Backtrace::file();
};
assertEquals(__FILE__, $a());
expect($a())->toBe(__FILE__);
});

View File

@ -15,32 +15,32 @@ it('exists')
it('gets an instance', function () {
$this->container->add(Container::class, $this->container);
assertSame($this->container, $this->container->get(Container::class));
expect($this->container->get(Container::class))->toBe($this->container);
});
test('autowire', function () {
assertInstanceOf(Container::class, $this->container->get(Container::class));
expect($this->container->get(Container::class))->toBeInstanceOf(Container::class);
});
it('creates an instance and resolves parameters', function () {
$this->container->add(Container::class, $this->container);
$instance = $this->container->get(ClassWithDependency::class);
assertInstanceOf(ClassWithDependency::class, $instance);
expect($instance)->toBeInstanceOf(ClassWithDependency::class);
});
it('creates an instance and resolves also sub parameters', function () {
$this->container->add(Container::class, $this->container);
$instance = $this->container->get(ClassWithSubDependency::class);
assertInstanceOf(ClassWithSubDependency::class, $instance);
expect($instance)->toBeInstanceOf(ClassWithSubDependency::class);
});
it('can resolve builtin value types', function () {
$this->container->add('rootPath', getcwd());
$instance = $this->container->get(TestSuite::class);
assertInstanceOf(TestSuite::class, $instance);
expect($instance)->toBeInstanceOf(TestSuite::class);
});
it('cannot resolve a parameter without type', function () {

View File

@ -3,9 +3,10 @@
use Pest\Support\Reflection;
it('gets file name from closure', function () {
$fileName = Reflection::getFileNameFromClosure(function () {});
$fileName = Reflection::getFileNameFromClosure(function () {
});
assertEquals(__FILE__, $fileName);
expect($fileName)->toBe(__FILE__);
});
it('gets property values', function () {
@ -15,5 +16,5 @@ it('gets property values', function () {
$value = Reflection::getPropertyValue($class, 'foo');
assertEquals('bar', $value);
expect($value)->toBe('bar');
});

27
tests/Visual/Help.php Normal file
View File

@ -0,0 +1,27 @@
<?php
use Pest\Console\Help;
use Symfony\Component\Console\Output\BufferedOutput;
test('visual snapshot of help command output', function () {
$snapshot = __DIR__ . '/../.snapshots/help-command.txt';
if (getenv('REBUILD_SNAPSHOTS')) {
$outputBuffer = new BufferedOutput();
$plugin = new Help($outputBuffer);
$plugin();
file_put_contents($snapshot, $outputBuffer->fetch());
}
$output = function () {
$process = (new Symfony\Component\Process\Process(['php', 'bin/pest', '--help']));
$process->run();
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
};
expect($output())->toContain(file_get_contents($snapshot));
})->skip(PHP_OS_FAMILY === 'Windows');

View File

@ -10,7 +10,7 @@ $run = function (string $target, $decorated = false) {
return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
};
$snapshot = function ($name) {
$snapshot = function ($name) {
$testsPath = dirname(__DIR__);
return file_get_contents(implode(DIRECTORY_SEPARATOR, [
@ -21,23 +21,15 @@ $snapshot = function ($name) {
};
test('allows to run a single test', function () use ($run, $snapshot) {
assertStringContainsString(
$snapshot('allows-to-run-a-single-test'),
$run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'));
expect($run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'))->toContain($snapshot('allows-to-run-a-single-test'));
})->skip(PHP_OS_FAMILY === 'Windows');
test('allows to run a directory', function () use ($run, $snapshot) {
assertStringContainsString(
$snapshot('allows-to-run-a-directory'),
$run('tests/Fixtures')
);
expect($run('tests/Fixtures'))->toContain($snapshot('allows-to-run-a-directory'));
})->skip(PHP_OS_FAMILY === 'Windows');
it('has ascii chars', function () use ($run, $snapshot) {
assertStringContainsString(
$snapshot('has-ascii-chars'),
$run('tests/Fixtures/DirectoryWithTests/ExampleTest.php', true)
);
expect($run('tests/Fixtures/DirectoryWithTests/ExampleTest.php', true))->toContain($snapshot('has-ascii-chars'));
})->skip(PHP_OS_FAMILY === 'Windows');
it('disable decorating printer when colors is set to never', function () use ($snapshot) {
@ -49,9 +41,5 @@ it('disable decorating printer when colors is set to never', function () use ($s
], dirname(__DIR__, 2));
$process->run();
$output = $process->getOutput();
assertStringContainsString(
$snapshot('disable-decorating-printer'),
$output
);
expect($output)->toContain($snapshot('disable-decorating-printer'));
})->skip(PHP_OS_FAMILY === 'Windows');

View File

@ -17,12 +17,16 @@ test('visual snapshot of test suite on success', function () {
};
if (getenv('REBUILD_SNAPSHOTS')) {
file_put_contents($snapshot, $output());
// Strip time from end of snapshot
$outputContent = preg_replace('/Time\: \s+\d+\.\d+s\s+/m', '', $output());
file_put_contents($snapshot, $outputContent);
} elseif (!getenv('EXCLUDE')) {
$output = explode("\n", $output());
array_pop($output);
array_pop($output);
assertStringContainsString(implode("\n", $output), file_get_contents($snapshot));
expect(implode("\n", $output))->toContain(file_get_contents($snapshot));
}
})->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE'))
->skip(PHP_OS_FAMILY === 'Windows');