mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6616b6299b | |||
| 0bab649156 | |||
| 2de7cb4726 | |||
| d2babb1331 | |||
| a6cced6b63 | |||
| 7917313422 | |||
| e02c22e136 | |||
| 2157644a39 | |||
| b6c2812a91 | |||
| 4b65d2c426 | |||
| 3589f3d5e7 | |||
| 1f39b8d239 | |||
| 7c3c390cbf | |||
| 19a1569fa8 | |||
| 9a0240bc7b | |||
| dd94a843b5 | |||
| 9426d08aa2 | |||
| fe2fac37f8 | |||
| cabd64df00 | |||
| bb57a54089 | |||
| 5e0bfba7bf | |||
| f6c19e469f | |||
| 13f09cc662 | |||
| a7e2856887 | |||
| 721e047485 | |||
| 301ff155a4 | |||
| 40f2065575 | |||
| be906eb823 | |||
| 2cee825f61 | |||
| ea6308bfdf | |||
| c6a6f7e2ab | |||
| 20077c285a | |||
| fa13016785 | |||
| b81bb9d621 | |||
| 2deb53c14f |
4
.github/workflows/static.yml
vendored
4
.github/workflows/static.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
|||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: 7.4
|
php-version: 8.0
|
||||||
tools: composer:v2
|
tools: composer:v2
|
||||||
coverage: none
|
coverage: none
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ jobs:
|
|||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: 7.4
|
php-version: 8.0
|
||||||
tools: composer:v2
|
tools: composer:v2
|
||||||
coverage: none
|
coverage: none
|
||||||
|
|
||||||
|
|||||||
19
CHANGELOG.md
19
CHANGELOG.md
@ -4,7 +4,24 @@ 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.0.0 (2021-01-18)](https://github.com/pestphp/pest/compare/v1.0.0...v1.0.1)
|
## [v1.0.5 (2021-03-31)](https://github.com/pestphp/pest/compare/v1.0.4...v1.0.5)
|
||||||
|
### Added
|
||||||
|
- Add `--browse` option to `pest:dusk` command ([#280](https://github.com/pestphp/pest/pull/280))
|
||||||
|
- Support for PHPUnit 9.5.4 ([#284](https://github.com/pestphp/pest/pull/284))
|
||||||
|
|
||||||
|
## [v1.0.4 (2021-03-17)](https://github.com/pestphp/pest/compare/v1.0.3...v1.0.4)
|
||||||
|
### Added
|
||||||
|
- Support for PHPUnit 9.5.3 ([#278](https://github.com/pestphp/pest/pull/278))
|
||||||
|
|
||||||
|
## [v1.0.3 (2021-03-13)](https://github.com/pestphp/pest/compare/v1.0.2...v1.0.3)
|
||||||
|
### Added
|
||||||
|
- Support for test extensions ([#269](https://github.com/pestphp/pest/pull/269))
|
||||||
|
|
||||||
|
## [v1.0.2 (2021-02-04)](https://github.com/pestphp/pest/compare/v1.0.1...v1.0.2)
|
||||||
|
### Added
|
||||||
|
- Support for PHPUnit 9.5.2 ([#267](https://github.com/pestphp/pest/pull/267))
|
||||||
|
|
||||||
|
## [v1.0.1 (2021-01-18)](https://github.com/pestphp/pest/compare/v1.0.0...v1.0.1)
|
||||||
### Added
|
### Added
|
||||||
- Support for PHPUnit 9.5.1 ([#261](https://github.com/pestphp/pest/pull/261))
|
- Support for PHPUnit 9.5.1 ([#261](https://github.com/pestphp/pest/pull/261))
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
"pestphp/pest-plugin-coverage": "^1.0",
|
"pestphp/pest-plugin-coverage": "^1.0",
|
||||||
"pestphp/pest-plugin-expectations": "^1.0",
|
"pestphp/pest-plugin-expectations": "^1.0",
|
||||||
"pestphp/pest-plugin-init": "^1.0",
|
"pestphp/pest-plugin-init": "^1.0",
|
||||||
"phpunit/phpunit": ">= 9.3.7 <= 9.5.1"
|
"phpunit/phpunit": ">= 9.3.7 <= 9.5.4"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@ -43,10 +43,10 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"illuminate/console": "^8.0",
|
"illuminate/console": "^8.32.1",
|
||||||
"illuminate/support": "^8.0",
|
"illuminate/support": "^8.32.1",
|
||||||
"laravel/dusk": "^6.9.1",
|
"laravel/dusk": "^6.13.0",
|
||||||
"mockery/mockery": "^1.4.1",
|
"mockery/mockery": "^1.4.3",
|
||||||
"pestphp/pest-dev-tools": "dev-master"
|
"pestphp/pest-dev-tools": "dev-master"
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
|
|||||||
@ -14,7 +14,6 @@ parameters:
|
|||||||
|
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
- "#type mixed is not subtype of native#"
|
- "#type mixed is not subtype of native#"
|
||||||
- "#Undefined variable: \\$this#"
|
|
||||||
- "#is not allowed to extend#"
|
- "#is not allowed to extend#"
|
||||||
- "#Language construct eval#"
|
- "#Language construct eval#"
|
||||||
- "# with null as default value#"
|
- "# with null as default value#"
|
||||||
|
|||||||
@ -5,14 +5,17 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Factories;
|
namespace Pest\Factories;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use ParseError;
|
||||||
use Pest\Concerns;
|
use Pest\Concerns;
|
||||||
use Pest\Contracts\HasPrintableTestCaseName;
|
use Pest\Contracts\HasPrintableTestCaseName;
|
||||||
use Pest\Datasets;
|
use Pest\Datasets;
|
||||||
use Pest\Exceptions\ShouldNotHappen;
|
use Pest\Exceptions\ShouldNotHappen;
|
||||||
use Pest\Support\HigherOrderMessageCollection;
|
use Pest\Support\HigherOrderMessageCollection;
|
||||||
use Pest\Support\NullClosure;
|
use Pest\Support\NullClosure;
|
||||||
|
use Pest\Support\Str;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -139,6 +142,7 @@ final class TestCaseFactory
|
|||||||
$proxies->proxy($this);
|
$proxies->proxy($this);
|
||||||
$chains->chain($this);
|
$chains->chain($this);
|
||||||
|
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
return call_user_func(Closure::bind($factoryTest, $this, get_class($this)), ...func_get_args());
|
return call_user_func(Closure::bind($factoryTest, $this, get_class($this)), ...func_get_args());
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -168,7 +172,7 @@ final class TestCaseFactory
|
|||||||
}, $filename);
|
}, $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = (string) realpath($filename);
|
$filename = str_replace('\\\\', '\\', addslashes((string) realpath($filename)));
|
||||||
$rootPath = TestSuite::getInstance()->rootPath;
|
$rootPath = TestSuite::getInstance()->rootPath;
|
||||||
$relativePath = str_replace($rootPath . DIRECTORY_SEPARATOR, '', $filename);
|
$relativePath = str_replace($rootPath . DIRECTORY_SEPARATOR, '', $filename);
|
||||||
$relativePath = dirname(ucfirst($relativePath)) . DIRECTORY_SEPARATOR . basename($relativePath, '.php');
|
$relativePath = dirname(ucfirst($relativePath)) . DIRECTORY_SEPARATOR . basename($relativePath, '.php');
|
||||||
@ -176,8 +180,12 @@ final class TestCaseFactory
|
|||||||
|
|
||||||
// Strip out any %-encoded octets.
|
// Strip out any %-encoded octets.
|
||||||
$relativePath = (string) preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $relativePath);
|
$relativePath = (string) preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $relativePath);
|
||||||
|
// Remove escaped quote sequences (maintain namespace)
|
||||||
|
$relativePath = str_replace(array_map(function (string $quote): string {
|
||||||
|
return sprintf('\\%s', $quote);
|
||||||
|
}, ['\'', '"']), '', $relativePath);
|
||||||
// Limit to A-Z, a-z, 0-9, '_', '-'.
|
// Limit to A-Z, a-z, 0-9, '_', '-'.
|
||||||
$relativePath = (string) preg_replace('/[^A-Za-z0-9.\\\]/', '', $relativePath);
|
$relativePath = (string) preg_replace('/[^A-Za-z0-9\\\\]/', '', $relativePath);
|
||||||
|
|
||||||
$classFQN = 'P\\' . $relativePath;
|
$classFQN = 'P\\' . $relativePath;
|
||||||
if (class_exists($classFQN)) {
|
if (class_exists($classFQN)) {
|
||||||
@ -194,15 +202,24 @@ final class TestCaseFactory
|
|||||||
$namespace = implode('\\', $partsFQN);
|
$namespace = implode('\\', $partsFQN);
|
||||||
$baseClass = sprintf('\%s', $this->class);
|
$baseClass = sprintf('\%s', $this->class);
|
||||||
|
|
||||||
eval("
|
if ('' === trim($className)) {
|
||||||
namespace $namespace;
|
$className = 'InvalidTestName' . Str::random();
|
||||||
|
$classFQN .= $className;
|
||||||
|
}
|
||||||
|
|
||||||
final class $className extends $baseClass implements $hasPrintableTestCaseClassFQN {
|
try {
|
||||||
$traitsCode
|
eval("
|
||||||
|
namespace $namespace;
|
||||||
|
|
||||||
private static \$__filename = '$filename';
|
final class $className extends $baseClass implements $hasPrintableTestCaseClassFQN {
|
||||||
}
|
$traitsCode
|
||||||
");
|
|
||||||
|
private static \$__filename = '$filename';
|
||||||
|
}
|
||||||
|
");
|
||||||
|
} catch (ParseError $caught) {
|
||||||
|
throw new RuntimeException(sprintf('Unable to create test case for test file at %s', $filename), 1, $caught);
|
||||||
|
}
|
||||||
|
|
||||||
return $classFQN;
|
return $classFQN;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,9 @@ final class PestDuskCommand extends DuskCommand
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'pest:dusk {--without-tty : Disable output to TTY}';
|
protected $signature = 'pest:dusk
|
||||||
|
{--browse : Open a browser instead of using headless mode}
|
||||||
|
{--without-tty : Disable output to TTY}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
|
|||||||
@ -6,5 +6,5 @@ namespace Pest;
|
|||||||
|
|
||||||
function version(): string
|
function version(): string
|
||||||
{
|
{
|
||||||
return '1.0.1';
|
return '1.0.5';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,9 @@ final class ChainableClosure
|
|||||||
public static function from(Closure $closure, Closure $next): Closure
|
public static function from(Closure $closure, Closure $next): Closure
|
||||||
{
|
{
|
||||||
return function () use ($closure, $next): void {
|
return function () use ($closure, $next): void {
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
call_user_func_array(Closure::bind($closure, $this, get_class($this)), func_get_args());
|
call_user_func_array(Closure::bind($closure, $this, get_class($this)), func_get_args());
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
call_user_func_array(Closure::bind($next, $this, get_class($this)), func_get_args());
|
call_user_func_array(Closure::bind($next, $this, get_class($this)), func_get_args());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,6 +79,7 @@ final class Container
|
|||||||
|
|
||||||
if ($candidate === null) {
|
if ($candidate === null) {
|
||||||
$type = $param->getType();
|
$type = $param->getType();
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
if ($type !== null && $type->isBuiltin()) {
|
if ($type !== null && $type->isBuiltin()) {
|
||||||
$candidate = $param->getName();
|
$candidate = $param->getName();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -9,6 +9,25 @@ namespace Pest\Support;
|
|||||||
*/
|
*/
|
||||||
final class Str
|
final class Str
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Pool of alpha-numeric characters for generating (unsafe) random strings
|
||||||
|
* from.
|
||||||
|
*/
|
||||||
|
private const POOL = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a (unsecure & non-cryptographically safe) random alpha-numeric
|
||||||
|
* string value.
|
||||||
|
*
|
||||||
|
* @param int $length the length of the resulting randomized string
|
||||||
|
*
|
||||||
|
* @see https://github.com/laravel/framework/blob/4.2/src/Illuminate/Support/Str.php#L240-L242
|
||||||
|
*/
|
||||||
|
public static function random(int $length = 16): string
|
||||||
|
{
|
||||||
|
return substr(str_shuffle(str_repeat(self::POOL, 5)), 0, $length);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the given `$target` starts with the given `$search`.
|
* Checks if the given `$target` starts with the given `$search`.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -103,6 +103,27 @@
|
|||||||
PASS Tests\Fixtures\ExampleTest
|
PASS Tests\Fixtures\ExampleTest
|
||||||
✓ it example 2
|
✓ it example 2
|
||||||
|
|
||||||
|
PASS Tests\PHPUnit\CustomAffixes\InvalidTestName
|
||||||
|
✓ it runs file names like `@#$%^&()-_=+.php`
|
||||||
|
|
||||||
|
PASS Tests\PHPUnit\CustomAffixes\ATestWithSpaces
|
||||||
|
✓ it runs file names like `A Test With Spaces.php`
|
||||||
|
|
||||||
|
PASS Tests\PHPUnit\CustomAffixes\AdditionalFileExtensionspec
|
||||||
|
✓ it runs file names like `AdditionalFileExtension.spec.php`
|
||||||
|
|
||||||
|
PASS Tests\PHPUnit\CustomAffixes\ManyExtensionsclasstest
|
||||||
|
✓ it runs file names like `ManyExtensions.class.test.php`
|
||||||
|
|
||||||
|
PASS Tests\PHPUnit\CustomAffixes\TestCaseWithQuotes
|
||||||
|
✓ it runs file names like `Test 'Case' With Quotes.php`
|
||||||
|
|
||||||
|
PASS Tests\PHPUnit\CustomAffixes\kebabcasespec
|
||||||
|
✓ it runs file names like `kebab-case-spec.php`
|
||||||
|
|
||||||
|
PASS Tests\PHPUnit\CustomAffixes\snakecasespec
|
||||||
|
✓ it runs file names like `snake_case_spec.php`
|
||||||
|
|
||||||
PASS Tests\PHPUnit\CustomTestCase\UsesPerDirectory
|
PASS Tests\PHPUnit\CustomTestCase\UsesPerDirectory
|
||||||
✓ closure was bound to CustomTestCase
|
✓ closure was bound to CustomTestCase
|
||||||
|
|
||||||
@ -188,5 +209,5 @@
|
|||||||
✓ it is a test
|
✓ it is a test
|
||||||
✓ it uses correct parent class
|
✓ it uses correct parent class
|
||||||
|
|
||||||
Tests: 7 skipped, 108 passed
|
Tests: 7 skipped, 115 passed
|
||||||
|
|
||||||
10
tests/PHPUnit/CustomAffixes/@#$%^&()-_=+.php
Normal file
10
tests/PHPUnit/CustomAffixes/@#$%^&()-_=+.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE: To preserve cross-platform testing compatibility we cannot use ! * and
|
||||||
|
* other Windows reserved characters in this test's filename.
|
||||||
|
*
|
||||||
|
* See https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
|
||||||
|
*/
|
||||||
|
|
||||||
|
it(sprintf('runs file names like `%s`', basename(__FILE__)))->assertTrue(true);
|
||||||
3
tests/PHPUnit/CustomAffixes/A Test With Spaces.php
Normal file
3
tests/PHPUnit/CustomAffixes/A Test With Spaces.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
it(sprintf('runs file names like `%s`', basename(__FILE__)))->assertTrue(true);
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
it(sprintf('runs file names like `%s`', basename(__FILE__)))->assertTrue(true);
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
it(sprintf('runs file names like `%s`', basename(__FILE__)))->assertTrue(true);
|
||||||
3
tests/PHPUnit/CustomAffixes/Test 'Case' With Quotes.php
Normal file
3
tests/PHPUnit/CustomAffixes/Test 'Case' With Quotes.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
it(sprintf('runs file names like `%s`', basename(__FILE__)))->assertTrue(true);
|
||||||
3
tests/PHPUnit/CustomAffixes/kebab-case-spec.php
Normal file
3
tests/PHPUnit/CustomAffixes/kebab-case-spec.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
it(sprintf('runs file names like `%s`', basename(__FILE__)))->assertTrue(true);
|
||||||
3
tests/PHPUnit/CustomAffixes/snake_case_spec.php
Normal file
3
tests/PHPUnit/CustomAffixes/snake_case_spec.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
it(sprintf('runs file names like `%s`', basename(__FILE__)))->assertTrue(true);
|
||||||
@ -13,7 +13,13 @@ test('visual snapshot of test suite on success', function () {
|
|||||||
|
|
||||||
$process->run();
|
$process->run();
|
||||||
|
|
||||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
return preg_replace([
|
||||||
|
'#\\x1b[[][^A-Za-z]*[A-Za-z]#',
|
||||||
|
'/(Tests\\\PHPUnit\\\CustomAffixes\\\InvalidTestName)([A-Za-z0-9]*)/',
|
||||||
|
], [
|
||||||
|
'',
|
||||||
|
'$1',
|
||||||
|
], $process->getOutput());
|
||||||
};
|
};
|
||||||
|
|
||||||
if (getenv('REBUILD_SNAPSHOTS')) {
|
if (getenv('REBUILD_SNAPSHOTS')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user