Compare commits

...

34 Commits

Author SHA1 Message Date
66f69617f1 release: 1.21.3 2022-05-12 20:10:25 +01:00
5721e8c29a docs: updates release 2022-05-12 20:06:47 +01:00
546d19fd84 chore: cs 2022-05-12 20:03:22 +01:00
c1b32b9ffb fix: debug in high order tests 2022-05-12 20:03:11 +01:00
298b1e6784 fix: update branch alias for 1.x branch 2022-03-16 09:24:51 +00:00
63f009fadf release: v1.21.2 2022-03-05 19:34:40 +00:00
1066c2270d Merge pull request #487 from fabio-ivona/fix-throws-missing-exception
Fix throws missing exception
2022-03-04 08:57:50 +00:00
984f237a92 phpstan 2022-03-03 15:45:41 +01:00
dccd8239dd handles toThrow exception with a "class not found" error 2022-02-18 18:01:09 +01:00
e103623ecb adds failing test 2022-02-18 18:00:55 +01:00
542fc046d2 Merge pull request #462 from pestphp/revert-461-json_fix
Revert "Fixes `json` in Higher Order Expectations"
2022-01-21 16:48:35 +00:00
4720e0655b Revert "Fixes json in Higher Order Expectations" 2022-01-21 16:48:26 +00:00
a533772fe2 Merge pull request #461 from pestphp/json_fix
Fixes `json` in Higher Order Expectations
2022-01-21 16:46:30 +00:00
2218a0c137 Tweaks 2022-01-21 16:39:10 +00:00
2831629f1b Fixes bug with json method call in Higher Order Expectations. 2022-01-21 16:35:21 +00:00
1b7f1dc5b3 chore(deps): update nunomaduro/collision to ^5.10
This ensures that the minimum dependencies work with PHP 8.1
2021-12-13 20:57:27 +00:00
92b8d32ef7 release: v1.21.1 2021-11-25 16:44:17 +00:00
2969c7a5e3 Merge pull request #442 from pestphp/fix_for_sequence
[1.x] Fix for sequence
2021-11-25 16:40:08 +00:00
63c1faa9f4 Prevents issues with callables in sequence 2021-11-25 16:37:23 +00:00
b5b14ef280 chore: updates changelog branch to 1.x 2021-11-17 11:03:56 +00:00
11eb1903c2 release: v1.21.0 2021-11-17 10:54:00 +00:00
a110848f9b docs: updates changelog 2021-11-17 10:47:28 +00:00
da5c21de8f Update README.md 2021-11-09 01:42:10 +00:00
408ae4cad8 docs: adds spatie.be as platinum sponsor 2021-11-08 18:31:48 +00:00
fc2484a28a Update README.md 2021-11-05 12:00:56 +01:00
de46ee0f64 fix: adds link to xdebug coverage mode 2021-10-10 15:33:27 +01:00
1e011c7b40 fix: warns about xdebug modes 2021-10-10 15:25:02 +01:00
04dcebf3aa Revert "Merge pull request #413 from def-studio/fix_skipping_tests_with_exception_asserting"
This reverts commit e853792a59, reversing
changes made to 205238fcbf.
2021-10-10 14:40:07 +01:00
e853792a59 Merge pull request #413 from def-studio/fix_skipping_tests_with_exception_asserting
Fix skipping tests with exception asserting
2021-10-02 12:01:04 +01:00
b0fbe54181 removes duplicated test 2021-10-02 09:15:52 +02:00
2a649bdfc0 revert previous solution and invert chain and proxy calls in TestCaseFactory.php 2021-10-02 09:09:47 +02:00
e042bf7d3a removes expection expectations if test is marked as skipped 2021-10-01 15:52:45 +02:00
3ff71a4563 adds failing test 2021-10-01 15:52:02 +02:00
205238fcbf docs: updates release process 2021-09-25 13:56:06 +01:00
29 changed files with 416 additions and 61 deletions

View File

@ -2,12 +2,12 @@ name: Changelog
on: on:
push: push:
branches: [ master ] branches: [ 1.x ]
paths: paths:
- CHANGELOG.md - CHANGELOG.md
- .github/workflows/changelog.yml - .github/workflows/changelog.yml
pull_request: pull_request:
branches: [ master ] branches: [ 1.x ]
paths: paths:
- CHANGELOG.md - CHANGELOG.md
jobs: jobs:

View File

@ -4,6 +4,22 @@ 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/).
## [v1.21.3 (2022-05-12)](https://github.com/pestphp/pest/compare/v1.21.2...v1.21.3)
### Fixed
- Debug of high order tests ([c1b32b9](https://github.com/pestphp/pest/commit/c1b32b9ffb5134803c490592454b11b8c05ea27d))
## [v1.21.2 (2022-03-05)](https://github.com/pestphp/pest/compare/v1.21.1...v1.21.2)
### Fixed
- `toThrow` expectation when exception does not exist ([#487](https://github.com/pestphp/pest/pull/487))
## [v1.21.1 (2021-11-25)](https://github.com/pestphp/pest/compare/v1.21.0...v1.21.1)
### Fixed
- sequence callables causing problems ([#442](https://github.com/pestphp/pest/pull/442))
## [v1.21.0 (2021-11-17)](https://github.com/pestphp/pest/compare/v1.20.0...v1.21.0)
### Added
- warn about xdebug modes ([1e011c](https://github.com/pestphp/pest/commit/1e011c7b4074d08f5dabab1f927d45383c85d210))
## [v1.20.0 (2021-09-25)](https://github.com/pestphp/pest/compare/v1.19.0...v1.20.0) ## [v1.20.0 (2021-09-25)](https://github.com/pestphp/pest/compare/v1.19.0...v1.20.0)
### Added ### Added
- `throwsIf` test call ([#371](https://github.com/pestphp/pest/pull/371)) - `throwsIf` test call ([#371](https://github.com/pestphp/pest/pull/371))

View File

@ -19,14 +19,18 @@
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). 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).
### Platinum Sponsors
- **[Spatie](https://spatie.be)**
- **[Worksome](https://www.worksome.com/)**
### Premium Sponsors ### Premium Sponsors
- **[Akaunting](https://akaunting.com)** - [Akaunting](https://akaunting.com)
- **[Auth0](https://auth0.com)** - [Auth0](https://auth0.com)
- **[Codecourse](https://codecourse.com/)** - [Codecourse](https://codecourse.com/)
- **[Fathom Analytics](https://usefathom.com/)** - [Fathom Analytics](https://usefathom.com/)
- **[Meema](https://meema.io)** - [Meema](https://meema.io)
- **[Scout APM](https://scoutapm.com)** - [Scout APM](https://scoutapm.com)
- **[Spatie](https://spatie.be)**
Pest is an open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**. Pest is an open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.

View File

@ -2,14 +2,15 @@
When releasing a new version of Pest there are some checks and updates that need to be done: 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` - Clear your local repository with: `git add . && git reset --hard && git checkout 1.x`
- 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 - On the GitHub repository, check the contents of [github.com/pestphp/pest/compare/{latest_version}...1.x](https://github.com/pestphp/pest/compare/{latest_version}...1.x) 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) - Update the version number in [src/Pest.php](src/Pest.php)
- Run the tests locally using: `composer test` - Run the tests locally using: `composer test`
- Commit the CHANGELOG and Pest file with the message: `git commit -m "release: vX.X.X"` - Commit the CHANGELOG and Pest file with the message: `git commit -m "release: vX.X.X"`
- Push the changes to GitHub - Push the changes to GitHub
- Check that the CI is passing as expected: [github.com/pestphp/pest/actions](https://github.com/pestphp/pest/actions) - 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` - Tag and push the tag with `git tag vX.X.X && git push --tags`
- Publish release here: [github.com/pestphp/pest/releases/new](https://github.com/pestphp/pest/releases/new).
### Plugins ### Plugins

View File

@ -18,7 +18,7 @@
], ],
"require": { "require": {
"php": "^7.3 || ^8.0", "php": "^7.3 || ^8.0",
"nunomaduro/collision": "^5.4.0|^6.0", "nunomaduro/collision": "^5.10.0|^6.0",
"pestphp/pest-plugin": "^1.0.0", "pestphp/pest-plugin": "^1.0.0",
"phpunit/phpunit": "^9.5.5" "phpunit/phpunit": "^9.5.5"
}, },
@ -50,7 +50,10 @@
"prefer-stable": true, "prefer-stable": true,
"config": { "config": {
"sort-packages": true, "sort-packages": true,
"preferred-install": "dist" "preferred-install": "dist",
"allow-plugins": {
"pestphp/pest-plugin": true
}
}, },
"bin": [ "bin": [
"bin/pest" "bin/pest"
@ -73,7 +76,7 @@
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.x-dev" "dev-1.x": "1.x-dev"
}, },
"pest": { "pest": {
"plugins": [ "plugins": [

287
phpstan-baseline.neon Normal file
View File

@ -0,0 +1,287 @@
parameters:
ignoreErrors:
-
message: "#^Cannot access an offset on mixed\\.$#"
count: 1
path: src/Actions/AddsDefaults.php
-
message: "#^Parameter \\#1 \\$out of class Pest\\\\Logging\\\\JUnit constructor expects string, mixed given\\.$#"
count: 1
path: src/Actions/AddsDefaults.php
-
message: "#^Parameter \\#2 \\$verbose of class NunoMaduro\\\\Collision\\\\Adapters\\\\Phpunit\\\\Printer constructor expects bool, mixed given\\.$#"
count: 1
path: src/Actions/AddsDefaults.php
-
message: "#^Parameter \\#2 \\$verbose of class Pest\\\\Logging\\\\TeamCity constructor expects bool, mixed given\\.$#"
count: 1
path: src/Actions/AddsDefaults.php
-
message: "#^Parameter \\#3 \\$colors of class NunoMaduro\\\\Collision\\\\Adapters\\\\Phpunit\\\\Printer constructor expects string, mixed given\\.$#"
count: 1
path: src/Actions/AddsDefaults.php
-
message: "#^Parameter \\#3 \\$colors of class Pest\\\\Logging\\\\TeamCity constructor expects string, mixed given\\.$#"
count: 1
path: src/Actions/AddsDefaults.php
-
message: "#^Parameter \\#1 \\$filename of function file_exists expects string, mixed given\\.$#"
count: 1
path: src/Actions/ValidatesConfiguration.php
-
message: "#^Parameter \\#1 \\$filename of method PHPUnit\\\\TextUI\\\\XmlConfiguration\\\\Loader\\:\\:load\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Actions/ValidatesConfiguration.php
-
message: "#^Parameter \\#1 \\$loader of class PHPUnit\\\\TextUI\\\\TestRunner constructor expects PHPUnit\\\\Runner\\\\TestSuiteLoader\\|null, mixed given\\.$#"
count: 1
path: src/Console/Command.php
-
message: "#^Parameter \\#1 \\$testSuite of static method Pest\\\\Actions\\\\AddsTests\\:\\:to\\(\\) expects iterable\\<PHPUnit\\\\Framework\\\\TestCase\\>&PHPUnit\\\\Framework\\\\TestSuite, mixed given\\.$#"
count: 1
path: src/Console/Command.php
-
message: "#^Parameter \\#2 \\$suffixes of method SebastianBergmann\\\\FileIterator\\\\Facade\\:\\:getFilesAsArray\\(\\) expects array\\|string, mixed given\\.$#"
count: 1
path: src/Console/Command.php
-
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
count: 1
path: src/Datasets.php
-
message: "#^Method Pest\\\\Datasets\\:\\:getDataSetsCombinations\\(\\) has parameter \\$combinations with no value type specified in iterable type array\\.$#"
count: 1
path: src/Datasets.php
-
message: "#^Method Pest\\\\Datasets\\:\\:getDataSetsCombinations\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Datasets.php
-
message: "#^Method Pest\\\\Datasets\\:\\:processDatasets\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Datasets.php
-
message: "#^Parameter \\#1 \\$key of static method Pest\\\\Datasets\\:\\:getDataSetDescription\\(\\) expects int\\|string, mixed given\\.$#"
count: 1
path: src/Datasets.php
-
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
count: 1
path: src/Each.php
-
message: "#^Parameter \\#1 \\$ of callable callable\\(Pest\\\\Expectation\\<TValue\\>\\)\\: mixed expects Pest\\\\Expectation\\<TValue\\>, Pest\\\\Expectation\\<mixed\\> given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#1 \\$actualJson of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertJson\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#1 \\$directory of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertDirectoryExists\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#1 \\$directory of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertDirectoryIsReadable\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#1 \\$directory of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertDirectoryIsWritable\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#1 \\$file of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFileIsReadable\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#1 \\$file of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFileIsWritable\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#1 \\$filename of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFileExists\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#1 \\$json of function json_decode expects string, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#1 \\$needle of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#1 \\$object_or_class of function property_exists expects object\\|string, mixed given\\.$#"
count: 2
path: src/Expectation.php
-
message: "#^Parameter \\#2 \\$haystack of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertContains\\(\\) expects iterable, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#2 \\$haystack of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertCount\\(\\) expects Countable\\|iterable, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#2 \\$string of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertMatchesRegularExpression\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#2 \\$string of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringEndsWith\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#2 \\$string of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringStartsWith\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Parameter \\#2 \\$value of method Pest\\\\Expectation\\<TValue\\>\\:\\:retrieve\\(\\) expects array\\<string, null\\>\\|object, mixed given\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Trying to invoke mixed but it's not a callable\\.$#"
count: 1
path: src/Expectation.php
-
message: "#^Method Pest\\\\Factories\\\\TestCaseFactory\\:\\:build\\(\\) should return array\\<int, PHPUnit\\\\Framework\\\\TestCase\\> but returns array\\<int, object\\>\\.$#"
count: 1
path: src/Factories/TestCaseFactory.php
-
message: "#^Function it\\(\\) should return Pest\\\\PendingObjects\\\\TestCall but returns mixed\\.$#"
count: 1
path: src/Functions.php
-
message: "#^Parameter \\#2 \\$classAndTraits of class Pest\\\\PendingObjects\\\\UsesCall constructor expects array\\<int, string\\>, array\\<int\\|string, string\\> given\\.$#"
count: 1
path: src/Functions.php
-
message: "#^Parameter \\#2 \\$value of method Pest\\\\HigherOrderExpectation\\:\\:retrieve\\(\\) expects array\\<string, null\\>\\|object, mixed given\\.$#"
count: 1
path: src/HigherOrderExpectation.php
-
message: "#^Dead catch \\- ReflectionException is never thrown in the try block\\.$#"
count: 1
path: src/Logging/JUnit.php
-
message: "#^Parameter \\#2 \\$value of method DOMElement\\:\\:setAttribute\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Logging/JUnit.php
-
message: "#^Parameter \\$test of method Pest\\\\Logging\\\\JUnit\\:\\:startTest\\(\\) has invalid type Pest\\\\Concerns\\\\Testable\\.$#"
count: 1
path: src/Logging/JUnit.php
-
message: "#^Parameter \\$test of method Pest\\\\Logging\\\\TeamCity\\:\\:endTest\\(\\) has invalid type Pest\\\\Concerns\\\\Testable\\.$#"
count: 1
path: src/Logging/TeamCity.php
-
message: "#^Parameter \\$test of method Pest\\\\Logging\\\\TeamCity\\:\\:startTest\\(\\) has invalid type Pest\\\\Concerns\\\\Testable\\.$#"
count: 1
path: src/Logging/TeamCity.php
-
message: "#^Dead catch \\- PHPUnit\\\\Framework\\\\ExpectationFailedException is never thrown in the try block\\.$#"
count: 1
path: src/OppositeExpectation.php
-
message: "#^Property Pest\\\\PendingObjects\\\\UsesCall\\:\\:\\$groups \\(array\\<int, string\\>\\) does not accept array\\<int\\|string, string\\>\\.$#"
count: 1
path: src/PendingObjects/UsesCall.php
-
message: "#^Cannot cast mixed to float\\.$#"
count: 1
path: src/Plugins/Coverage.php
-
message: "#^Static property Pest\\\\Plugins\\\\Environment\\:\\:\\$instance is unused\\.$#"
count: 1
path: src/Plugins/Environment.php
-
message: "#^Method Pest\\\\Support\\\\Container\\:\\:get\\(\\) should return object but returns mixed\\.$#"
count: 1
path: src/Support/Container.php
-
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
count: 1
path: src/Support/ExceptionTrace.php
-
message: "#^Cannot access offset 'file' on mixed\\.$#"
count: 1
path: src/Support/ExceptionTrace.php
-
message: "#^Parameter \\#1 \\$haystack of function mb_strpos expects string, mixed given\\.$#"
count: 1
path: src/Support/ExceptionTrace.php
-
message: "#^Parameter \\#2 \\$array of function key_exists expects array, mixed given\\.$#"
count: 1
path: src/Support/ExceptionTrace.php
-
message: "#^Method Pest\\\\Support\\\\HigherOrderCallables\\:\\:expect\\(\\) should return Pest\\\\Expectation\\<TValue\\> but returns Pest\\\\Expectation\\<mixed\\>\\.$#"
count: 1
path: src/Support/HigherOrderCallables.php
-
message: "#^Parameter \\#1 \\$target of method Pest\\\\Support\\\\HigherOrderMessage\\:\\:call\\(\\) expects object, mixed given\\.$#"
count: 1
path: src/Support/HigherOrderMessageCollection.php
-
message: "#^Constant Pest\\\\Support\\\\HigherOrderTapProxy\\:\\:UNDEFINED_PROPERTY is unused\\.$#"
count: 1
path: src/Support/HigherOrderTapProxy.php
-
message: "#^Dead catch \\- Throwable is never thrown in the try block\\.$#"
count: 1
path: src/Support/HigherOrderTapProxy.php

View File

@ -2,6 +2,7 @@ includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon - vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/ergebnis/phpstan-rules/rules.neon - vendor/ergebnis/phpstan-rules/rules.neon
- vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
- phpstan-baseline.neon
parameters: parameters:
level: max level: max
@ -23,9 +24,6 @@ parameters:
- -
message: '#Call to an undefined method PHPUnit\\Framework\\Test::getName\(\)#' message: '#Call to an undefined method PHPUnit\\Framework\\Test::getName\(\)#'
path: src/Logging path: src/Logging
-
message: '#invalid typehint type Pest\\Concerns\\Testable#'
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/Logging path: src/Logging

View File

@ -50,6 +50,7 @@ final class LoadStructure
$directory = new RecursiveDirectoryIterator($filename); $directory = new RecursiveDirectoryIterator($filename);
$iterator = new RecursiveIteratorIterator($directory); $iterator = new RecursiveIteratorIterator($directory);
foreach ($iterator as $file) { foreach ($iterator as $file) {
/* @phpstan-ignore-next-line */
$filename = $file->__toString(); $filename = $file->__toString();
if (Str::endsWith($filename, '.php') && file_exists($filename)) { if (Str::endsWith($filename, '.php') && file_exists($filename)) {
require_once $filename; require_once $filename;

View File

@ -6,6 +6,7 @@ namespace Pest;
use BadMethodCallException; use BadMethodCallException;
use Closure; use Closure;
use Error;
use InvalidArgumentException; use InvalidArgumentException;
use Pest\Concerns\Extendable; use Pest\Concerns\Extendable;
use Pest\Concerns\RetrievesValues; use Pest\Concerns\RetrievesValues;
@ -108,7 +109,6 @@ final class Expectation
public function ray(...$arguments): self public function ray(...$arguments): self
{ {
if (function_exists('ray')) { if (function_exists('ray')) {
// @phpstan-ignore-next-line
ray($this->value, ...$arguments); ray($this->value, ...$arguments);
} }
@ -171,7 +171,7 @@ final class Expectation
} }
foreach ($values as $key => $item) { foreach ($values as $key => $item) {
if (is_callable($callbacks[$key])) { if ($callbacks[$key] instanceof Closure) {
call_user_func($callbacks[$key], new self($item), new self($keys[$key])); call_user_func($callbacks[$key], new self($item), new self($keys[$key]));
continue; continue;
} }
@ -912,8 +912,12 @@ final class Expectation
try { try {
($this->value)(); ($this->value)();
} catch (Throwable $e) { // @phpstan-ignore-line } catch (Throwable $e) {
if (!class_exists($exception)) { if (!class_exists($exception)) {
if ($e instanceof Error && (bool) preg_match("/Class [\"']{$exception}[\"'] not found/", $e->getMessage())) {
throw $e;
}
Assert::assertStringContainsString($exception, $e->getMessage()); Assert::assertStringContainsString($exception, $e->getMessage());
return $this; return $this;

View File

@ -173,7 +173,6 @@ final class JUnit extends Printer implements TestListener
$this->doAddSkipped(); $this->doAddSkipped();
} }
/** @phpstan-ignore-next-line */
public function startTestSuite(TestSuite $suite): void public function startTestSuite(TestSuite $suite): void
{ {
$testSuite = $this->document->createElement('testsuite'); $testSuite = $this->document->createElement('testsuite');
@ -212,7 +211,6 @@ final class JUnit extends Printer implements TestListener
$this->testSuiteTimes[$this->testSuiteLevel] = 0; $this->testSuiteTimes[$this->testSuiteLevel] = 0;
} }
/** @phpstan-ignore-next-line */
public function endTestSuite(TestSuite $suite): void public function endTestSuite(TestSuite $suite): void
{ {
$this->testSuites[$this->testSuiteLevel]->setAttribute( $this->testSuites[$this->testSuiteLevel]->setAttribute(
@ -283,7 +281,6 @@ final class JUnit extends Printer implements TestListener
$class = new ReflectionClass($test); $class = new ReflectionClass($test);
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
} catch (ReflectionException $e) { } catch (ReflectionException $e) {
// @phpstan-ignore-next-line
throw new Exception($e->getMessage(), (int) $e->getCode(), $e); throw new Exception($e->getMessage(), (int) $e->getCode(), $e);
} }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd

View File

@ -106,7 +106,6 @@ final class TeamCity extends DefaultResultPrinter
- $result->riskyCount(); - $result->riskyCount();
} }
/** @phpstan-ignore-next-line */
public function startTestSuite(TestSuite $suite): void public function startTestSuite(TestSuite $suite): void
{ {
$suiteName = $suite->getName(); $suiteName = $suite->getName();
@ -164,7 +163,6 @@ final class TeamCity extends DefaultResultPrinter
); );
} }
/** @phpstan-ignore-next-line */
public function endTestSuite(TestSuite $suite): void public function endTestSuite(TestSuite $suite): void
{ {
$suiteName = $suite->getName(); $suiteName = $suite->getName();

View File

@ -51,6 +51,8 @@ final class OppositeExpectation
* Handle dynamic method calls into the original expectation. * Handle dynamic method calls into the original expectation.
* *
* @param array<int, mixed> $arguments * @param array<int, mixed> $arguments
*
* @return Expectation|never
*/ */
public function __call(string $name, array $arguments): Expectation public function __call(string $name, array $arguments): Expectation
{ {
@ -61,12 +63,13 @@ final class OppositeExpectation
return $this->original; return $this->original;
} }
// @phpstan-ignore-next-line
$this->throwExpectationFailedException($name, $arguments); $this->throwExpectationFailedException($name, $arguments);
} }
/** /**
* Handle dynamic properties gets into the original expectation. * Handle dynamic properties gets into the original expectation.
*
* @return Expectation|never
*/ */
public function __get(string $name): Expectation public function __get(string $name): Expectation
{ {
@ -77,7 +80,6 @@ final class OppositeExpectation
return $this->original; return $this->original;
} }
// @phpstan-ignore-next-line
$this->throwExpectationFailedException($name); $this->throwExpectationFailedException($name);
} }
@ -85,6 +87,8 @@ final class OppositeExpectation
* Creates a new expectation failed exception with a nice readable message. * Creates a new expectation failed exception with a nice readable message.
* *
* @param array<int, mixed> $arguments * @param array<int, mixed> $arguments
*
* @return never
*/ */
private function throwExpectationFailedException(string $name, array $arguments = []): void private function throwExpectationFailedException(string $name, array $arguments = []): void
{ {

View File

@ -160,7 +160,7 @@ final class TestCall
$condition = is_callable($condition) $condition = is_callable($condition)
? $condition ? $condition
: function () use ($condition) { /* @phpstan-ignore-line */ : function () use ($condition) {
return $condition; return $condition;
}; };
@ -183,7 +183,7 @@ final class TestCall
*/ */
public function __get(string $name): self public function __get(string $name): self
{ {
return $this->addChain($name); return $this->addChain(Backtrace::file(), Backtrace::line(), $name);
} }
/** /**
@ -193,7 +193,7 @@ final class TestCall
*/ */
public function __call(string $name, array $arguments): self public function __call(string $name, array $arguments): self
{ {
return $this->addChain($name, $arguments); return $this->addChain(Backtrace::file(), Backtrace::line(), $name, $arguments);
} }
/** /**
@ -201,11 +201,11 @@ final class TestCall
* *
* @param array<int, mixed>|null $arguments * @param array<int, mixed>|null $arguments
*/ */
private function addChain(string $name, array $arguments = null): self private function addChain(string $file, int $line, string $name, array $arguments = null): self
{ {
$this->testCaseFactory $this->testCaseFactory
->chains ->chains
->add(Backtrace::file(), Backtrace::line(), $name, $arguments); ->add($file, $line, $name, $arguments);
if ($this->descriptionLess) { if ($this->descriptionLess) {
$exporter = new Exporter(); $exporter = new Exporter();

View File

@ -6,7 +6,7 @@ namespace Pest;
function version(): string function version(): string
{ {
return '1.20.0'; return '1.21.3';
} }
function testDirectory(string $file = ''): string function testDirectory(string $file = ''): string

View File

@ -26,6 +26,7 @@ final class Backtrace
$current = null; $current = null;
foreach (debug_backtrace(self::BACKTRACE_OPTIONS) as $trace) { foreach (debug_backtrace(self::BACKTRACE_OPTIONS) as $trace) {
assert(array_key_exists(self::FILE, $trace));
if (Str::endsWith($trace[self::FILE], (string) realpath('vendor/phpunit/phpunit/src/Util/FileLoader.php'))) { if (Str::endsWith($trace[self::FILE], (string) realpath('vendor/phpunit/phpunit/src/Util/FileLoader.php'))) {
break; break;
} }
@ -45,7 +46,11 @@ final class Backtrace
*/ */
public static function file(): string public static function file(): string
{ {
return debug_backtrace(self::BACKTRACE_OPTIONS)[1][self::FILE]; $trace = debug_backtrace(self::BACKTRACE_OPTIONS)[1];
assert(array_key_exists(self::FILE, $trace));
return $trace[self::FILE];
} }
/** /**
@ -53,7 +58,11 @@ final class Backtrace
*/ */
public static function dirname(): string public static function dirname(): string
{ {
return dirname(debug_backtrace(self::BACKTRACE_OPTIONS)[1][self::FILE]); $trace = debug_backtrace(self::BACKTRACE_OPTIONS)[1];
assert(array_key_exists(self::FILE, $trace));
return dirname($trace[self::FILE]);
} }
/** /**
@ -61,6 +70,10 @@ final class Backtrace
*/ */
public static function line(): int public static function line(): int
{ {
return debug_backtrace(self::BACKTRACE_OPTIONS)[1]['line']; $trace = debug_backtrace(self::BACKTRACE_OPTIONS)[1];
assert(array_key_exists('line', $trace));
return $trace['line'];
} }
} }

View File

@ -30,14 +30,21 @@ final class Coverage
} }
/** /**
* Runs true there is any code * Runs true there is any code coverage driver available.
* coverage driver available.
*/ */
public static function isAvailable(): bool public static function isAvailable(): bool
{ {
return (new Runtime())->canCollectCodeCoverage(); return (new Runtime())->canCollectCodeCoverage();
} }
/**
* If the user is using Xdebug.
*/
public static function usingXdebug(): bool
{
return (new Runtime())->hasXdebug();
}
/** /**
* Reports the code coverage report to the * Reports the code coverage report to the
* console and returns the result in float. * console and returns the result in float.
@ -45,6 +52,14 @@ final class Coverage
public static function report(OutputInterface $output): float public static function report(OutputInterface $output): float
{ {
if (!file_exists($reportPath = self::getPath())) { if (!file_exists($reportPath = self::getPath())) {
if (self::usingXdebug()) {
$output->writeln(
" <fg=black;bg=yellow;options=bold> WARN </> Unable to get coverage using Xdebug. Did you set <href=https://xdebug.org/docs/code_coverage#mode>Xdebug's coverage mode</>?</>",
);
return 0.0;
}
throw ShouldNotHappen::fromMessage(sprintf('Coverage not found in path: %s.', $reportPath)); throw ShouldNotHappen::fromMessage(sprintf('Coverage not found in path: %s.', $reportPath));
} }

View File

@ -496,6 +496,8 @@
✓ not failures ✓ not failures
✓ closure missing parameter ✓ closure missing parameter
✓ closure missing type-hint ✓ closure missing type-hint
✓ it can handle a non-defined exception
✓ it can handle a class not found Error
PASS Tests\Features\Expect\unless PASS Tests\Features\Expect\unless
✓ it pass ✓ it pass
@ -720,5 +722,5 @@
✓ it is a test ✓ it is a test
✓ it uses correct parent class ✓ it uses correct parent class
Tests: 4 incompleted, 9 skipped, 478 passed Tests: 4 incompleted, 9 skipped, 480 passed

View File

@ -58,3 +58,15 @@ test('closure missing parameter', function () {
test('closure missing type-hint', function () { test('closure missing type-hint', function () {
expect(function () {})->toThrow(function ($e) {}); expect(function () {})->toThrow(function ($e) {});
})->throws(InvalidArgumentException::class, 'The given closure\'s parameter must be type-hinted as the class string.'); })->throws(InvalidArgumentException::class, 'The given closure\'s parameter must be type-hinted as the class string.');
it('can handle a non-defined exception', function () {
expect(function () {
throw new NonExistingException();
})->toThrow(NonExistingException::class);
})->throws(Error::class);
it('can handle a class not found Error', function () {
expect(function () {
throw new NonExistingException();
})->toThrow(Error::class);
});

0
tests/Visual/junit.html Normal file
View File