Compare commits

...

48 Commits

Author SHA1 Message Date
a1a0f049cd release: v1.22.5 2023-03-03 10:16:59 +00:00
a7e231f64f chore: requires latest version of phpunit 2023-03-03 10:16:21 +00:00
1856c15e67 release: v1.22.4 2023-02-03 13:05:47 +00:00
ee4ff5a909 chore: bumps dependencies 2023-02-03 13:03:07 +00:00
7de10d52a7 feat: include 'RefreshDatabase' on uses 2023-02-03 12:56:42 +00:00
660df6d8d1 chore: bump phpunit 2023-02-03 12:55:06 +00:00
d8666c8abf chore: coding style changes 2023-02-03 12:55:01 +00:00
b8ac4968ee chore: style changes 2023-01-01 20:27:38 +00:00
78b3c41825 chore: bumps phpunit 2022-12-12 13:45:28 +00:00
b58a020423 release: v1.22.3 2022-12-07 14:31:55 +00:00
e337a52cda Merge pull request #612 from alexmanase/1.x-fix-ignored-description-for-layz-datasets
[1.x] Fixes ignored dataset description only for string description
2022-12-07 14:23:55 +00:00
0a6873d8a6 wip 2022-11-17 16:14:03 +02:00
09b7ab9a42 fixes ignored dataset description for string description 2022-11-17 15:43:30 +02:00
339414e348 release: v1.22.2 2022-11-09 21:10:57 +00:00
bb56d32643 chore: fixes coding style issues 2022-11-09 21:08:19 +00:00
acd6bb2234 Merge pull request #602 from alexmanase/fix/iterator-to-array
[1.x] Fix storing of lazy datasets into internal array
2022-11-09 20:59:19 +00:00
cf93e316ff chore: bumps dependencies 2022-11-09 20:09:40 +00:00
47cc88a6ab add tests for eager registered wrapped datasets with Generator functions 2022-10-30 01:35:46 +03:00
45bf9e8650 ignore the keys returned by the datasets Generator for storing them into an array 2022-10-29 18:19:43 +03:00
3c766c15d5 Updates dependencies 2022-09-18 14:21:38 +01:00
aa407f34d5 Merge pull request #575 from fabio-ivona/1.x-fix-tests
1.x fix tests
2022-09-12 18:21:07 +02:00
077b5ffce0 fix tests 2022-09-12 18:18:52 +02:00
af6240b4ee release: v1.22.1 2022-08-29 11:42:13 +01:00
78b328e970 release: v1.22.1 2022-08-29 11:42:07 +01:00
c92fa45ad7 Adds tests on PHP 8.2 2022-08-29 11:35:36 +01:00
d050ef8d54 Fixes support for PHP 8.2 2022-08-29 11:29:41 +01:00
1c2f1facac release: v1.22.0 2022-08-28 22:32:39 +01:00
8e695d62e9 Merge pull request #563 from fabio-ivona/1.x-dynamic-properties
[1.x] Dynamic properties handling
2022-08-25 13:22:45 +01:00
b9a301a13e ignore dynamic properties deprecation 2022-08-25 13:27:24 +02:00
4b9da9e3c1 Merge pull request #562 from fabio-ivona/1.x-dynamic-properties
Fix tests
2022-08-25 12:50:09 +02:00
239fceab9e lint 2022-08-25 09:46:32 +02:00
bedf033655 lint 2022-08-25 09:32:48 +02:00
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
42 changed files with 270 additions and 124 deletions

View File

@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
php: ['7.3', '7.4', '8.0', '8.1']
php: ['7.3', '7.4', '8.0', '8.1', '8.2']
dependency-version: [prefer-lowest, prefer-stable]
parallel: ['', '--parallel']
exclude:
@ -16,6 +16,10 @@ jobs:
os: macos-latest
- php: 8.1
os: windows-latest
- php: 8.2
os: macos-latest
- php: 8.2
os: windows-latest
name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} - ${{ matrix.parallel }}

View File

@ -8,11 +8,11 @@ $finder = PhpCsFixer\Finder::create()
->append(['.php-cs-fixer.dist.php']);
$rules = [
'@Symfony' => true,
'phpdoc_no_empty_return' => false,
'array_syntax' => ['syntax' => 'short'],
'yoda_style' => false,
'binary_operator_spaces' => [
'@Symfony' => true,
'phpdoc_no_empty_return' => false,
'array_syntax' => ['syntax' => 'short'],
'yoda_style' => false,
'binary_operator_spaces' => [
'operators' => [
'=>' => 'align',
'=' => 'align',
@ -20,6 +20,11 @@ $rules = [
],
'concat_space' => ['spacing' => 'one'],
'not_operator_with_space' => false,
'global_namespace_import' => [
'import_classes' => true,
'import_functions' => true,
'import_constants' => true,
],
];
$rules['increment_style'] = ['style' => 'post'];

View File

@ -4,6 +4,38 @@ 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/).
## [v1.22.5 (2023-03-03)](https://github.com/pestphp/pest/compare/v1.22.4...v1.22.5)
### Changed
- Bumps dependencies
## [v1.22.4 (2023-02-03)](https://github.com/pestphp/pest/compare/v1.22.3...v1.22.4)
### Changed
- Bumps dependencies
## [v1.22.3 (2022-12-07)](https://github.com/pestphp/pest/compare/v1.22.2...v1.22.3)
### Fixed
- Fixes ignoring datasets description on lazy datasets ([#612](https://github.com/pestphp/pest/pull/612))
## [v1.22.2 (2022-11-09)](https://github.com/pestphp/pest/compare/v1.22.1...v1.22.2)
### Fixed
- Fixes storing lazy datasets into internal array ([#602](https://github.com/pestphp/pest/pull/602))
## [v1.22.1 (2022-08-29)](https://github.com/pestphp/pest/compare/v1.22.0...v1.22.1)
### Fixed
- Initial PHP 8.2 support ([d050ef8](https://github.com/pestphp/pest/commit/d050ef8d54ffe8dfe015adeb1188aae2cca33c33))
## [v1.22.0 (2022-08-28)](https://github.com/pestphp/pest/compare/v1.21.3...v1.22.0)
### Added
- Initial PHP 8.2 support ([#563](https://github.com/pestphp/pest/pull/563))
## [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))

View File

@ -2,8 +2,8 @@
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
- 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}...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)
- Run the tests locally using: `composer test`
- Commit the CHANGELOG and Pest file with the message: `git commit -m "release: vX.X.X"`

View File

@ -18,9 +18,9 @@
],
"require": {
"php": "^7.3 || ^8.0",
"nunomaduro/collision": "^5.4.0|^6.0",
"pestphp/pest-plugin": "^1.0.0",
"phpunit/phpunit": "^9.5.5"
"nunomaduro/collision": "^5.11.0|^6.3.0",
"pestphp/pest-plugin": "^1.1.0",
"phpunit/phpunit": "^9.6.4"
},
"autoload": {
"psr-4": {
@ -40,24 +40,27 @@
]
},
"require-dev": {
"illuminate/console": "^8.47.0",
"illuminate/support": "^8.47.0",
"laravel/dusk": "^6.15.0",
"pestphp/pest-dev-tools": "dev-master",
"pestphp/pest-plugin-parallel": "^1.0"
"illuminate/console": "^8.83.27",
"illuminate/support": "^8.83.27",
"laravel/dusk": "^6.25.2",
"pestphp/pest-dev-tools": "^1.0.0",
"pestphp/pest-plugin-parallel": "^1.2.1"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true,
"preferred-install": "dist"
"preferred-install": "dist",
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"bin": [
"bin/pest"
],
"scripts": {
"lint": "php-cs-fixer fix -v",
"test:lint": "php-cs-fixer fix -v --dry-run",
"lint": "PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix -v",
"test:lint": "PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix -v --dry-run",
"test:types": "phpstan analyse --ansi --memory-limit=-1",
"test:unit": "php bin/pest --colors=always --exclude-group=integration",
"test:parallel": "php bin/pest -p --colors=always --exclude-group=integration",
@ -73,7 +76,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
"dev-1.x": "1.x-dev"
},
"pest": {
"plugins": [

View File

@ -55,11 +55,6 @@ parameters:
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
@ -75,11 +70,6 @@ parameters:
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
@ -90,11 +80,6 @@ parameters:
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
@ -140,11 +125,6 @@ parameters:
count: 2
path: src/Expectation.php
-
message: "#^Parameter \\#1 \\$value of method Pest\\\\Expectation\\<TValue\\>\\:\\:and\\(\\) expects TValue, 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
@ -255,16 +235,6 @@ parameters:
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

View File

@ -5,11 +5,12 @@ declare(strict_types=1);
namespace Pest\Actions;
use Pest\Support\Str;
use function Pest\testDirectory;
use PHPUnit\Util\FileLoader;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use function Pest\testDirectory;
/**
* @internal
*/
@ -50,6 +51,7 @@ final class LoadStructure
$directory = new RecursiveDirectoryIterator($filename);
$iterator = new RecursiveIteratorIterator($directory);
foreach ($iterator as $file) {
/* @phpstan-ignore-next-line */
$filename = $file->__toString();
if (Str::endsWith($filename, '.php') && file_exists($filename)) {
require_once $filename;

View File

@ -11,6 +11,8 @@ use Pest\TestSuite;
use PHPUnit\Framework\ExecutionOrderDependency;
use Throwable;
use function sprintf;
/**
* To avoid inheritance conflicts, all the fields related
* to Pest only will be prefixed by double underscore.
@ -257,7 +259,7 @@ trait Testable
*/
public function toString(): string
{
return \sprintf(
return sprintf(
'%s::%s',
self::$__filename,
$this->__description

View File

@ -18,6 +18,8 @@ use PHPUnit\TextUI\TestRunner;
use SebastianBergmann\FileIterator\Facade as FileIteratorFacade;
use Symfony\Component\Console\Output\OutputInterface;
use function is_dir;
/**
* @internal
*/
@ -81,7 +83,7 @@ final class Command extends BaseCommand
$testSuite = $this->arguments['test'];
if (is_string($testSuite)) {
if (\is_dir($testSuite)) {
if (is_dir($testSuite)) {
/** @var string[] $files */
$files = (new FileIteratorFacade())->getFilesAsArray(
$testSuite,

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Pest;
use Closure;
use Generator;
use Pest\Exceptions\DatasetAlreadyExist;
use Pest\Exceptions\DatasetDoesNotExist;
use SebastianBergmann\Exporter\Exporter;
@ -122,7 +123,10 @@ final class Datasets
}
if ($datasets[$index] instanceof Traversable) {
$datasets[$index] = iterator_to_array($datasets[$index]);
$preserveKeysForArrayIterator = $datasets[$index] instanceof Generator
&& is_string($datasets[$index]->key());
$datasets[$index] = iterator_to_array($datasets[$index], $preserveKeysForArrayIterator);
}
foreach ($datasets[$index] as $key => $values) {

View File

@ -6,6 +6,7 @@ namespace Pest;
use BadMethodCallException;
use Closure;
use Error;
use InvalidArgumentException;
use Pest\Concerns\Extendable;
use Pest\Concerns\RetrievesValues;
@ -722,7 +723,7 @@ final class Expectation
try {
Assert::assertTrue(Arr::has($array, $key));
/* @phpstan-ignore-next-line */
/* @phpstan-ignore-next-line */
} catch (ExpectationFailedException $exception) {
throw new ExpectationFailedException("Failed asserting that an array has the key '$key'", $exception->getComparisonFailure());
}
@ -911,8 +912,12 @@ final class Expectation
try {
($this->value)();
} catch (Throwable $e) { // @phpstan-ignore-line
} catch (Throwable $e) {
if (!class_exists($exception)) {
if ($e instanceof Error && (bool) preg_match("/Class [\"']{$exception}[\"'] not found/", $e->getMessage())) {
throw $e;
}
Assert::assertStringContainsString($exception, $e->getMessage());
return $this;

View File

@ -216,6 +216,7 @@ final class TestCaseFactory
eval("
namespace $namespace;
#[\AllowDynamicProperties]
final class $className extends $baseClass implements $hasPrintableTestCaseClassFQN {
$traitsCode

View File

@ -8,9 +8,10 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Pest\Exceptions\InvalidConsoleArgument;
use function Pest\testDirectory;
use Pest\TestSuite;
use function Pest\testDirectory;
/**
* @internal
*/

View File

@ -8,9 +8,10 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Pest\Console\Thanks;
use Pest\Exceptions\InvalidConsoleArgument;
use function Pest\testDirectory;
use Pest\TestSuite;
use function Pest\testDirectory;
/**
* @internal
*/

View File

@ -8,9 +8,10 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Pest\Exceptions\InvalidConsoleArgument;
use Pest\Support\Str;
use function Pest\testDirectory;
use Pest\TestSuite;
use function Pest\testDirectory;
/**
* @internal
*/

View File

@ -12,12 +12,9 @@ declare(strict_types=1);
namespace Pest\Logging;
use function class_exists;
use DOMDocument;
use DOMElement;
use Exception;
use function get_class;
use function method_exists;
use Pest\Concerns\Testable;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\ExceptionWrapper;
@ -32,9 +29,13 @@ use PHPUnit\Util\Printer;
use PHPUnit\Util\Xml;
use ReflectionClass;
use ReflectionException;
use Throwable;
use function class_exists;
use function get_class;
use function method_exists;
use function sprintf;
use function str_replace;
use Throwable;
use function trim;
/**
@ -173,7 +174,6 @@ final class JUnit extends Printer implements TestListener
$this->doAddSkipped();
}
/** @phpstan-ignore-next-line */
public function startTestSuite(TestSuite $suite): void
{
$testSuite = $this->document->createElement('testsuite');
@ -212,7 +212,6 @@ final class JUnit extends Printer implements TestListener
$this->testSuiteTimes[$this->testSuiteLevel] = 0;
}
/** @phpstan-ignore-next-line */
public function endTestSuite(TestSuite $suite): void
{
$this->testSuites[$this->testSuiteLevel]->setAttribute(

View File

@ -4,11 +4,9 @@ declare(strict_types=1);
namespace Pest\Logging;
use function getmypid;
use Pest\Concerns\Logging\WritesToConsole;
use Pest\Concerns\Testable;
use Pest\Support\ExceptionTrace;
use function Pest\version;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;
@ -16,10 +14,13 @@ use PHPUnit\Framework\TestResult;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;
use PHPUnit\TextUI\DefaultResultPrinter;
use Throwable;
use function getmypid;
use function Pest\version;
use function round;
use function str_replace;
use function strlen;
use Throwable;
final class TeamCity extends DefaultResultPrinter
{
@ -81,6 +82,7 @@ final class TeamCity extends DefaultResultPrinter
foreach ($filteredResults as $key => $info) {
$this->writeWithColor($info['color'], $info['count'] . " $key", false);
/* @phpstan-ignore-next-line */
if ($key !== array_reverse(array_keys($filteredResults))[0]) {
$this->write(', ');
}
@ -106,7 +108,6 @@ final class TeamCity extends DefaultResultPrinter
- $result->riskyCount();
}
/** @phpstan-ignore-next-line */
public function startTestSuite(TestSuite $suite): void
{
$suiteName = $suite->getName();
@ -164,7 +165,6 @@ final class TeamCity extends DefaultResultPrinter
);
}
/** @phpstan-ignore-next-line */
public function endTestSuite(TestSuite $suite): void
{
$suiteName = $suite->getName();
@ -190,7 +190,7 @@ final class TeamCity extends DefaultResultPrinter
}
$this->printEvent(self::TEST_STARTED, [
self::NAME => $test->getName(),
self::NAME => $test->getName(),
// @phpstan-ignore-next-line
self::LOCATION_HINT => self::PROTOCOL . $test->toString(),
]);

View File

@ -102,7 +102,7 @@ final class TestCall
* Runs the current test multiple times with
* each item of the given `iterable`.
*
* @param array<\Closure|iterable<int|string, mixed>|string> $data
* @param array<Closure|iterable<int|string, mixed>|string> $data
*/
public function with(...$data): TestCall
{
@ -183,7 +183,7 @@ final class TestCall
*/
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
{
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
*/
private function addChain(string $name, array $arguments = null): self
private function addChain(string $file, int $line, string $name, array $arguments = null): self
{
$this->testCaseFactory
->chains
->add(Backtrace::file(), Backtrace::line(), $name, $arguments);
->add($file, $line, $name, $arguments);
if ($this->descriptionLess) {
$exporter = new Exporter();

View File

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

View File

@ -5,9 +5,10 @@ declare(strict_types=1);
namespace Pest\Plugins;
use Pest\Contracts\Plugins\HandlesArguments;
use function Pest\version;
use Symfony\Component\Console\Output\OutputInterface;
use function Pest\version;
/**
* @internal
*/

View File

@ -26,6 +26,7 @@ final class Backtrace
$current = null;
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'))) {
break;
}
@ -45,7 +46,11 @@ final class Backtrace
*/
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
{
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
{
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

@ -8,6 +8,8 @@ use Closure;
use ReflectionClass;
use Throwable;
use const PHP_MAJOR_VERSION;
/**
* @internal
*/
@ -132,7 +134,7 @@ final class HigherOrderMessage
private static function getUndefinedMethodMessage(object $target, string $methodName): string
{
if (\PHP_MAJOR_VERSION >= 8) {
if (PHP_MAJOR_VERSION >= 8) {
return sprintf(sprintf(self::UNDEFINED_METHOD, sprintf('%s::%s()', get_class($target), $methodName)));
}

View File

@ -11,7 +11,10 @@
|
*/
uses(Tests\TestCase::class)->in('Feature');
uses(
Tests\TestCase::class,
// Illuminate\Foundation\Testing\RefreshDatabase::class,
)->in('Feature');
/*
|--------------------------------------------------------------------------

View File

@ -96,6 +96,13 @@
✓ more than two datasets with (2) / (4) / (5)
✓ more than two datasets with (2) / (4) / (6)
✓ more than two datasets did the job right
✓ eager registered wrapped datasets with Generator functions with (1)
✓ eager registered wrapped datasets with Generator functions with (2)
✓ eager registered wrapped datasets with Generator functions with (3)
✓ eager registered wrapped datasets with Generator functions with (4)
✓ eager registered wrapped datasets with Generator functions did the job right
✓ eager registered wrapped datasets with Generator functions display description with data set "taylor"
✓ eager registered wrapped datasets with Generator functions display description with data set "james"
✓ it can resolve a dataset after the test case is available with (Closure Object (...))
✓ it can resolve a dataset after the test case is available with shared yield sets with (Closure Object (...)) #1
✓ it can resolve a dataset after the test case is available with shared yield sets with (Closure Object (...)) #2
@ -496,6 +503,8 @@
✓ not failures
✓ closure missing parameter
✓ closure missing type-hint
✓ it can handle a non-defined exception
✓ it can handle a class not found Error
PASS Tests\Features\Expect\unless
✓ it pass
@ -720,5 +729,5 @@
✓ it is a test
✓ it uses correct parent class
Tests: 4 incompleted, 9 skipped, 478 passed
Tests: 4 incompleted, 9 skipped, 487 passed

View File

@ -13,3 +13,20 @@ dataset('numbers.closure.wrapped', function () {
dataset('numbers.array', [[1], [2]]);
dataset('numbers.array.wrapped', [1, 2]);
dataset('numbers.generators.wrapped', function () {
yield from firstSetOfNumber();
yield from secondSetOfNumbers();
});
function firstSetOfNumber(): Generator
{
yield 1;
yield 2;
}
function secondSetOfNumbers(): Generator
{
yield 3;
yield 4;
}

View File

@ -8,7 +8,7 @@ use Symfony\Component\Console\Output\ConsoleOutput;
it('has plugin')->assertTrue(class_exists(CoveragePlugin::class));
it('adds coverage if --coverage exist', function () {
$plugin = new CoveragePlugin(new ConsoleOutput());
$plugin = new CoveragePlugin(new ConsoleOutput());
$testSuite = TestSuite::getInstance();
expect($plugin->coverage)->toBeFalse();

View File

@ -228,10 +228,38 @@ test('more than two datasets did the job right', function () use ($state) {
expect($state->text)->toBe('121212121212131423241314232411122122111221221112212213142324135136145146235236245246');
});
$wrapped_generator_state = new stdClass();
$wrapped_generator_state->text = '';
$wrapped_generator_function_datasets = [1, 2, 3, 4];
test(
'eager registered wrapped datasets with Generator functions',
function (int $text) use (
$wrapped_generator_state,
$wrapped_generator_function_datasets
) {
$wrapped_generator_state->text .= $text;
expect(in_array($text, $wrapped_generator_function_datasets))->toBe(true);
}
)->with('numbers.generators.wrapped');
test('eager registered wrapped datasets with Generator functions did the job right', function () use ($wrapped_generator_state) {
expect($wrapped_generator_state->text)->toBe('1234');
});
test('eager registered wrapped datasets with Generator functions display description', function ($wrapped_generator_state_with_description) {
expect($wrapped_generator_state_with_description)->not->toBeEmpty();
})->with(function () {
yield 'taylor' => 'taylor@laravel.com';
yield 'james' => 'james@laravel.com';
});
it('can resolve a dataset after the test case is available', function ($result) {
expect($result)->toBe('bar');
})->with([
function () { return $this->foo; },
function () {
return $this->foo;
},
]);
it('can resolve a dataset after the test case is available with shared yield sets', function ($result) {

View File

@ -47,7 +47,7 @@ it('runs with truthy', function () {
return $value->toEqual('bar');
},
true => function ($value) {
true => function ($value) {
$this->matched = 'foo';
return $value->toEqual('foo');
@ -88,7 +88,7 @@ it('runs with truthy closure condition', function () {
return $value->toEqual('bar');
},
true => function ($value) {
true => function ($value) {
$this->matched = 'foo';
return $value->toEqual('foo');
@ -141,7 +141,7 @@ it('can be used in higher order tests')
false => function ($value) {
return $value->toBeFalse();
},
true => function ($value) {
true => function ($value) {
return $value->toBeTrue();
},
]

View File

@ -9,9 +9,15 @@ test('an exception is thrown if the the type is not iterable', function () {
test('allows for sequences of checks to be run on iterable data', function () {
expect([1, 2, 3])
->sequence(
function ($expectation) { $expectation->toBeInt()->toEqual(1); },
function ($expectation) { $expectation->toBeInt()->toEqual(2); },
function ($expectation) { $expectation->toBeInt()->toEqual(3); },
function ($expectation) {
$expectation->toBeInt()->toEqual(1);
},
function ($expectation) {
$expectation->toBeInt()->toEqual(2);
},
function ($expectation) {
$expectation->toBeInt()->toEqual(3);
},
);
expect(static::getCount())->toBe(6);
@ -20,9 +26,15 @@ test('allows for sequences of checks to be run on iterable data', function () {
test('loops back to the start if it runs out of sequence items', function () {
expect([1, 2, 3, 1, 2, 3, 1, 2])
->sequence(
function ($expectation) { $expectation->toBeInt()->toEqual(1); },
function ($expectation) { $expectation->toBeInt()->toEqual(2); },
function ($expectation) { $expectation->toBeInt()->toEqual(3); },
function ($expectation) {
$expectation->toBeInt()->toEqual(1);
},
function ($expectation) {
$expectation->toBeInt()->toEqual(2);
},
function ($expectation) {
$expectation->toBeInt()->toEqual(3);
},
);
expect(static::getCount())->toBe(16);
@ -31,17 +43,29 @@ test('loops back to the start if it runs out of sequence items', function () {
test('fails if the number of iterable items is greater than the number of expectations', function () {
expect([1, 2])
->sequence(
function ($expectation) { $expectation->toBeInt()->toEqual(1); },
function ($expectation) { $expectation->toBeInt()->toEqual(2); },
function ($expectation) { $expectation->toBeInt()->toEqual(3); },
function ($expectation) {
$expectation->toBeInt()->toEqual(1);
},
function ($expectation) {
$expectation->toBeInt()->toEqual(2);
},
function ($expectation) {
$expectation->toBeInt()->toEqual(3);
},
);
})->throws(ExpectationFailedException::class);
test('it works with associative arrays', function () {
expect(['foo' => 'bar', 'baz' => 'boom'])
->sequence(
function ($expectation, $key) { $expectation->toEqual('bar'); $key->toEqual('foo'); },
function ($expectation, $key) { $expectation->toEqual('boom'); $key->toEqual('baz'); },
function ($expectation, $key) {
$expectation->toEqual('bar');
$key->toEqual('foo');
},
function ($expectation, $key) {
$expectation->toEqual('boom');
$key->toEqual('baz');
},
);
});
@ -54,7 +78,9 @@ test('it can be passed non-callable values', function () {
test('it can be passed a mixture of value types', function () {
expect(['foo', 'bar', 'baz'])->sequence(
'foo',
function ($expectation) { $expectation->toEqual('bar')->toBeString(); },
function ($expectation) {
$expectation->toEqual('bar')->toBeString();
},
'baz'
);

View File

@ -5,7 +5,7 @@ use PHPUnit\Framework\ExpectationFailedException;
expect(true)->toBeTrue()->and(false)->toBeFalse();
test('strict comparisons', function () {
$nuno = new stdClass();
$nuno = new stdClass();
$dries = new stdClass();
expect($nuno)->toBe($nuno)->not->toBe($dries);

View File

@ -3,24 +3,24 @@
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function () {
$object = new stdClass();
$object = new stdClass();
$object->name = 'Jhon';
$object->age = 21;
$object->age = 21;
expect($object)->toHaveProperties(['name', 'age']);
});
test('failures', function () {
$object = new stdClass();
$object = new stdClass();
$object->name = 'Jhon';
expect($object)->toHaveProperties(['name', 'age']);
})->throws(ExpectationFailedException::class);
test('not failures', function () {
$object = new stdClass();
$object = new stdClass();
$object->name = 'Jhon';
$object->age = 21;
$object->age = 21;
expect($object)->not->toHaveProperties(['name', 'age']);
})->throws(ExpectationFailedException::class);

View File

@ -58,3 +58,15 @@ test('closure missing parameter', function () {
test('closure missing type-hint', function () {
expect(function () {})->toThrow(function ($e) {});
})->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);
});

View File

@ -3,9 +3,9 @@
use PHPUnit\Framework\ExpectationFailedException;
beforeEach(function () {
$this->unlessObject = new stdClass();
$this->unlessObject = new stdClass();
$this->unlessObject->trueValue = true;
$this->unlessObject->foo = 'foo';
$this->unlessObject->foo = 'foo';
});
it('pass', function () {

View File

@ -3,9 +3,9 @@
use PHPUnit\Framework\ExpectationFailedException;
beforeEach(function () {
$this->whenObject = new stdClass();
$this->whenObject = new stdClass();
$this->whenObject->trueValue = true;
$this->whenObject->foo = 'foo';
$this->whenObject->foo = 'foo';
});
it('pass', function () {

View File

@ -4,9 +4,10 @@ declare(strict_types=1);
namespace Tests\CustomTestCase;
use function PHPUnit\Framework\assertTrue;
use PHPUnit\Framework\TestCase;
use function PHPUnit\Framework\assertTrue;
class CustomTestCase extends TestCase
{
public function assertCustomTrue()

View File

@ -4,9 +4,10 @@ declare(strict_types=1);
namespace Tests\CustomTestCase;
use function PHPUnit\Framework\assertTrue;
use PHPUnit\Framework\TestCase;
use function PHPUnit\Framework\assertTrue;
class ExecutedTest extends TestCase
{
public static $executed = false;

View File

@ -23,7 +23,7 @@ test('default php unit tests', function () {
});
it('removes warnings', function () {
$testSuite = new TestSuite();
$testSuite = new TestSuite();
$warningTestCase = new WarningTestCase('No tests found in class "Pest\TestCase".');
$testSuite->addTest($warningTestCase);

View File

@ -1,9 +1,10 @@
<?php
use Pest\Plugins\Version;
use function Pest\version;
use Symfony\Component\Console\Output\BufferedOutput;
use function Pest\version;
it('outputs the version when --version is used', function () {
$output = new BufferedOutput();
$plugin = new Version($output);

View File

@ -10,7 +10,7 @@ it('gets file name from closure', function () {
});
it('gets property values', function () {
$class = new class() {
$class = new class() {
private $foo = 'bar';
};

View File

@ -8,7 +8,7 @@ use Pest\TestSuite;
it('does not allow to add the same test description twice', function () {
$testSuite = new TestSuite(getcwd(), 'tests');
$test = function () {};
$test = function () {};
$testSuite->tests->set(new TestCaseFactory(__FILE__, 'foo', $test));
$testSuite->tests->set(new TestCaseFactory(__FILE__, 'foo', $test));
})->throws(
@ -18,7 +18,7 @@ it('does not allow to add the same test description twice', function () {
it('alerts users about tests with arguments but no input', function () {
$testSuite = new TestSuite(getcwd(), 'tests');
$test = function (int $arg) {};
$test = function (int $arg) {};
$testSuite->tests->set(new TestCaseFactory(__FILE__, 'foo', $test));
})->throws(
DatasetMissing::class,
@ -27,7 +27,7 @@ it('alerts users about tests with arguments but no input', function () {
it('can return an array of all test suite filenames', function () {
$testSuite = TestSuite::getInstance(getcwd(), 'tests');
$test = function () {};
$test = function () {};
$testSuite->tests->set(new TestCaseFactory(__FILE__, 'foo', $test));
$testSuite->tests->set(new TestCaseFactory(__FILE__, 'bar', $test));
@ -39,9 +39,9 @@ it('can return an array of all test suite filenames', function () {
it('can filter the test suite filenames to those with the only method', function () {
$testSuite = new TestSuite(getcwd(), 'tests');
$test = function () {};
$test = function () {};
$testWithOnly = new TestCaseFactory(__FILE__, 'foo', $test);
$testWithOnly = new TestCaseFactory(__FILE__, 'foo', $test);
$testWithOnly->only = true;
$testSuite->tests->set($testWithOnly);
@ -59,7 +59,7 @@ it('does not filter the test suite filenames to those with the only method when
$test = function () {};
$testWithOnly = new TestCaseFactory(__FILE__, 'foo', $test);
$testWithOnly = new TestCaseFactory(__FILE__, 'foo', $test);
$testWithOnly->only = true;
$testSuite->tests->set($testWithOnly);

View File

@ -8,7 +8,7 @@ test('visual snapshot of help command output', function () {
if (getenv('REBUILD_SNAPSHOTS')) {
$outputBuffer = new BufferedOutput();
$plugin = new Help($outputBuffer);
$plugin = new Help($outputBuffer);
$plugin();

View File

@ -2,7 +2,7 @@
test('visual snapshot of test suite on success', function () {
$testsPath = dirname(__DIR__);
$snapshot = implode(DIRECTORY_SEPARATOR, [
$snapshot = implode(DIRECTORY_SEPARATOR, [
$testsPath,
'.snapshots',
'success.txt',