mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 7.4
|
||||
php-version: 8.0
|
||||
tools: composer:v2
|
||||
coverage: none
|
||||
|
||||
@ -40,7 +40,7 @@ jobs:
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 7.4
|
||||
php-version: 8.0
|
||||
tools: composer:v2
|
||||
coverage: none
|
||||
|
||||
|
||||
10
CHANGELOG.md
10
CHANGELOG.md
@ -4,7 +4,15 @@ 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.0.0 (2021-01-18)](https://github.com/pestphp/pest/compare/v1.0.0...v1.0.1)
|
||||
## [v1.0.3 (2021-03-13)](https://github.com/pestphp/pest/compare/v1.0.2...v1.0.3)
|
||||
### Added
|
||||
- Support for test extensions ([#269](https://github.com/pestphp/pest/pull/269))
|
||||
|
||||
## [v1.0.2 (2021-02-04)](https://github.com/pestphp/pest/compare/v1.0.1...v1.0.2)
|
||||
### Added
|
||||
- Support for PHPUnit 9.5.2 ([#267](https://github.com/pestphp/pest/pull/267))
|
||||
|
||||
## [v1.0.1 (2021-01-18)](https://github.com/pestphp/pest/compare/v1.0.0...v1.0.1)
|
||||
### Added
|
||||
- Support for PHPUnit 9.5.1 ([#261](https://github.com/pestphp/pest/pull/261))
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
"pestphp/pest-plugin-coverage": "^1.0",
|
||||
"pestphp/pest-plugin-expectations": "^1.0",
|
||||
"pestphp/pest-plugin-init": "^1.0",
|
||||
"phpunit/phpunit": ">= 9.3.7 <= 9.5.1"
|
||||
"phpunit/phpunit": ">= 9.3.7 <= 9.5.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@ -43,10 +43,10 @@
|
||||
]
|
||||
},
|
||||
"require-dev": {
|
||||
"illuminate/console": "^8.0",
|
||||
"illuminate/support": "^8.0",
|
||||
"laravel/dusk": "^6.9.1",
|
||||
"mockery/mockery": "^1.4.1",
|
||||
"illuminate/console": "^8.32.1",
|
||||
"illuminate/support": "^8.32.1",
|
||||
"laravel/dusk": "^6.13.0",
|
||||
"mockery/mockery": "^1.4.3",
|
||||
"pestphp/pest-dev-tools": "dev-master"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
|
||||
@ -14,7 +14,6 @@ parameters:
|
||||
|
||||
ignoreErrors:
|
||||
- "#type mixed is not subtype of native#"
|
||||
- "#Undefined variable: \\$this#"
|
||||
- "#is not allowed to extend#"
|
||||
- "#Language construct eval#"
|
||||
- "# with null as default value#"
|
||||
|
||||
@ -5,14 +5,17 @@ declare(strict_types=1);
|
||||
namespace Pest\Factories;
|
||||
|
||||
use Closure;
|
||||
use ParseError;
|
||||
use Pest\Concerns;
|
||||
use Pest\Contracts\HasPrintableTestCaseName;
|
||||
use Pest\Datasets;
|
||||
use Pest\Exceptions\ShouldNotHappen;
|
||||
use Pest\Support\HigherOrderMessageCollection;
|
||||
use Pest\Support\NullClosure;
|
||||
use Pest\Support\Str;
|
||||
use Pest\TestSuite;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -139,6 +142,7 @@ final class TestCaseFactory
|
||||
$proxies->proxy($this);
|
||||
$chains->chain($this);
|
||||
|
||||
/* @phpstan-ignore-next-line */
|
||||
return call_user_func(Closure::bind($factoryTest, $this, get_class($this)), ...func_get_args());
|
||||
};
|
||||
|
||||
@ -168,7 +172,7 @@ final class TestCaseFactory
|
||||
}, $filename);
|
||||
}
|
||||
|
||||
$filename = (string) realpath($filename);
|
||||
$filename = str_replace('\\\\', '\\', addslashes((string) realpath($filename)));
|
||||
$rootPath = TestSuite::getInstance()->rootPath;
|
||||
$relativePath = str_replace($rootPath . DIRECTORY_SEPARATOR, '', $filename);
|
||||
$relativePath = dirname(ucfirst($relativePath)) . DIRECTORY_SEPARATOR . basename($relativePath, '.php');
|
||||
@ -176,8 +180,12 @@ final class TestCaseFactory
|
||||
|
||||
// Strip out any %-encoded octets.
|
||||
$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, '_', '-'.
|
||||
$relativePath = (string) preg_replace('/[^A-Za-z0-9.\\\]/', '', $relativePath);
|
||||
$relativePath = (string) preg_replace('/[^A-Za-z0-9\\\\]/', '', $relativePath);
|
||||
|
||||
$classFQN = 'P\\' . $relativePath;
|
||||
if (class_exists($classFQN)) {
|
||||
@ -194,6 +202,12 @@ final class TestCaseFactory
|
||||
$namespace = implode('\\', $partsFQN);
|
||||
$baseClass = sprintf('\%s', $this->class);
|
||||
|
||||
if ('' === trim($className)) {
|
||||
$className = 'InvalidTestName' . Str::random();
|
||||
$classFQN .= $className;
|
||||
}
|
||||
|
||||
try {
|
||||
eval("
|
||||
namespace $namespace;
|
||||
|
||||
@ -203,6 +217,9 @@ final class TestCaseFactory
|
||||
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;
|
||||
}
|
||||
|
||||
@ -6,5 +6,5 @@ namespace Pest;
|
||||
|
||||
function version(): string
|
||||
{
|
||||
return '1.0.1';
|
||||
return '1.0.3';
|
||||
}
|
||||
|
||||
@ -17,7 +17,9 @@ final class ChainableClosure
|
||||
public static function from(Closure $closure, Closure $next): Closure
|
||||
{
|
||||
return function () use ($closure, $next): void {
|
||||
/* @phpstan-ignore-next-line */
|
||||
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());
|
||||
};
|
||||
}
|
||||
|
||||
@ -79,6 +79,7 @@ final class Container
|
||||
|
||||
if ($candidate === null) {
|
||||
$type = $param->getType();
|
||||
/* @phpstan-ignore-next-line */
|
||||
if ($type !== null && $type->isBuiltin()) {
|
||||
$candidate = $param->getName();
|
||||
} else {
|
||||
|
||||
@ -9,6 +9,25 @@ namespace Pest\Support;
|
||||
*/
|
||||
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`.
|
||||
*/
|
||||
|
||||
@ -103,6 +103,27 @@
|
||||
PASS Tests\Fixtures\ExampleTest
|
||||
✓ 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
|
||||
✓ closure was bound to CustomTestCase
|
||||
|
||||
@ -188,5 +209,5 @@
|
||||
✓ it is a test
|
||||
✓ 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();
|
||||
|
||||
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')) {
|
||||
|
||||
Reference in New Issue
Block a user