mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Migrates to Pint
This commit is contained in:
10
.github/workflows/static.yml
vendored
10
.github/workflows/static.yml
vendored
@ -47,5 +47,11 @@ jobs:
|
|||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: composer update --prefer-stable --no-interaction --no-progress --ansi
|
run: composer update --prefer-stable --no-interaction --no-progress --ansi
|
||||||
|
|
||||||
- name: Run PHPStan
|
- name: Types
|
||||||
run: vendor/bin/phpstan analyse --no-progress --debug --ansi
|
run: composer test:types
|
||||||
|
|
||||||
|
- name: Style
|
||||||
|
run: composer test:lint
|
||||||
|
|
||||||
|
- name: Recfato
|
||||||
|
run: composer test:refacto
|
||||||
|
|||||||
6
.github/workflows/tests.yml
vendored
6
.github/workflows/tests.yml
vendored
@ -34,11 +34,11 @@ jobs:
|
|||||||
run: composer update --${{ matrix.dependency-version }} --no-interaction --no-progress --ansi
|
run: composer update --${{ matrix.dependency-version }} --no-interaction --no-progress --ansi
|
||||||
|
|
||||||
- name: Unit Tests
|
- name: Unit Tests
|
||||||
run: php bin/pest --colors=always --exclude-group=integration
|
run: composer test:unit
|
||||||
|
|
||||||
- name: Unit Tests
|
- name: Unit Tests
|
||||||
run: php bin/pest --colors=always --exclude-group=integration ${{ matrix.parallel }}
|
run: test:parallel
|
||||||
if: ${{ false }} # 2.x-dev is under development
|
if: ${{ false }} # 2.x-dev is under development
|
||||||
|
|
||||||
- name: Integration Tests
|
- name: Integration Tests
|
||||||
run: php bin/pest --colors=always --group=integration -v
|
run: composer test:integration
|
||||||
|
|||||||
@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
$finder = PhpCsFixer\Finder::create()
|
|
||||||
->in(__DIR__ . DIRECTORY_SEPARATOR . 'tests')
|
|
||||||
->in(__DIR__ . DIRECTORY_SEPARATOR . 'bin')
|
|
||||||
->in(__DIR__ . DIRECTORY_SEPARATOR . 'overrides')
|
|
||||||
->in(__DIR__ . DIRECTORY_SEPARATOR . 'stubs')
|
|
||||||
->in(__DIR__ . DIRECTORY_SEPARATOR . 'src')
|
|
||||||
->append(['.php-cs-fixer.dist.php']);
|
|
||||||
|
|
||||||
$rules = [
|
|
||||||
'@Symfony' => true,
|
|
||||||
'phpdoc_no_empty_return' => false,
|
|
||||||
'array_syntax' => ['syntax' => 'short'],
|
|
||||||
'yoda_style' => false,
|
|
||||||
'binary_operator_spaces' => [
|
|
||||||
'operators' => [
|
|
||||||
'=>' => 'align',
|
|
||||||
'=' => 'align',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'concat_space' => ['spacing' => 'one'],
|
|
||||||
'not_operator_with_space' => false,
|
|
||||||
];
|
|
||||||
|
|
||||||
$rules['increment_style'] = ['style' => 'post'];
|
|
||||||
|
|
||||||
return (new PhpCsFixer\Config())
|
|
||||||
->setUsingCache(true)
|
|
||||||
->setRules($rules)
|
|
||||||
->setFinder($finder);
|
|
||||||
@ -51,7 +51,13 @@
|
|||||||
"illuminate/console": "^9.30.1",
|
"illuminate/console": "^9.30.1",
|
||||||
"illuminate/support": "^9.30.1",
|
"illuminate/support": "^9.30.1",
|
||||||
"laravel/dusk": "^6.25.1",
|
"laravel/dusk": "^6.25.1",
|
||||||
"pestphp/pest-dev-tools": "dev-master"
|
"ergebnis/phpstan-rules": "^1.0.0",
|
||||||
|
"laravel/pint": "^1.2.0",
|
||||||
|
"phpstan/phpstan": "^1.8.5",
|
||||||
|
"phpstan/phpstan-strict-rules": "^1.4.3",
|
||||||
|
"symfony/var-dumper": "^6.2.0",
|
||||||
|
"thecodingmachine/phpstan-strict-rules": "^1.0.0",
|
||||||
|
"rector/rector": "^0.14.2"
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
@ -66,8 +72,10 @@
|
|||||||
"bin/pest"
|
"bin/pest"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix -v",
|
"lint": "pint --test",
|
||||||
"test:lint": "PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix -v --dry-run",
|
"refactor": "rector",
|
||||||
|
"test:lint": "pint --test",
|
||||||
|
"test:refactor": "rector --dry-run",
|
||||||
"test:types": "phpstan analyse --ansi --memory-limit=-1 --debug",
|
"test:types": "phpstan analyse --ansi --memory-limit=-1 --debug",
|
||||||
"test:unit": "php bin/pest --colors=always --exclude-group=integration",
|
"test:unit": "php bin/pest --colors=always --exclude-group=integration",
|
||||||
"test:parallel": "exit 1",
|
"test:parallel": "exit 1",
|
||||||
@ -77,7 +85,8 @@
|
|||||||
"@test:lint",
|
"@test:lint",
|
||||||
"@test:types",
|
"@test:types",
|
||||||
"@test:unit",
|
"@test:unit",
|
||||||
"@test:integration"
|
"@test:integration",
|
||||||
|
"@test:refactor"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
|
|||||||
@ -37,22 +37,16 @@
|
|||||||
namespace PHPUnit\Runner\Filter;
|
namespace PHPUnit\Runner\Filter;
|
||||||
|
|
||||||
use function end;
|
use function end;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
use function implode;
|
use function implode;
|
||||||
|
|
||||||
use Pest\Contracts\HasPrintableTestCaseName;
|
use Pest\Contracts\HasPrintableTestCaseName;
|
||||||
use PHPUnit\Framework\SelfDescribing;
|
use PHPUnit\Framework\SelfDescribing;
|
||||||
use PHPUnit\Framework\Test;
|
use PHPUnit\Framework\Test;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\TestSuite;
|
use PHPUnit\Framework\TestSuite;
|
||||||
|
|
||||||
use function preg_match;
|
use function preg_match;
|
||||||
|
|
||||||
use RecursiveFilterIterator;
|
use RecursiveFilterIterator;
|
||||||
use RecursiveIterator;
|
use RecursiveIterator;
|
||||||
|
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
use function str_replace;
|
use function str_replace;
|
||||||
|
|
||||||
@ -62,7 +56,9 @@ use function str_replace;
|
|||||||
final class NameFilterIterator extends RecursiveFilterIterator
|
final class NameFilterIterator extends RecursiveFilterIterator
|
||||||
{
|
{
|
||||||
private ?string $filter = null;
|
private ?string $filter = null;
|
||||||
|
|
||||||
private ?int $filterMin = null;
|
private ?int $filterMin = null;
|
||||||
|
|
||||||
private ?int $filterMax = null;
|
private ?int $filterMax = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,7 +90,7 @@ final class NameFilterIterator extends RecursiveFilterIterator
|
|||||||
$accepted = @preg_match($this->filter, $name, $matches);
|
$accepted = @preg_match($this->filter, $name, $matches);
|
||||||
|
|
||||||
if ($accepted && isset($this->filterMax)) {
|
if ($accepted && isset($this->filterMax)) {
|
||||||
$set = end($matches);
|
$set = end($matches);
|
||||||
$accepted = $set >= $this->filterMin && $set <= $this->filterMax;
|
$accepted = $set >= $this->filterMin && $set <= $this->filterMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -43,14 +43,12 @@ use function array_values;
|
|||||||
use function basename;
|
use function basename;
|
||||||
use function class_exists;
|
use function class_exists;
|
||||||
use function get_declared_classes;
|
use function get_declared_classes;
|
||||||
|
|
||||||
use Pest\Contracts\HasPrintableTestCaseName;
|
use Pest\Contracts\HasPrintableTestCaseName;
|
||||||
use Pest\TestCases\IgnorableTest;
|
use Pest\TestCases\IgnorableTest;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
|
||||||
use function substr;
|
use function substr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,7 +114,7 @@ final class TestSuiteLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$testCaseFound) {
|
if (! $testCaseFound) {
|
||||||
foreach (self::$loadedClasses as $loadedClass) {
|
foreach (self::$loadedClasses as $loadedClass) {
|
||||||
if (is_subclass_of($loadedClass, TestCase::class)) {
|
if (is_subclass_of($loadedClass, TestCase::class)) {
|
||||||
$suiteClassName = $loadedClass;
|
$suiteClassName = $loadedClass;
|
||||||
@ -126,7 +124,7 @@ final class TestSuiteLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!class_exists($suiteClassName, false)) {
|
if (! class_exists($suiteClassName, false)) {
|
||||||
return $this->exceptionFor($suiteClassName, $suiteClassFile);
|
return $this->exceptionFor($suiteClassName, $suiteClassFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +136,7 @@ final class TestSuiteLoader
|
|||||||
}
|
}
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
if ($class->isSubclassOf(TestCase::class) && !$class->isAbstract()) {
|
if ($class->isSubclassOf(TestCase::class) && ! $class->isAbstract()) {
|
||||||
return $class;
|
return $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +149,7 @@ final class TestSuiteLoader
|
|||||||
}
|
}
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
if (!$method->isAbstract() && $method->isPublic() && $method->isStatic()) {
|
if (! $method->isAbstract() && $method->isPublic() && $method->isStatic()) {
|
||||||
return $class;
|
return $class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,7 +165,7 @@ final class TestSuiteLoader
|
|||||||
private function classNameFromFileName(string $suiteClassFile): string
|
private function classNameFromFileName(string $suiteClassFile): string
|
||||||
{
|
{
|
||||||
$className = basename($suiteClassFile, '.php');
|
$className = basename($suiteClassFile, '.php');
|
||||||
$dotPos = strpos($className, '.');
|
$dotPos = strpos($className, '.');
|
||||||
|
|
||||||
if ($dotPos !== false) {
|
if ($dotPos !== false) {
|
||||||
$className = substr($className, 0, $dotPos);
|
$className = substr($className, 0, $dotPos);
|
||||||
|
|||||||
28
rector.php
Normal file
28
rector.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
|
||||||
|
use Rector\Config\RectorConfig;
|
||||||
|
use Rector\Set\ValueObject\LevelSetList;
|
||||||
|
use Rector\Set\ValueObject\SetList;
|
||||||
|
|
||||||
|
return static function (RectorConfig $rectorConfig): void {
|
||||||
|
$rectorConfig->paths([
|
||||||
|
__DIR__.'/bin',
|
||||||
|
__DIR__.'/src',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$rectorConfig->rules([
|
||||||
|
InlineConstructorDefaultToPropertyRector::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$rectorConfig->sets([
|
||||||
|
LevelSetList::UP_TO_PHP_81,
|
||||||
|
SetList::CODE_QUALITY,
|
||||||
|
SetList::DEAD_CODE,
|
||||||
|
SetList::EARLY_RETURN,
|
||||||
|
SetList::TYPE_DECLARATION,
|
||||||
|
SetList::PRIVATIZATION,
|
||||||
|
]);
|
||||||
|
};
|
||||||
@ -5,9 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Bootstrappers;
|
namespace Pest\Bootstrappers;
|
||||||
|
|
||||||
use Pest\Support\Str;
|
use Pest\Support\Str;
|
||||||
|
|
||||||
use function Pest\testDirectory;
|
use function Pest\testDirectory;
|
||||||
|
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use RecursiveDirectoryIterator;
|
use RecursiveDirectoryIterator;
|
||||||
use RecursiveIteratorIterator;
|
use RecursiveIteratorIterator;
|
||||||
@ -37,19 +35,19 @@ final class BootFiles
|
|||||||
*/
|
*/
|
||||||
public function __invoke(): void
|
public function __invoke(): void
|
||||||
{
|
{
|
||||||
$rootPath = TestSuite::getInstance()->rootPath;
|
$rootPath = TestSuite::getInstance()->rootPath;
|
||||||
$testsPath = $rootPath . DIRECTORY_SEPARATOR . testDirectory();
|
$testsPath = $rootPath.DIRECTORY_SEPARATOR.testDirectory();
|
||||||
|
|
||||||
foreach (self::STRUCTURE as $filename) {
|
foreach (self::STRUCTURE as $filename) {
|
||||||
$filename = sprintf('%s%s%s', $testsPath, DIRECTORY_SEPARATOR, $filename);
|
$filename = sprintf('%s%s%s', $testsPath, DIRECTORY_SEPARATOR, $filename);
|
||||||
|
|
||||||
if (!file_exists($filename)) {
|
if (! file_exists($filename)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_dir($filename)) {
|
if (is_dir($filename)) {
|
||||||
$directory = new RecursiveDirectoryIterator($filename);
|
$directory = new RecursiveDirectoryIterator($filename);
|
||||||
$iterator = new RecursiveIteratorIterator($directory);
|
$iterator = new RecursiveIteratorIterator($directory);
|
||||||
/** @var \DirectoryIterator $file */
|
/** @var \DirectoryIterator $file */
|
||||||
foreach ($iterator as $file) {
|
foreach ($iterator as $file) {
|
||||||
$this->load($file->__toString());
|
$this->load($file->__toString());
|
||||||
|
|||||||
@ -16,8 +16,7 @@ trait Expectable
|
|||||||
*
|
*
|
||||||
* Creates a new Expectation.
|
* Creates a new Expectation.
|
||||||
*
|
*
|
||||||
* @param TValue $value
|
* @param TValue $value
|
||||||
*
|
|
||||||
* @return Expectation<TValue>
|
* @return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function expect(mixed $value): Expectation
|
public function expect(mixed $value): Expectation
|
||||||
|
|||||||
@ -16,9 +16,8 @@ trait Retrievable
|
|||||||
*
|
*
|
||||||
* @template TRetrievableValue
|
* @template TRetrievableValue
|
||||||
*
|
*
|
||||||
* @param array<string, TRetrievableValue>|object $value
|
* @param array<string, TRetrievableValue>|object $value
|
||||||
* @param TRetrievableValue|null $default
|
* @param TRetrievableValue|null $default
|
||||||
*
|
|
||||||
* @return TRetrievableValue|null
|
* @return TRetrievableValue|null
|
||||||
*/
|
*/
|
||||||
private function retrieve(string $key, mixed $value, mixed $default = null): mixed
|
private function retrieve(string $key, mixed $value, mixed $default = null): mixed
|
||||||
|
|||||||
@ -55,7 +55,7 @@ trait Testable
|
|||||||
public static function flush(): void
|
public static function flush(): void
|
||||||
{
|
{
|
||||||
self::$__beforeAll = null;
|
self::$__beforeAll = null;
|
||||||
self::$__afterAll = null;
|
self::$__afterAll = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,9 +68,9 @@ trait Testable
|
|||||||
$test = TestSuite::getInstance()->tests->get(self::$__filename);
|
$test = TestSuite::getInstance()->tests->get(self::$__filename);
|
||||||
|
|
||||||
if ($test->hasMethod($name)) {
|
if ($test->hasMethod($name)) {
|
||||||
$method = $test->getMethod($name);
|
$method = $test->getMethod($name);
|
||||||
self::$__description = $method->description;
|
self::$__description = $method->description;
|
||||||
$this->__test = $method->getClosure($this);
|
$this->__test = $method->getClosure($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ trait Testable
|
|||||||
*/
|
*/
|
||||||
public function __addBeforeAll(?Closure $hook): void
|
public function __addBeforeAll(?Closure $hook): void
|
||||||
{
|
{
|
||||||
if (!$hook) {
|
if (! $hook) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ trait Testable
|
|||||||
*/
|
*/
|
||||||
public function __addAfterAll(?Closure $hook): void
|
public function __addAfterAll(?Closure $hook): void
|
||||||
{
|
{
|
||||||
if (!$hook) {
|
if (! $hook) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ trait Testable
|
|||||||
*/
|
*/
|
||||||
private function __addHook(string $property, ?Closure $hook): void
|
private function __addHook(string $property, ?Closure $hook): void
|
||||||
{
|
{
|
||||||
if (!$hook) {
|
if (! $hook) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ trait Testable
|
|||||||
$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());
|
$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());
|
||||||
|
|
||||||
if ($this->dataName()) {
|
if ($this->dataName()) {
|
||||||
self::$__description = $method->description . ' with ' . $this->dataName();
|
self::$__description = $method->description.' with '.$this->dataName();
|
||||||
} else {
|
} else {
|
||||||
self::$__description = $method->description;
|
self::$__description = $method->description;
|
||||||
}
|
}
|
||||||
@ -231,11 +231,11 @@ trait Testable
|
|||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$arguments[0] instanceof Closure) {
|
if (! $arguments[0] instanceof Closure) {
|
||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
$underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure');
|
$underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure');
|
||||||
$testParameterTypes = array_values(Reflection::getFunctionArguments($underlyingTest));
|
$testParameterTypes = array_values(Reflection::getFunctionArguments($underlyingTest));
|
||||||
|
|
||||||
if (in_array($testParameterTypes[0], ['Closure', 'callable'])) {
|
if (in_array($testParameterTypes[0], ['Closure', 'callable'])) {
|
||||||
@ -244,7 +244,7 @@ trait Testable
|
|||||||
|
|
||||||
$boundDatasetResult = $this->__callClosure($arguments[0], []);
|
$boundDatasetResult = $this->__callClosure($arguments[0], []);
|
||||||
|
|
||||||
if (count($testParameterTypes) === 1 || !is_array($boundDatasetResult)) {
|
if (count($testParameterTypes) === 1 || ! is_array($boundDatasetResult)) {
|
||||||
return [$boundDatasetResult];
|
return [$boundDatasetResult];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@ final class ConfigLoader
|
|||||||
$suiteDirectory = $this->config->xpath('/phpunit/testsuites/testsuite/directory');
|
$suiteDirectory = $this->config->xpath('/phpunit/testsuites/testsuite/directory');
|
||||||
|
|
||||||
// @phpstan-ignore-next-line
|
// @phpstan-ignore-next-line
|
||||||
if (!$suiteDirectory || count($suiteDirectory) === 0) {
|
if (! $suiteDirectory || count($suiteDirectory) === 0) {
|
||||||
return self::DEFAULT_TESTS_PATH;
|
return self::DEFAULT_TESTS_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,9 +71,9 @@ final class ConfigLoader
|
|||||||
public function getConfigurationFilePath(): string|false
|
public function getConfigurationFilePath(): string|false
|
||||||
{
|
{
|
||||||
$candidates = [
|
$candidates = [
|
||||||
$this->rootPath . '/phpunit.xml',
|
$this->rootPath.'/phpunit.xml',
|
||||||
$this->rootPath . '/phpunit.dist.xml',
|
$this->rootPath.'/phpunit.dist.xml',
|
||||||
$this->rootPath . '/phpunit.xml.dist',
|
$this->rootPath.'/phpunit.xml.dist',
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($candidates as $candidate) {
|
foreach ($candidates as $candidate) {
|
||||||
@ -97,7 +97,7 @@ final class ConfigLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
$oldReportingLevel = error_reporting(0);
|
$oldReportingLevel = error_reporting(0);
|
||||||
$content = file_get_contents($configPath);
|
$content = file_get_contents($configPath);
|
||||||
|
|
||||||
if ($content !== false) {
|
if ($content !== false) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -12,8 +12,7 @@ interface HandlesArguments
|
|||||||
/**
|
/**
|
||||||
* Adds arguments before of the Test Suite execution.
|
* Adds arguments before of the Test Suite execution.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $arguments
|
* @param array<int, string> $arguments
|
||||||
*
|
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
public function handleArguments(array $arguments): array;
|
public function handleArguments(array $arguments): array;
|
||||||
|
|||||||
@ -17,7 +17,7 @@ final class DatasetMissing extends BadFunctionCallException implements Exception
|
|||||||
/**
|
/**
|
||||||
* Creates a new Exception instance.
|
* Creates a new Exception instance.
|
||||||
*
|
*
|
||||||
* @param array<string, string> $arguments
|
* @param array<string, string> $arguments
|
||||||
*/
|
*/
|
||||||
public function __construct(string $file, string $name, array $arguments)
|
public function __construct(string $file, string $name, array $arguments)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -37,7 +37,7 @@ final class Expectation
|
|||||||
/**
|
/**
|
||||||
* Creates a new expectation.
|
* Creates a new expectation.
|
||||||
*
|
*
|
||||||
* @param TValue $value
|
* @param TValue $value
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public mixed $value
|
public mixed $value
|
||||||
@ -50,8 +50,7 @@ final class Expectation
|
|||||||
*
|
*
|
||||||
* @template TAndValue
|
* @template TAndValue
|
||||||
*
|
*
|
||||||
* @param TAndValue $value
|
* @param TAndValue $value
|
||||||
*
|
|
||||||
* @return self<TAndValue>
|
* @return self<TAndValue>
|
||||||
*/
|
*/
|
||||||
public function and(mixed $value): Expectation
|
public function and(mixed $value): Expectation
|
||||||
@ -66,7 +65,7 @@ final class Expectation
|
|||||||
*/
|
*/
|
||||||
public function json(): Expectation
|
public function json(): Expectation
|
||||||
{
|
{
|
||||||
if (!is_string($this->value)) {
|
if (! is_string($this->value)) {
|
||||||
InvalidExpectationValue::expected('string');
|
InvalidExpectationValue::expected('string');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +138,7 @@ final class Expectation
|
|||||||
*/
|
*/
|
||||||
public function each(callable $callback = null): EachExpectation
|
public function each(callable $callback = null): EachExpectation
|
||||||
{
|
{
|
||||||
if (!is_iterable($this->value)) {
|
if (! is_iterable($this->value)) {
|
||||||
throw new BadMethodCallException('Expectation value is not iterable.');
|
throw new BadMethodCallException('Expectation value is not iterable.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,25 +157,24 @@ final class Expectation
|
|||||||
* @template TSequenceValue
|
* @template TSequenceValue
|
||||||
*
|
*
|
||||||
* @param (callable(self<TValue>, self<string|int>): void)|TSequenceValue ...$callbacks
|
* @param (callable(self<TValue>, self<string|int>): void)|TSequenceValue ...$callbacks
|
||||||
*
|
|
||||||
* @return self<TValue>
|
* @return self<TValue>
|
||||||
*/
|
*/
|
||||||
public function sequence(mixed ...$callbacks): Expectation
|
public function sequence(mixed ...$callbacks): Expectation
|
||||||
{
|
{
|
||||||
if (!is_iterable($this->value)) {
|
if (! is_iterable($this->value)) {
|
||||||
throw new BadMethodCallException('Expectation value is not iterable.');
|
throw new BadMethodCallException('Expectation value is not iterable.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = is_array($this->value) ? $this->value : iterator_to_array($this->value);
|
$value = is_array($this->value) ? $this->value : iterator_to_array($this->value);
|
||||||
$keys = array_keys($value);
|
$keys = array_keys($value);
|
||||||
$values = array_values($value);
|
$values = array_values($value);
|
||||||
$callbacksCount = count($callbacks);
|
$callbacksCount = count($callbacks);
|
||||||
|
|
||||||
$index = 0;
|
$index = 0;
|
||||||
|
|
||||||
while (count($callbacks) < count($values)) {
|
while (count($callbacks) < count($values)) {
|
||||||
$callbacks[] = $callbacks[$index];
|
$callbacks[] = $callbacks[$index];
|
||||||
$index = $index < count($values) - 1 ? $index + 1 : 0;
|
$index = $index < count($values) - 1 ? $index + 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($callbacksCount > count($values)) {
|
if ($callbacksCount > count($values)) {
|
||||||
@ -203,7 +201,6 @@ final class Expectation
|
|||||||
*
|
*
|
||||||
* @param (callable(): TMatchSubject)|TMatchSubject $subject
|
* @param (callable(): TMatchSubject)|TMatchSubject $subject
|
||||||
* @param array<TMatchSubject, (callable(self<TValue>): mixed)|TValue> $expressions
|
* @param array<TMatchSubject, (callable(self<TValue>): mixed)|TValue> $expressions
|
||||||
*
|
|
||||||
* @return self<TValue>
|
* @return self<TValue>
|
||||||
*/
|
*/
|
||||||
public function match(mixed $subject, array $expressions): Expectation
|
public function match(mixed $subject, array $expressions): Expectation
|
||||||
@ -241,8 +238,7 @@ final class Expectation
|
|||||||
* Apply the callback if the given "condition" is falsy.
|
* Apply the callback if the given "condition" is falsy.
|
||||||
*
|
*
|
||||||
* @param (callable(): bool)|bool $condition
|
* @param (callable(): bool)|bool $condition
|
||||||
* @param callable(Expectation<TValue>): mixed $callback
|
* @param callable(Expectation<TValue>): mixed $callback
|
||||||
*
|
|
||||||
* @return self<TValue>
|
* @return self<TValue>
|
||||||
*/
|
*/
|
||||||
public function unless(callable|bool $condition, callable $callback): Expectation
|
public function unless(callable|bool $condition, callable $callback): Expectation
|
||||||
@ -253,15 +249,14 @@ final class Expectation
|
|||||||
return $condition;
|
return $condition;
|
||||||
};
|
};
|
||||||
|
|
||||||
return $this->when(!$condition(), $callback);
|
return $this->when(! $condition(), $callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the callback if the given "condition" is truthy.
|
* Apply the callback if the given "condition" is truthy.
|
||||||
*
|
*
|
||||||
* @param (callable(): bool)|bool $condition
|
* @param (callable(): bool)|bool $condition
|
||||||
* @param callable(self<TValue>): mixed $callback
|
* @param callable(self<TValue>): mixed $callback
|
||||||
*
|
|
||||||
* @return self<TValue>
|
* @return self<TValue>
|
||||||
*/
|
*/
|
||||||
public function when(callable|bool $condition, callable $callback): Expectation
|
public function when(callable|bool $condition, callable $callback): Expectation
|
||||||
@ -282,13 +277,12 @@ final class Expectation
|
|||||||
/**
|
/**
|
||||||
* Dynamically calls methods on the class or creates a new higher order expectation.
|
* Dynamically calls methods on the class or creates a new higher order expectation.
|
||||||
*
|
*
|
||||||
* @param array<int, mixed> $parameters
|
* @param array<int, mixed> $parameters
|
||||||
*
|
|
||||||
* @return Expectation<TValue>|HigherOrderExpectation<Expectation<TValue>, TValue>
|
* @return Expectation<TValue>|HigherOrderExpectation<Expectation<TValue>, TValue>
|
||||||
*/
|
*/
|
||||||
public function __call(string $method, array $parameters): Expectation|HigherOrderExpectation
|
public function __call(string $method, array $parameters): Expectation|HigherOrderExpectation
|
||||||
{
|
{
|
||||||
if (!self::hasMethod($method)) {
|
if (! self::hasMethod($method)) {
|
||||||
/* @phpstan-ignore-next-line */
|
/* @phpstan-ignore-next-line */
|
||||||
return new HigherOrderExpectation($this, $this->value->$method(...$parameters));
|
return new HigherOrderExpectation($this, $this->value->$method(...$parameters));
|
||||||
}
|
}
|
||||||
@ -331,7 +325,7 @@ final class Expectation
|
|||||||
*/
|
*/
|
||||||
public function __get(string $name)
|
public function __get(string $name)
|
||||||
{
|
{
|
||||||
if (!self::hasMethod($name)) {
|
if (! self::hasMethod($name)) {
|
||||||
/* @phpstan-ignore-next-line */
|
/* @phpstan-ignore-next-line */
|
||||||
return new HigherOrderExpectation($this, $this->retrieve($name, $this->value));
|
return new HigherOrderExpectation($this, $this->retrieve($name, $this->value));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Expectations;
|
namespace Pest\Expectations;
|
||||||
|
|
||||||
use function expect;
|
use function expect;
|
||||||
|
|
||||||
use Pest\Expectation;
|
use Pest\Expectation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,7 +21,7 @@ final class EachExpectation
|
|||||||
/**
|
/**
|
||||||
* Creates an expectation on each item of the iterable "value".
|
* Creates an expectation on each item of the iterable "value".
|
||||||
*
|
*
|
||||||
* @param Expectation<TValue> $original
|
* @param Expectation<TValue> $original
|
||||||
*/
|
*/
|
||||||
public function __construct(private Expectation $original)
|
public function __construct(private Expectation $original)
|
||||||
{
|
{
|
||||||
@ -33,8 +32,7 @@ final class EachExpectation
|
|||||||
*
|
*
|
||||||
* @template TAndValue
|
* @template TAndValue
|
||||||
*
|
*
|
||||||
* @param TAndValue $value
|
* @param TAndValue $value
|
||||||
*
|
|
||||||
* @return Expectation<TAndValue>
|
* @return Expectation<TAndValue>
|
||||||
*/
|
*/
|
||||||
public function and(mixed $value): Expectation
|
public function and(mixed $value): Expectation
|
||||||
@ -57,8 +55,7 @@ final class EachExpectation
|
|||||||
/**
|
/**
|
||||||
* Dynamically calls methods on the class with the given arguments on each item.
|
* Dynamically calls methods on the class with the given arguments on each item.
|
||||||
*
|
*
|
||||||
* @param array<int|string, mixed> $arguments
|
* @param array<int|string, mixed> $arguments
|
||||||
*
|
|
||||||
* @return self<TValue>
|
* @return self<TValue>
|
||||||
*/
|
*/
|
||||||
public function __call(string $name, array $arguments): EachExpectation
|
public function __call(string $name, array $arguments): EachExpectation
|
||||||
|
|||||||
@ -32,8 +32,8 @@ final class HigherOrderExpectation
|
|||||||
/**
|
/**
|
||||||
* Creates a new higher order expectation.
|
* Creates a new higher order expectation.
|
||||||
*
|
*
|
||||||
* @param Expectation<TOriginalValue> $original
|
* @param Expectation<TOriginalValue> $original
|
||||||
* @param TValue $value
|
* @param TValue $value
|
||||||
*/
|
*/
|
||||||
public function __construct(private Expectation $original, mixed $value)
|
public function __construct(private Expectation $original, mixed $value)
|
||||||
{
|
{
|
||||||
@ -47,7 +47,7 @@ final class HigherOrderExpectation
|
|||||||
*/
|
*/
|
||||||
public function not(): HigherOrderExpectation
|
public function not(): HigherOrderExpectation
|
||||||
{
|
{
|
||||||
$this->opposite = !$this->opposite;
|
$this->opposite = ! $this->opposite;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -57,8 +57,7 @@ final class HigherOrderExpectation
|
|||||||
*
|
*
|
||||||
* @template TExpectValue
|
* @template TExpectValue
|
||||||
*
|
*
|
||||||
* @param TExpectValue $value
|
* @param TExpectValue $value
|
||||||
*
|
|
||||||
* @return Expectation<TExpectValue>
|
* @return Expectation<TExpectValue>
|
||||||
*/
|
*/
|
||||||
public function expect(mixed $value): Expectation
|
public function expect(mixed $value): Expectation
|
||||||
@ -71,8 +70,7 @@ final class HigherOrderExpectation
|
|||||||
*
|
*
|
||||||
* @template TExpectValue
|
* @template TExpectValue
|
||||||
*
|
*
|
||||||
* @param TExpectValue $value
|
* @param TExpectValue $value
|
||||||
*
|
|
||||||
* @return Expectation<TExpectValue>
|
* @return Expectation<TExpectValue>
|
||||||
*/
|
*/
|
||||||
public function and(mixed $value): Expectation
|
public function and(mixed $value): Expectation
|
||||||
@ -84,8 +82,7 @@ final class HigherOrderExpectation
|
|||||||
* Scope an expectation callback to the current value in
|
* Scope an expectation callback to the current value in
|
||||||
* the HigherOrderExpectation chain.
|
* the HigherOrderExpectation chain.
|
||||||
*
|
*
|
||||||
* @param Closure(Expectation<TValue>): void $expectation
|
* @param Closure(Expectation<TValue>): void $expectation
|
||||||
*
|
|
||||||
* @return HigherOrderExpectation<TOriginalValue, TOriginalValue>
|
* @return HigherOrderExpectation<TOriginalValue, TOriginalValue>
|
||||||
*/
|
*/
|
||||||
public function scoped(Closure $expectation): self
|
public function scoped(Closure $expectation): self
|
||||||
@ -108,13 +105,12 @@ final class HigherOrderExpectation
|
|||||||
/**
|
/**
|
||||||
* Dynamically calls methods on the class with the given arguments.
|
* Dynamically calls methods on the class with the given arguments.
|
||||||
*
|
*
|
||||||
* @param array<int, mixed> $arguments
|
* @param array<int, mixed> $arguments
|
||||||
*
|
|
||||||
* @return self<TOriginalValue, mixed>|self<TOriginalValue, TValue>
|
* @return self<TOriginalValue, mixed>|self<TOriginalValue, TValue>
|
||||||
*/
|
*/
|
||||||
public function __call(string $name, array $arguments): self
|
public function __call(string $name, array $arguments): self
|
||||||
{
|
{
|
||||||
if (!$this->expectationHasMethod($name)) {
|
if (! $this->expectationHasMethod($name)) {
|
||||||
/* @phpstan-ignore-next-line */
|
/* @phpstan-ignore-next-line */
|
||||||
return new self($this->original, $this->getValue()->$name(...$arguments));
|
return new self($this->original, $this->getValue()->$name(...$arguments));
|
||||||
}
|
}
|
||||||
@ -133,7 +129,7 @@ final class HigherOrderExpectation
|
|||||||
return $this->not();
|
return $this->not();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->expectationHasMethod($name)) {
|
if (! $this->expectationHasMethod($name)) {
|
||||||
/** @var array<string, mixed>|object $value */
|
/** @var array<string, mixed>|object $value */
|
||||||
$value = $this->getValue();
|
$value = $this->getValue();
|
||||||
|
|
||||||
@ -165,8 +161,7 @@ final class HigherOrderExpectation
|
|||||||
/**
|
/**
|
||||||
* Performs the given assertion with the current expectation.
|
* Performs the given assertion with the current expectation.
|
||||||
*
|
*
|
||||||
* @param array<int, mixed> $arguments
|
* @param array<int, mixed> $arguments
|
||||||
*
|
|
||||||
* @return self<TOriginalValue, TValue>
|
* @return self<TOriginalValue, TValue>
|
||||||
*/
|
*/
|
||||||
private function performAssertion(string $name, array $arguments): self
|
private function performAssertion(string $name, array $arguments): self
|
||||||
@ -174,7 +169,7 @@ final class HigherOrderExpectation
|
|||||||
/* @phpstan-ignore-next-line */
|
/* @phpstan-ignore-next-line */
|
||||||
$this->expectation = ($this->opposite ? $this->expectation->not() : $this->expectation)->{$name}(...$arguments);
|
$this->expectation = ($this->opposite ? $this->expectation->not() : $this->expectation)->{$name}(...$arguments);
|
||||||
|
|
||||||
$this->opposite = false;
|
$this->opposite = false;
|
||||||
$this->shouldReset = true;
|
$this->shouldReset = true;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
@ -21,7 +21,7 @@ final class OppositeExpectation
|
|||||||
/**
|
/**
|
||||||
* Creates a new opposite expectation.
|
* Creates a new opposite expectation.
|
||||||
*
|
*
|
||||||
* @param Expectation<TValue> $original
|
* @param Expectation<TValue> $original
|
||||||
*/
|
*/
|
||||||
public function __construct(private Expectation $original)
|
public function __construct(private Expectation $original)
|
||||||
{
|
{
|
||||||
@ -30,8 +30,7 @@ final class OppositeExpectation
|
|||||||
/**
|
/**
|
||||||
* Asserts that the value array not has the provided $keys.
|
* Asserts that the value array not has the provided $keys.
|
||||||
*
|
*
|
||||||
* @param array<int, int|string|array<int-string, mixed>> $keys
|
* @param array<int, int|string|array<int-string, mixed>> $keys
|
||||||
*
|
|
||||||
* @return Expectation<TValue>
|
* @return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function toHaveKeys(array $keys): Expectation
|
public function toHaveKeys(array $keys): Expectation
|
||||||
@ -39,7 +38,7 @@ final class OppositeExpectation
|
|||||||
foreach ($keys as $k => $key) {
|
foreach ($keys as $k => $key) {
|
||||||
try {
|
try {
|
||||||
if (is_array($key)) {
|
if (is_array($key)) {
|
||||||
$this->toHaveKeys(array_keys(Arr::dot($key, $k . '.')));
|
$this->toHaveKeys(array_keys(Arr::dot($key, $k.'.')));
|
||||||
} else {
|
} else {
|
||||||
$this->original->toHaveKey($key);
|
$this->original->toHaveKey($key);
|
||||||
}
|
}
|
||||||
@ -56,8 +55,7 @@ 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<TValue>|Expectation<mixed>|never
|
* @return Expectation<TValue>|Expectation<mixed>|never
|
||||||
*/
|
*/
|
||||||
public function __call(string $name, array $arguments): Expectation
|
public function __call(string $name, array $arguments): Expectation
|
||||||
@ -91,8 +89,7 @@ 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
|
* @return never
|
||||||
*/
|
*/
|
||||||
private function throwExpectationFailedException(string $name, array $arguments = []): void
|
private function throwExpectationFailedException(string $name, array $arguments = []): void
|
||||||
|
|||||||
@ -15,8 +15,7 @@ final class CoversNothing
|
|||||||
/**
|
/**
|
||||||
* Adds annotations regarding the "depends" feature.
|
* Adds annotations regarding the "depends" feature.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $annotations
|
* @param array<int, string> $annotations
|
||||||
*
|
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
||||||
|
|||||||
@ -15,8 +15,7 @@ final class Depends
|
|||||||
/**
|
/**
|
||||||
* Adds annotations regarding the "depends" feature.
|
* Adds annotations regarding the "depends" feature.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $annotations
|
* @param array<int, string> $annotations
|
||||||
*
|
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
||||||
|
|||||||
@ -14,8 +14,7 @@ final class Groups
|
|||||||
/**
|
/**
|
||||||
* Adds annotations regarding the "groups" feature.
|
* Adds annotations regarding the "groups" feature.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $annotations
|
* @param array<int, string> $annotations
|
||||||
*
|
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
||||||
|
|||||||
@ -19,8 +19,7 @@ abstract class Attribute
|
|||||||
public const ABOVE_CLASS = false;
|
public const ABOVE_CLASS = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<int, string> $attributes
|
* @param array<int, string> $attributes
|
||||||
*
|
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
public function __invoke(TestCaseMethodFactory $method, array $attributes): array // @phpstan-ignore-line
|
public function __invoke(TestCaseMethodFactory $method, array $attributes): array // @phpstan-ignore-line
|
||||||
|
|||||||
@ -23,8 +23,7 @@ final class Covers extends Attribute
|
|||||||
/**
|
/**
|
||||||
* Adds attributes regarding the "covers" feature.
|
* Adds attributes regarding the "covers" feature.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $attributes
|
* @param array<int, string> $attributes
|
||||||
*
|
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
public function __invoke(TestCaseMethodFactory $method, array $attributes): array
|
public function __invoke(TestCaseMethodFactory $method, array $attributes): array
|
||||||
@ -33,7 +32,7 @@ final class Covers extends Attribute
|
|||||||
if ($covering instanceof CoversClass) {
|
if ($covering instanceof CoversClass) {
|
||||||
// Prepend a backslash for FQN classes
|
// Prepend a backslash for FQN classes
|
||||||
if (str_contains($covering->class, '\\')) {
|
if (str_contains($covering->class, '\\')) {
|
||||||
$covering->class = '\\' . $covering->class;
|
$covering->class = '\\'.$covering->class;
|
||||||
}
|
}
|
||||||
|
|
||||||
$attributes[] = "#[\PHPUnit\Framework\Attributes\CoversClass({$covering->class}::class)]";
|
$attributes[] = "#[\PHPUnit\Framework\Attributes\CoversClass({$covering->class}::class)]";
|
||||||
|
|||||||
@ -28,8 +28,8 @@ trait HigherOrderable
|
|||||||
*/
|
*/
|
||||||
private function bootHigherOrderable(): void
|
private function bootHigherOrderable(): void
|
||||||
{
|
{
|
||||||
$this->chains = new HigherOrderMessageCollection();
|
$this->chains = new HigherOrderMessageCollection();
|
||||||
$this->factoryProxies = new HigherOrderMessageCollection();
|
$this->factoryProxies = new HigherOrderMessageCollection();
|
||||||
$this->proxies = new HigherOrderMessageCollection();
|
$this->proxies = new HigherOrderMessageCollection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -109,7 +109,7 @@ final class TestCaseFactory
|
|||||||
/**
|
/**
|
||||||
* Creates a Test Case class using a runtime evaluate.
|
* Creates a Test Case class using a runtime evaluate.
|
||||||
*
|
*
|
||||||
* @param array<int, TestCaseMethodFactory> $methods
|
* @param array<int, TestCaseMethodFactory> $methods
|
||||||
*/
|
*/
|
||||||
public function evaluate(string $filename, array $methods): void
|
public function evaluate(string $filename, array $methods): void
|
||||||
{
|
{
|
||||||
@ -118,9 +118,9 @@ final class TestCaseFactory
|
|||||||
$filename = (string) preg_replace_callback('~^(?P<drive>[a-z]+:\\\)~i', static fn ($match): string => strtolower($match['drive']), $filename);
|
$filename = (string) preg_replace_callback('~^(?P<drive>[a-z]+:\\\)~i', static fn ($match): string => strtolower($match['drive']), $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = str_replace('\\\\', '\\', addslashes((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);
|
||||||
|
|
||||||
$basename = basename($relativePath, '.php');
|
$basename = basename($relativePath, '.php');
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ final class TestCaseFactory
|
|||||||
$basename = substr($basename, 0, $dotPos);
|
$basename = substr($basename, 0, $dotPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
$relativePath = dirname(ucfirst($relativePath)) . DIRECTORY_SEPARATOR . $basename;
|
$relativePath = dirname(ucfirst($relativePath)).DIRECTORY_SEPARATOR.$basename;
|
||||||
|
|
||||||
$relativePath = str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath);
|
$relativePath = str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath);
|
||||||
|
|
||||||
@ -141,29 +141,29 @@ final class TestCaseFactory
|
|||||||
// 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)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$hasPrintableTestCaseClassFQN = sprintf('\%s', HasPrintableTestCaseName::class);
|
$hasPrintableTestCaseClassFQN = sprintf('\%s', HasPrintableTestCaseName::class);
|
||||||
$traitsCode = sprintf('use %s;', implode(', ', array_map(
|
$traitsCode = sprintf('use %s;', implode(', ', array_map(
|
||||||
static fn ($trait): string => sprintf('\%s', $trait), $this->traits))
|
static fn ($trait): string => sprintf('\%s', $trait), $this->traits))
|
||||||
);
|
);
|
||||||
|
|
||||||
$partsFQN = explode('\\', $classFQN);
|
$partsFQN = explode('\\', $classFQN);
|
||||||
$className = array_pop($partsFQN);
|
$className = array_pop($partsFQN);
|
||||||
$namespace = implode('\\', $partsFQN);
|
$namespace = implode('\\', $partsFQN);
|
||||||
$baseClass = sprintf('\%s', $this->class);
|
$baseClass = sprintf('\%s', $this->class);
|
||||||
|
|
||||||
if ('' === trim($className)) {
|
if ('' === trim($className)) {
|
||||||
$className = 'InvalidTestName' . Str::random();
|
$className = 'InvalidTestName'.Str::random();
|
||||||
$classFQN .= $className;
|
$classFQN .= $className;
|
||||||
}
|
}
|
||||||
|
|
||||||
$classAvailableAttributes = array_filter(self::$attributes, fn (string $attribute) => $attribute::ABOVE_CLASS);
|
$classAvailableAttributes = array_filter(self::$attributes, fn (string $attribute) => $attribute::ABOVE_CLASS);
|
||||||
$methodAvailableAttributes = array_filter(self::$attributes, fn (string $attribute) => !$attribute::ABOVE_CLASS);
|
$methodAvailableAttributes = array_filter(self::$attributes, fn (string $attribute) => ! $attribute::ABOVE_CLASS);
|
||||||
|
|
||||||
$classAttributes = [];
|
$classAttributes = [];
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ final class TestCaseFactory
|
|||||||
throw new TestAlreadyExist($method->filename, $method->description);
|
throw new TestAlreadyExist($method->filename, $method->description);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$method->receivesArguments()) {
|
if (! $method->receivesArguments()) {
|
||||||
if ($method->closure === null) {
|
if ($method->closure === null) {
|
||||||
throw ShouldNotHappen::fromMessage('The test closure may not be empty.');
|
throw ShouldNotHappen::fromMessage('The test closure may not be empty.');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,7 +90,7 @@ final class TestCaseMethodFactory
|
|||||||
$method = $this;
|
$method = $this;
|
||||||
|
|
||||||
return function () use ($testCase, $method, $closure): mixed { // @phpstan-ignore-line
|
return function () use ($testCase, $method, $closure): mixed { // @phpstan-ignore-line
|
||||||
/* @var TestCase $this */
|
/* @var TestCase $this */
|
||||||
$testCase->proxies->proxy($this);
|
$testCase->proxies->proxy($this);
|
||||||
$method->proxies->proxy($this);
|
$method->proxies->proxy($this);
|
||||||
|
|
||||||
@ -112,8 +112,8 @@ final class TestCaseMethodFactory
|
|||||||
/**
|
/**
|
||||||
* Creates a PHPUnit method as a string ready for evaluation.
|
* Creates a PHPUnit method as a string ready for evaluation.
|
||||||
*
|
*
|
||||||
* @param array<int, class-string> $annotationsToUse
|
* @param array<int, class-string> $annotationsToUse
|
||||||
* @param array<int, class-string<\Pest\Factories\Attributes\Attribute>> $attributesToUse
|
* @param array<int, class-string<\Pest\Factories\Attributes\Attribute>> $attributesToUse
|
||||||
*/
|
*/
|
||||||
public function buildForEvaluation(string $classFQN, array $annotationsToUse, array $attributesToUse): string
|
public function buildForEvaluation(string $classFQN, array $annotationsToUse, array $attributesToUse): string
|
||||||
{
|
{
|
||||||
@ -123,13 +123,13 @@ final class TestCaseMethodFactory
|
|||||||
|
|
||||||
$methodName = Str::evaluable($this->description);
|
$methodName = Str::evaluable($this->description);
|
||||||
|
|
||||||
if (Retry::$retrying && !TestSuite::getInstance()->retryTempRepository->exists(sprintf('%s::%s', $classFQN, $methodName))) {
|
if (Retry::$retrying && ! TestSuite::getInstance()->retryTempRepository->exists(sprintf('%s::%s', $classFQN, $methodName))) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$datasetsCode = '';
|
$datasetsCode = '';
|
||||||
$annotations = ['@test'];
|
$annotations = ['@test'];
|
||||||
$attributes = [];
|
$attributes = [];
|
||||||
|
|
||||||
foreach ($annotationsToUse as $annotation) {
|
foreach ($annotationsToUse as $annotation) {
|
||||||
/** @phpstan-ignore-next-line */
|
/** @phpstan-ignore-next-line */
|
||||||
@ -141,9 +141,9 @@ final class TestCaseMethodFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count($this->datasets) > 0) {
|
if (count($this->datasets) > 0) {
|
||||||
$dataProviderName = $methodName . '_dataset';
|
$dataProviderName = $methodName.'_dataset';
|
||||||
$annotations[] = "@dataProvider $dataProviderName";
|
$annotations[] = "@dataProvider $dataProviderName";
|
||||||
$datasetsCode = $this->buildDatasetForEvaluation($methodName, $dataProviderName);
|
$datasetsCode = $this->buildDatasetForEvaluation($methodName, $dataProviderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
$annotations = implode('', array_map(
|
$annotations = implode('', array_map(
|
||||||
|
|||||||
@ -13,14 +13,13 @@ use Pest\Support\HigherOrderTapProxy;
|
|||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
if (!function_exists('expect')) {
|
if (! function_exists('expect')) {
|
||||||
/**
|
/**
|
||||||
* Creates a new expectation.
|
* Creates a new expectation.
|
||||||
*
|
*
|
||||||
* @template TValue
|
* @template TValue
|
||||||
*
|
*
|
||||||
* @param TValue $value
|
* @param TValue $value
|
||||||
*
|
|
||||||
* @return Expectation<TValue>
|
* @return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
function expect(mixed $value = null): Expectation
|
function expect(mixed $value = null): Expectation
|
||||||
@ -29,7 +28,7 @@ if (!function_exists('expect')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('beforeAll')) {
|
if (! function_exists('beforeAll')) {
|
||||||
/**
|
/**
|
||||||
* Runs the given closure before all tests in the current file.
|
* Runs the given closure before all tests in the current file.
|
||||||
*/
|
*/
|
||||||
@ -39,7 +38,7 @@ if (!function_exists('beforeAll')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('beforeEach')) {
|
if (! function_exists('beforeEach')) {
|
||||||
/**
|
/**
|
||||||
* Runs the given closure before each test in the current file.
|
* Runs the given closure before each test in the current file.
|
||||||
*
|
*
|
||||||
@ -53,11 +52,11 @@ if (!function_exists('beforeEach')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('dataset')) {
|
if (! function_exists('dataset')) {
|
||||||
/**
|
/**
|
||||||
* Registers the given dataset.
|
* Registers the given dataset.
|
||||||
*
|
*
|
||||||
* @param Closure|iterable<int|string, mixed> $dataset
|
* @param Closure|iterable<int|string, mixed> $dataset
|
||||||
*/
|
*/
|
||||||
function dataset(string $name, Closure|iterable $dataset): void
|
function dataset(string $name, Closure|iterable $dataset): void
|
||||||
{
|
{
|
||||||
@ -65,12 +64,12 @@ if (!function_exists('dataset')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('uses')) {
|
if (! function_exists('uses')) {
|
||||||
/**
|
/**
|
||||||
* The uses function binds the given
|
* The uses function binds the given
|
||||||
* arguments to test closures.
|
* arguments to test closures.
|
||||||
*
|
*
|
||||||
* @param class-string ...$classAndTraits
|
* @param class-string ...$classAndTraits
|
||||||
*/
|
*/
|
||||||
function uses(string ...$classAndTraits): UsesCall
|
function uses(string ...$classAndTraits): UsesCall
|
||||||
{
|
{
|
||||||
@ -80,7 +79,7 @@ if (!function_exists('uses')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('test')) {
|
if (! function_exists('test')) {
|
||||||
/**
|
/**
|
||||||
* Adds the given closure as a test. The first argument
|
* Adds the given closure as a test. The first argument
|
||||||
* is the test description; the second argument is
|
* is the test description; the second argument is
|
||||||
@ -100,7 +99,7 @@ if (!function_exists('test')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('it')) {
|
if (! function_exists('it')) {
|
||||||
/**
|
/**
|
||||||
* Adds the given closure as a test. The first argument
|
* Adds the given closure as a test. The first argument
|
||||||
* is the test description; the second argument is
|
* is the test description; the second argument is
|
||||||
@ -119,7 +118,7 @@ if (!function_exists('it')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('todo')) {
|
if (! function_exists('todo')) {
|
||||||
/**
|
/**
|
||||||
* Adds the given todo test. Internally, this test
|
* Adds the given todo test. Internally, this test
|
||||||
* is marked as incomplete. Yet, Collision, Pest's
|
* is marked as incomplete. Yet, Collision, Pest's
|
||||||
@ -136,7 +135,7 @@ if (!function_exists('todo')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('afterEach')) {
|
if (! function_exists('afterEach')) {
|
||||||
/**
|
/**
|
||||||
* Runs the given closure after each test in the current file.
|
* Runs the given closure after each test in the current file.
|
||||||
*
|
*
|
||||||
@ -150,7 +149,7 @@ if (!function_exists('afterEach')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('afterAll')) {
|
if (! function_exists('afterAll')) {
|
||||||
/**
|
/**
|
||||||
* Runs the given closure after all tests in the current file.
|
* Runs the given closure after all tests in the current file.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -55,7 +55,7 @@ final class Kernel
|
|||||||
/**
|
/**
|
||||||
* Handles the given argv.
|
* Handles the given argv.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $argv
|
* @param array<int, string> $argv
|
||||||
*/
|
*/
|
||||||
public function handle(array $argv): int
|
public function handle(array $argv): int
|
||||||
{
|
{
|
||||||
@ -90,7 +90,7 @@ final class Kernel
|
|||||||
$returnCode = self::FAILURE_EXIT;
|
$returnCode = self::FAILURE_EXIT;
|
||||||
|
|
||||||
if ($result->wasSuccessfulIgnoringPhpunitWarnings()
|
if ($result->wasSuccessfulIgnoringPhpunitWarnings()
|
||||||
&& !$result->hasTestTriggeredPhpunitWarningEvents()) {
|
&& ! $result->hasTestTriggeredPhpunitWarningEvents()) {
|
||||||
$returnCode = self::SUCCESS_EXIT;
|
$returnCode = self::SUCCESS_EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,9 +8,7 @@ use Illuminate\Console\Command;
|
|||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Pest\Exceptions\InvalidConsoleArgument;
|
use Pest\Exceptions\InvalidConsoleArgument;
|
||||||
|
|
||||||
use function Pest\testDirectory;
|
use function Pest\testDirectory;
|
||||||
|
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,7 +51,7 @@ final class PestDatasetCommand extends Command
|
|||||||
throw new InvalidConsoleArgument(sprintf('%s already exist', $target));
|
throw new InvalidConsoleArgument(sprintf('%s already exist', $target));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!File::exists(dirname($relativePath))) {
|
if (! File::exists(dirname($relativePath))) {
|
||||||
File::makeDirectory(dirname($relativePath));
|
File::makeDirectory(dirname($relativePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,10 +61,10 @@ final class PestDatasetCommand extends Command
|
|||||||
'Dataset.php',
|
'Dataset.php',
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$name = mb_strtolower($name);
|
$name = mb_strtolower($name);
|
||||||
$contents = str_replace('{dataset_name}', $name, $contents);
|
$contents = str_replace('{dataset_name}', $name, $contents);
|
||||||
|
|
||||||
$element = Str::singular($name);
|
$element = Str::singular($name);
|
||||||
$contents = str_replace('{dataset_element}', $element, $contents);
|
$contents = str_replace('{dataset_element}', $element, $contents);
|
||||||
File::put($target, str_replace('{dataset_name}', $name, $contents));
|
File::put($target, str_replace('{dataset_name}', $name, $contents));
|
||||||
$message = sprintf('`%s` created successfully.', $relativePath);
|
$message = sprintf('`%s` created successfully.', $relativePath);
|
||||||
|
|||||||
@ -8,9 +8,7 @@ use Illuminate\Console\Command;
|
|||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Pest\Console\Thanks;
|
use Pest\Console\Thanks;
|
||||||
use Pest\Exceptions\InvalidConsoleArgument;
|
use Pest\Exceptions\InvalidConsoleArgument;
|
||||||
|
|
||||||
use function Pest\testDirectory;
|
use function Pest\testDirectory;
|
||||||
|
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,7 +39,7 @@ final class PestInstallCommand extends Command
|
|||||||
TestSuite::getInstance(base_path(), $this->option('test-directory'));
|
TestSuite::getInstance(base_path(), $this->option('test-directory'));
|
||||||
|
|
||||||
/* @phpstan-ignore-next-line */
|
/* @phpstan-ignore-next-line */
|
||||||
$pest = base_path(testDirectory('Pest.php'));
|
$pest = base_path(testDirectory('Pest.php'));
|
||||||
$stubs = 'stubs/Laravel';
|
$stubs = 'stubs/Laravel';
|
||||||
|
|
||||||
if (File::exists($pest)) {
|
if (File::exists($pest)) {
|
||||||
@ -56,7 +54,7 @@ final class PestInstallCommand extends Command
|
|||||||
|
|
||||||
$this->output->success('`tests/Pest.php` created successfully.');
|
$this->output->success('`tests/Pest.php` created successfully.');
|
||||||
|
|
||||||
if (!(bool) $this->option('no-interaction')) {
|
if (! (bool) $this->option('no-interaction')) {
|
||||||
(new Thanks($this->output))();
|
(new Thanks($this->output))();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,9 +8,7 @@ use Illuminate\Console\Command;
|
|||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Pest\Exceptions\InvalidConsoleArgument;
|
use Pest\Exceptions\InvalidConsoleArgument;
|
||||||
use Pest\Support\Str;
|
use Pest\Support\Str;
|
||||||
|
|
||||||
use function Pest\testDirectory;
|
use function Pest\testDirectory;
|
||||||
|
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,11 +52,11 @@ final class PestTestCommand extends Command
|
|||||||
/* @phpstan-ignore-next-line */
|
/* @phpstan-ignore-next-line */
|
||||||
$target = base_path($relativePath);
|
$target = base_path($relativePath);
|
||||||
|
|
||||||
if (!File::isDirectory(dirname($target))) {
|
if (! File::isDirectory(dirname($target))) {
|
||||||
File::makeDirectory(dirname($target), 0777, true, true);
|
File::makeDirectory(dirname($target), 0777, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (File::exists($target) && !(bool) $this->option('force')) {
|
if (File::exists($target) && ! (bool) $this->option('force')) {
|
||||||
throw new InvalidConsoleArgument(sprintf('%s already exist', $target));
|
throw new InvalidConsoleArgument(sprintf('%s already exist', $target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,7 @@ final class Expectation
|
|||||||
/**
|
/**
|
||||||
* Creates a new expectation.
|
* Creates a new expectation.
|
||||||
*
|
*
|
||||||
* @param TValue $value
|
* @param TValue $value
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public mixed $value
|
public mixed $value
|
||||||
@ -180,7 +180,7 @@ final class Expectation
|
|||||||
// @phpstan-ignore-next-line
|
// @phpstan-ignore-next-line
|
||||||
Assert::assertStringContainsString((string) $needle, $this->value);
|
Assert::assertStringContainsString((string) $needle, $this->value);
|
||||||
} else {
|
} else {
|
||||||
if (!is_iterable($this->value)) {
|
if (! is_iterable($this->value)) {
|
||||||
InvalidExpectationValue::expected('iterable');
|
InvalidExpectationValue::expected('iterable');
|
||||||
}
|
}
|
||||||
Assert::assertContains($needle, $this->value);
|
Assert::assertContains($needle, $this->value);
|
||||||
@ -193,13 +193,12 @@ final class Expectation
|
|||||||
/**
|
/**
|
||||||
* Asserts that the value starts with $expected.
|
* Asserts that the value starts with $expected.
|
||||||
*
|
*
|
||||||
* @param non-empty-string $expected
|
* @param non-empty-string $expected
|
||||||
*
|
|
||||||
*@return Expectation<TValue>
|
*@return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function toStartWith(string $expected): Expectation
|
public function toStartWith(string $expected): Expectation
|
||||||
{
|
{
|
||||||
if (!is_string($this->value)) {
|
if (! is_string($this->value)) {
|
||||||
InvalidExpectationValue::expected('string');
|
InvalidExpectationValue::expected('string');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,13 +210,12 @@ final class Expectation
|
|||||||
/**
|
/**
|
||||||
* Asserts that the value ends with $expected.
|
* Asserts that the value ends with $expected.
|
||||||
*
|
*
|
||||||
* @param non-empty-string $expected
|
* @param non-empty-string $expected
|
||||||
*
|
|
||||||
*@return Expectation<TValue>
|
*@return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function toEndWith(string $expected): Expectation
|
public function toEndWith(string $expected): Expectation
|
||||||
{
|
{
|
||||||
if (!is_string($this->value)) {
|
if (! is_string($this->value)) {
|
||||||
InvalidExpectationValue::expected('string');
|
InvalidExpectationValue::expected('string');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,7 +263,7 @@ final class Expectation
|
|||||||
*/
|
*/
|
||||||
public function toHaveCount(int $count): Expectation
|
public function toHaveCount(int $count): Expectation
|
||||||
{
|
{
|
||||||
if (!is_countable($this->value) && !is_iterable($this->value)) {
|
if (! is_countable($this->value) && ! is_iterable($this->value)) {
|
||||||
InvalidExpectationValue::expected('string');
|
InvalidExpectationValue::expected('string');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,8 +295,7 @@ final class Expectation
|
|||||||
/**
|
/**
|
||||||
* Asserts that the value contains the provided properties $names.
|
* Asserts that the value contains the provided properties $names.
|
||||||
*
|
*
|
||||||
* @param iterable<array-key, string> $names
|
* @param iterable<array-key, string> $names
|
||||||
*
|
|
||||||
*@return Expectation<TValue>
|
*@return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function toHaveProperties(iterable $names): Expectation
|
public function toHaveProperties(iterable $names): Expectation
|
||||||
@ -356,8 +353,7 @@ final class Expectation
|
|||||||
/**
|
/**
|
||||||
* Asserts that the value is one of the given values.
|
* Asserts that the value is one of the given values.
|
||||||
*
|
*
|
||||||
* @param iterable<int|string, mixed> $values
|
* @param iterable<int|string, mixed> $values
|
||||||
*
|
|
||||||
* @return Expectation<TValue>
|
* @return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function toBeIn(iterable $values): Expectation
|
public function toBeIn(iterable $values): Expectation
|
||||||
@ -382,8 +378,7 @@ final class Expectation
|
|||||||
/**
|
/**
|
||||||
* Asserts that the value is an instance of $class.
|
* Asserts that the value is an instance of $class.
|
||||||
*
|
*
|
||||||
* @param class-string $class
|
* @param class-string $class
|
||||||
*
|
|
||||||
* @return Expectation<TValue>
|
* @return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function toBeInstanceOf(string $class): Expectation
|
public function toBeInstanceOf(string $class): Expectation
|
||||||
@ -595,15 +590,14 @@ final class Expectation
|
|||||||
/**
|
/**
|
||||||
* Asserts that the value array has the provided $keys.
|
* Asserts that the value array has the provided $keys.
|
||||||
*
|
*
|
||||||
* @param array<int, int|string|array<int-string, mixed>> $keys
|
* @param array<int, int|string|array<int-string, mixed>> $keys
|
||||||
*
|
|
||||||
* @return Expectation<TValue>
|
* @return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function toHaveKeys(array $keys): Expectation
|
public function toHaveKeys(array $keys): Expectation
|
||||||
{
|
{
|
||||||
foreach ($keys as $k => $key) {
|
foreach ($keys as $k => $key) {
|
||||||
if (is_array($key)) {
|
if (is_array($key)) {
|
||||||
$this->toHaveKeys(array_keys(Arr::dot($key, $k . '.')));
|
$this->toHaveKeys(array_keys(Arr::dot($key, $k.'.')));
|
||||||
} else {
|
} else {
|
||||||
$this->toHaveKey($key);
|
$this->toHaveKey($key);
|
||||||
}
|
}
|
||||||
@ -619,7 +613,7 @@ final class Expectation
|
|||||||
*/
|
*/
|
||||||
public function toBeDirectory(): Expectation
|
public function toBeDirectory(): Expectation
|
||||||
{
|
{
|
||||||
if (!is_string($this->value)) {
|
if (! is_string($this->value)) {
|
||||||
InvalidExpectationValue::expected('string');
|
InvalidExpectationValue::expected('string');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,7 +629,7 @@ final class Expectation
|
|||||||
*/
|
*/
|
||||||
public function toBeReadableDirectory(): Expectation
|
public function toBeReadableDirectory(): Expectation
|
||||||
{
|
{
|
||||||
if (!is_string($this->value)) {
|
if (! is_string($this->value)) {
|
||||||
InvalidExpectationValue::expected('string');
|
InvalidExpectationValue::expected('string');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -651,7 +645,7 @@ final class Expectation
|
|||||||
*/
|
*/
|
||||||
public function toBeWritableDirectory(): Expectation
|
public function toBeWritableDirectory(): Expectation
|
||||||
{
|
{
|
||||||
if (!is_string($this->value)) {
|
if (! is_string($this->value)) {
|
||||||
InvalidExpectationValue::expected('string');
|
InvalidExpectationValue::expected('string');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -667,7 +661,7 @@ final class Expectation
|
|||||||
*/
|
*/
|
||||||
public function toBeFile(): Expectation
|
public function toBeFile(): Expectation
|
||||||
{
|
{
|
||||||
if (!is_string($this->value)) {
|
if (! is_string($this->value)) {
|
||||||
InvalidExpectationValue::expected('string');
|
InvalidExpectationValue::expected('string');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -683,7 +677,7 @@ final class Expectation
|
|||||||
*/
|
*/
|
||||||
public function toBeReadableFile(): Expectation
|
public function toBeReadableFile(): Expectation
|
||||||
{
|
{
|
||||||
if (!is_string($this->value)) {
|
if (! is_string($this->value)) {
|
||||||
InvalidExpectationValue::expected('string');
|
InvalidExpectationValue::expected('string');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -699,7 +693,7 @@ final class Expectation
|
|||||||
*/
|
*/
|
||||||
public function toBeWritableFile(): Expectation
|
public function toBeWritableFile(): Expectation
|
||||||
{
|
{
|
||||||
if (!is_string($this->value)) {
|
if (! is_string($this->value)) {
|
||||||
InvalidExpectationValue::expected('string');
|
InvalidExpectationValue::expected('string');
|
||||||
}
|
}
|
||||||
Assert::assertFileIsWritable($this->value);
|
Assert::assertFileIsWritable($this->value);
|
||||||
@ -710,8 +704,7 @@ final class Expectation
|
|||||||
/**
|
/**
|
||||||
* Asserts that the value array matches the given array subset.
|
* Asserts that the value array matches the given array subset.
|
||||||
*
|
*
|
||||||
* @param iterable<int|string, mixed> $array
|
* @param iterable<int|string, mixed> $array
|
||||||
*
|
|
||||||
* @return Expectation<TValue>
|
* @return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function toMatchArray(iterable $array): Expectation
|
public function toMatchArray(iterable $array): Expectation
|
||||||
@ -743,14 +736,13 @@ final class Expectation
|
|||||||
* Asserts that the value object matches a subset
|
* Asserts that the value object matches a subset
|
||||||
* of the properties of an given object.
|
* of the properties of an given object.
|
||||||
*
|
*
|
||||||
* @param iterable<string, mixed> $object
|
* @param iterable<string, mixed> $object
|
||||||
*
|
|
||||||
* @return Expectation<TValue>
|
* @return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function toMatchObject(iterable $object): Expectation
|
public function toMatchObject(iterable $object): Expectation
|
||||||
{
|
{
|
||||||
foreach ((array) $object as $property => $value) {
|
foreach ((array) $object as $property => $value) {
|
||||||
if (!is_object($this->value) && !is_string($this->value)) {
|
if (! is_object($this->value) && ! is_string($this->value)) {
|
||||||
InvalidExpectationValue::expected('object|string');
|
InvalidExpectationValue::expected('object|string');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -779,7 +771,7 @@ final class Expectation
|
|||||||
*/
|
*/
|
||||||
public function toMatch(string $expression): Expectation
|
public function toMatch(string $expression): Expectation
|
||||||
{
|
{
|
||||||
if (!is_string($this->value)) {
|
if (! is_string($this->value)) {
|
||||||
InvalidExpectationValue::expected('string');
|
InvalidExpectationValue::expected('string');
|
||||||
}
|
}
|
||||||
Assert::assertMatchesRegularExpression($expression, $this->value);
|
Assert::assertMatchesRegularExpression($expression, $this->value);
|
||||||
@ -800,13 +792,12 @@ final class Expectation
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param class-string $class
|
* @param class-string $class
|
||||||
*
|
|
||||||
* @return Expectation<TValue>
|
* @return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function toContainOnlyInstancesOf(string $class): Expectation
|
public function toContainOnlyInstancesOf(string $class): Expectation
|
||||||
{
|
{
|
||||||
if (!is_iterable($this->value)) {
|
if (! is_iterable($this->value)) {
|
||||||
InvalidExpectationValue::expected('iterable');
|
InvalidExpectationValue::expected('iterable');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -819,7 +810,6 @@ final class Expectation
|
|||||||
* Asserts that executing value throws an exception.
|
* Asserts that executing value throws an exception.
|
||||||
*
|
*
|
||||||
* @param (Closure(Throwable): mixed)|string $exception
|
* @param (Closure(Throwable): mixed)|string $exception
|
||||||
*
|
|
||||||
* @return Expectation<TValue>
|
* @return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function toThrow(callable|string $exception, string $exceptionMessage = null): Expectation
|
public function toThrow(callable|string $exception, string $exceptionMessage = null): Expectation
|
||||||
@ -827,14 +817,14 @@ final class Expectation
|
|||||||
$callback = NullClosure::create();
|
$callback = NullClosure::create();
|
||||||
|
|
||||||
if ($exception instanceof Closure) {
|
if ($exception instanceof Closure) {
|
||||||
$callback = $exception;
|
$callback = $exception;
|
||||||
$parameters = (new ReflectionFunction($exception))->getParameters();
|
$parameters = (new ReflectionFunction($exception))->getParameters();
|
||||||
|
|
||||||
if (1 !== count($parameters)) {
|
if (1 !== count($parameters)) {
|
||||||
throw new InvalidArgumentException('The given closure must have a single parameter type-hinted as the class string.');
|
throw new InvalidArgumentException('The given closure must have a single parameter type-hinted as the class string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!($type = $parameters[0]->getType()) instanceof ReflectionNamedType) {
|
if (! ($type = $parameters[0]->getType()) instanceof ReflectionNamedType) {
|
||||||
throw new InvalidArgumentException('The given closure\'s parameter must be type-hinted as the class string.');
|
throw new InvalidArgumentException('The given closure\'s parameter must be type-hinted as the class string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -844,7 +834,7 @@ final class Expectation
|
|||||||
try {
|
try {
|
||||||
($this->value)();
|
($this->value)();
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
if (!class_exists($exception)) {
|
if (! class_exists($exception)) {
|
||||||
if ($e instanceof Error && $e->getMessage() === "Class \"$exception\" not found") {
|
if ($e instanceof Error && $e->getMessage() === "Class \"$exception\" not found") {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
@ -864,7 +854,7 @@ final class Expectation
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!class_exists($exception)) {
|
if (! class_exists($exception)) {
|
||||||
throw new ExpectationFailedException("Exception with message \"$exception\" not thrown.");
|
throw new ExpectationFailedException("Exception with message \"$exception\" not thrown.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -57,7 +57,7 @@ final class AfterEachCall
|
|||||||
/**
|
/**
|
||||||
* Saves the calls to be used on the target.
|
* Saves the calls to be used on the target.
|
||||||
*
|
*
|
||||||
* @param array<int, mixed> $arguments
|
* @param array<int, mixed> $arguments
|
||||||
*/
|
*/
|
||||||
public function __call(string $name, array $arguments): self
|
public function __call(string $name, array $arguments): self
|
||||||
{
|
{
|
||||||
|
|||||||
@ -57,7 +57,7 @@ final class BeforeEachCall
|
|||||||
/**
|
/**
|
||||||
* Saves the calls to be used on the target.
|
* Saves the calls to be used on the target.
|
||||||
*
|
*
|
||||||
* @param array<int, mixed> $arguments
|
* @param array<int, mixed> $arguments
|
||||||
*/
|
*/
|
||||||
public function __call(string $name, array $arguments): self
|
public function __call(string $name, array $arguments): self
|
||||||
{
|
{
|
||||||
|
|||||||
@ -42,7 +42,7 @@ final class TestCall
|
|||||||
string $description = null,
|
string $description = null,
|
||||||
Closure $closure = null
|
Closure $closure = null
|
||||||
) {
|
) {
|
||||||
$this->testCaseMethod = new TestCaseMethodFactory($filename, $description, $closure);
|
$this->testCaseMethod = new TestCaseMethodFactory($filename, $description, $closure);
|
||||||
$this->descriptionLess = $description === null;
|
$this->descriptionLess = $description === null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ final class TestCall
|
|||||||
* Runs the current test multiple times with
|
* Runs the current test multiple times with
|
||||||
* each item of the given `iterable`.
|
* 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(Closure|iterable|string ...$data): TestCall
|
public function with(Closure|iterable|string ...$data): TestCall
|
||||||
{
|
{
|
||||||
@ -178,10 +178,10 @@ final class TestCall
|
|||||||
public function covers(string ...$classesOrFunctions): TestCall
|
public function covers(string ...$classesOrFunctions): TestCall
|
||||||
{
|
{
|
||||||
foreach ($classesOrFunctions as $classOrFunction) {
|
foreach ($classesOrFunctions as $classOrFunction) {
|
||||||
$isClass = class_exists($classOrFunction);
|
$isClass = class_exists($classOrFunction);
|
||||||
$isMethod = function_exists($classOrFunction);
|
$isMethod = function_exists($classOrFunction);
|
||||||
|
|
||||||
if (!$isClass && !$isMethod) {
|
if (! $isClass && ! $isMethod) {
|
||||||
throw new InvalidArgumentException(sprintf('No class or method named "%s" has been found.', $classOrFunction));
|
throw new InvalidArgumentException(sprintf('No class or method named "%s" has been found.', $classOrFunction));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +252,7 @@ final class TestCall
|
|||||||
/**
|
/**
|
||||||
* Saves the calls to be used on the target.
|
* Saves the calls to be used on the target.
|
||||||
*
|
*
|
||||||
* @param array<int, mixed> $arguments
|
* @param array<int, mixed> $arguments
|
||||||
*/
|
*/
|
||||||
public function __call(string $name, array $arguments): self
|
public function __call(string $name, array $arguments): self
|
||||||
{
|
{
|
||||||
@ -262,7 +262,7 @@ final class TestCall
|
|||||||
/**
|
/**
|
||||||
* Add a chain to the test case factory. Omitting the arguments will treat it as a property accessor.
|
* Add a chain to the test case factory. Omitting the arguments will treat it as a property accessor.
|
||||||
*
|
*
|
||||||
* @param array<int, mixed>|null $arguments
|
* @param array<int, mixed>|null $arguments
|
||||||
*/
|
*/
|
||||||
private function addChain(string $file, int $line, string $name, array $arguments = null): self
|
private function addChain(string $file, int $line, string $name, array $arguments = null): self
|
||||||
{
|
{
|
||||||
|
|||||||
@ -43,7 +43,7 @@ final class UsesCall
|
|||||||
/**
|
/**
|
||||||
* Creates a new Pending Call.
|
* Creates a new Pending Call.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $classAndTraits
|
* @param array<int, string> $classAndTraits
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private string $filename,
|
private string $filename,
|
||||||
@ -58,7 +58,7 @@ final class UsesCall
|
|||||||
*/
|
*/
|
||||||
public function in(string ...$targets): void
|
public function in(string ...$targets): void
|
||||||
{
|
{
|
||||||
$targets = array_map(function ($path): string {
|
$targets = array_map(function ($path): string {
|
||||||
$startChar = DIRECTORY_SEPARATOR;
|
$startChar = DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
if ('\\' === DIRECTORY_SEPARATOR || preg_match('~\A[A-Z]:(?![^/\\\\])~i', $path) > 0) {
|
if ('\\' === DIRECTORY_SEPARATOR || preg_match('~\A[A-Z]:(?![^/\\\\])~i', $path) > 0) {
|
||||||
|
|||||||
@ -11,5 +11,5 @@ function version(): string
|
|||||||
|
|
||||||
function testDirectory(string $file = ''): string
|
function testDirectory(string $file = ''): string
|
||||||
{
|
{
|
||||||
return TestSuite::getInstance()->testPath . '/' . $file;
|
return TestSuite::getInstance()->testPath.'/'.$file;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,12 +18,12 @@ final class Plugin
|
|||||||
/**
|
/**
|
||||||
* Lazy loads an `uses` call on the context of plugins.
|
* Lazy loads an `uses` call on the context of plugins.
|
||||||
*
|
*
|
||||||
* @param class-string ...$traits
|
* @param class-string ...$traits
|
||||||
*/
|
*/
|
||||||
public static function uses(string ...$traits): void
|
public static function uses(string ...$traits): void
|
||||||
{
|
{
|
||||||
self::$callables[] = function () use ($traits): void {
|
self::$callables[] = function () use ($traits): void {
|
||||||
uses(...$traits)->in(TestSuite::getInstance()->rootPath . DIRECTORY_SEPARATOR . testDirectory());
|
uses(...$traits)->in(TestSuite::getInstance()->rootPath.DIRECTORY_SEPARATOR.testDirectory());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,8 +17,7 @@ final class HandleArguments
|
|||||||
*
|
*
|
||||||
* Transform the input arguments by passing it to the relevant plugins.
|
* Transform the input arguments by passing it to the relevant plugins.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $argv
|
* @param array<int, string> $argv
|
||||||
*
|
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
public function __invoke(array $argv): array
|
public function __invoke(array $argv): array
|
||||||
|
|||||||
@ -12,7 +12,7 @@ trait HandleArguments
|
|||||||
/**
|
/**
|
||||||
* Checks if the given argument exists on the arguments.
|
* Checks if the given argument exists on the arguments.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $arguments
|
* @param array<int, string> $arguments
|
||||||
*/
|
*/
|
||||||
public function hasArgument(string $argument, array $arguments): bool
|
public function hasArgument(string $argument, array $arguments): bool
|
||||||
{
|
{
|
||||||
@ -22,8 +22,7 @@ trait HandleArguments
|
|||||||
/**
|
/**
|
||||||
* Adds the given argument and value to the list of arguments.
|
* Adds the given argument and value to the list of arguments.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $arguments
|
* @param array<int, string> $arguments
|
||||||
*
|
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
public function pushArgument(string $argument, array $arguments): array
|
public function pushArgument(string $argument, array $arguments): array
|
||||||
@ -36,8 +35,7 @@ trait HandleArguments
|
|||||||
/**
|
/**
|
||||||
* Pops the given argument from the arguments.
|
* Pops the given argument from the arguments.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $arguments
|
* @param array<int, string> $arguments
|
||||||
*
|
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
public function popArgument(string $argument, array $arguments): array
|
public function popArgument(string $argument, array $arguments): array
|
||||||
|
|||||||
@ -66,15 +66,15 @@ final class Coverage implements AddsOutput, HandlesArguments
|
|||||||
}
|
}
|
||||||
$originals = array_flip($originals);
|
$originals = array_flip($originals);
|
||||||
|
|
||||||
$inputs = [];
|
$inputs = [];
|
||||||
$inputs[] = new InputOption(self::COVERAGE_OPTION, null, InputOption::VALUE_NONE);
|
$inputs[] = new InputOption(self::COVERAGE_OPTION, null, InputOption::VALUE_NONE);
|
||||||
$inputs[] = new InputOption(self::MIN_OPTION, null, InputOption::VALUE_REQUIRED);
|
$inputs[] = new InputOption(self::MIN_OPTION, null, InputOption::VALUE_REQUIRED);
|
||||||
|
|
||||||
$input = new ArgvInput($arguments, new InputDefinition($inputs));
|
$input = new ArgvInput($arguments, new InputDefinition($inputs));
|
||||||
if ((bool) $input->getOption(self::COVERAGE_OPTION)) {
|
if ((bool) $input->getOption(self::COVERAGE_OPTION)) {
|
||||||
$this->coverage = true;
|
$this->coverage = true;
|
||||||
$originals[] = '--coverage-php';
|
$originals[] = '--coverage-php';
|
||||||
$originals[] = \Pest\Support\Coverage::getPath();
|
$originals[] = \Pest\Support\Coverage::getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($input->getOption(self::MIN_OPTION) !== null) {
|
if ($input->getOption(self::MIN_OPTION) !== null) {
|
||||||
@ -93,7 +93,7 @@ final class Coverage implements AddsOutput, HandlesArguments
|
|||||||
public function addOutput(int $exitCode): int
|
public function addOutput(int $exitCode): int
|
||||||
{
|
{
|
||||||
if ($exitCode === 0 && $this->coverage) {
|
if ($exitCode === 0 && $this->coverage) {
|
||||||
if (!\Pest\Support\Coverage::isAvailable()) {
|
if (! \Pest\Support\Coverage::isAvailable()) {
|
||||||
$this->output->writeln(
|
$this->output->writeln(
|
||||||
"\n <fg=white;bg=red;options=bold> ERROR </> No code coverage driver is available.</>",
|
"\n <fg=white;bg=red;options=bold> ERROR </> No code coverage driver is available.</>",
|
||||||
);
|
);
|
||||||
|
|||||||
@ -23,8 +23,8 @@ final class Init implements HandlesArguments
|
|||||||
* The files that will be created.
|
* The files that will be created.
|
||||||
*/
|
*/
|
||||||
private const STUBS = [
|
private const STUBS = [
|
||||||
'phpunit.xml' => 'phpunit.xml',
|
'phpunit.xml' => 'phpunit.xml',
|
||||||
'Pest.php' => 'tests/Pest.php',
|
'Pest.php' => 'tests/Pest.php',
|
||||||
'ExampleTest.php' => 'tests/ExampleTest.php',
|
'ExampleTest.php' => 'tests/ExampleTest.php',
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ final class Init implements HandlesArguments
|
|||||||
*/
|
*/
|
||||||
public function handleArguments(array $arguments): array
|
public function handleArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
if (!array_key_exists(1, $arguments) || $arguments[1] !== self::INIT_OPTION) {
|
if (! array_key_exists(1, $arguments) || $arguments[1] !== self::INIT_OPTION) {
|
||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,8 +58,8 @@ final class Init implements HandlesArguments
|
|||||||
{
|
{
|
||||||
$testsBaseDir = "{$this->testSuite->rootPath}/tests";
|
$testsBaseDir = "{$this->testSuite->rootPath}/tests";
|
||||||
|
|
||||||
if (!is_dir($testsBaseDir)) {
|
if (! is_dir($testsBaseDir)) {
|
||||||
if (!mkdir($testsBaseDir) && !is_dir($testsBaseDir)) {
|
if (! mkdir($testsBaseDir) && ! is_dir($testsBaseDir)) {
|
||||||
$this->output->writeln(sprintf(
|
$this->output->writeln(sprintf(
|
||||||
"\n <fg=white;bg=red;options=bold> ERROR </> Directory `%s` was not created.</>",
|
"\n <fg=white;bg=red;options=bold> ERROR </> Directory `%s` was not created.</>",
|
||||||
$testsBaseDir
|
$testsBaseDir
|
||||||
@ -74,8 +74,8 @@ final class Init implements HandlesArguments
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (self::STUBS as $from => $to) {
|
foreach (self::STUBS as $from => $to) {
|
||||||
$fromPath = __DIR__ . "/../../stubs/init/{$from}";
|
$fromPath = __DIR__."/../../stubs/init/{$from}";
|
||||||
$toPath = "{$this->testSuite->rootPath}/{$to}";
|
$toPath = "{$this->testSuite->rootPath}/{$to}";
|
||||||
|
|
||||||
if (file_exists($toPath)) {
|
if (file_exists($toPath)) {
|
||||||
$this->output->writeln(sprintf(
|
$this->output->writeln(sprintf(
|
||||||
@ -86,16 +86,16 @@ final class Init implements HandlesArguments
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($from === 'phpunit.xml' && file_exists($toPath . '.dist')) {
|
if ($from === 'phpunit.xml' && file_exists($toPath.'.dist')) {
|
||||||
$this->output->writeln(sprintf(
|
$this->output->writeln(sprintf(
|
||||||
' <fg=black;bg=yellow;options=bold> INFO </> File `%s` already exists, skipped.</>',
|
' <fg=black;bg=yellow;options=bold> INFO </> File `%s` already exists, skipped.</>',
|
||||||
$to . '.dist'
|
$to.'.dist'
|
||||||
));
|
));
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!copy($fromPath, $toPath)) {
|
if (! copy($fromPath, $toPath)) {
|
||||||
$this->output->writeln(sprintf(
|
$this->output->writeln(sprintf(
|
||||||
'<fg=black;bg=red>[WARNING] Failed to copy stub `%s` to `%s`</>',
|
'<fg=black;bg=red>[WARNING] Failed to copy stub `%s` to `%s`</>',
|
||||||
$from,
|
$from,
|
||||||
|
|||||||
@ -18,7 +18,7 @@ final class Printer implements HandlesArguments
|
|||||||
*/
|
*/
|
||||||
public function handleArguments(array $arguments): array
|
public function handleArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
if (!array_key_exists('COLLISION_PRINTER', $_SERVER)) {
|
if (! array_key_exists('COLLISION_PRINTER', $_SERVER)) {
|
||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Plugins;
|
namespace Pest\Plugins;
|
||||||
|
|
||||||
use Pest\Contracts\Plugins\HandlesArguments;
|
use Pest\Contracts\Plugins\HandlesArguments;
|
||||||
|
|
||||||
use function Pest\version;
|
use function Pest\version;
|
||||||
|
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -9,9 +9,7 @@ use Pest\Exceptions\DatasetAlreadyExist;
|
|||||||
use Pest\Exceptions\DatasetDoesNotExist;
|
use Pest\Exceptions\DatasetDoesNotExist;
|
||||||
use Pest\Exceptions\ShouldNotHappen;
|
use Pest\Exceptions\ShouldNotHappen;
|
||||||
use SebastianBergmann\Exporter\Exporter;
|
use SebastianBergmann\Exporter\Exporter;
|
||||||
|
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
|
||||||
use Traversable;
|
use Traversable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,7 +34,7 @@ final class DatasetsRepository
|
|||||||
/**
|
/**
|
||||||
* Sets the given.
|
* Sets the given.
|
||||||
*
|
*
|
||||||
* @param Closure|iterable<int|string, mixed> $data
|
* @param Closure|iterable<int|string, mixed> $data
|
||||||
*/
|
*/
|
||||||
public static function set(string $name, Closure|iterable $data): void
|
public static function set(string $name, Closure|iterable $data): void
|
||||||
{
|
{
|
||||||
@ -50,16 +48,16 @@ final class DatasetsRepository
|
|||||||
/**
|
/**
|
||||||
* Sets the given "with".
|
* Sets the given "with".
|
||||||
*
|
*
|
||||||
* @param array<Closure|iterable<int|string, mixed>|string> $with
|
* @param array<Closure|iterable<int|string, mixed>|string> $with
|
||||||
*/
|
*/
|
||||||
public static function with(string $filename, string $description, array $with): void
|
public static function with(string $filename, string $description, array $with): void
|
||||||
{
|
{
|
||||||
self::$withs[$filename . '>>>' . $description] = $with;
|
self::$withs[$filename.'>>>'.$description] = $with;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function has(string $filename, string $description): bool
|
public static function has(string $filename, string $description): bool
|
||||||
{
|
{
|
||||||
return array_key_exists($filename . '>>>' . $description, self::$withs);
|
return array_key_exists($filename.'>>>'.$description, self::$withs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,7 +67,7 @@ final class DatasetsRepository
|
|||||||
*/
|
*/
|
||||||
public static function get(string $filename, string $description): Closure|iterable
|
public static function get(string $filename, string $description): Closure|iterable
|
||||||
{
|
{
|
||||||
$dataset = self::$withs[$filename . '>>>' . $description];
|
$dataset = self::$withs[$filename.'>>>'.$description];
|
||||||
|
|
||||||
$dataset = self::resolve($description, $dataset);
|
$dataset = self::resolve($description, $dataset);
|
||||||
|
|
||||||
@ -83,8 +81,7 @@ final class DatasetsRepository
|
|||||||
/**
|
/**
|
||||||
* Resolves the current dataset to an array value.
|
* Resolves the current dataset to an array value.
|
||||||
*
|
*
|
||||||
* @param array<Closure|iterable<int|string, mixed>|string> $dataset
|
* @param array<Closure|iterable<int|string, mixed>|string> $dataset
|
||||||
*
|
|
||||||
* @return array<string, mixed>|null
|
* @return array<string, mixed>|null
|
||||||
*/
|
*/
|
||||||
public static function resolve(string $description, array $dataset): array|null
|
public static function resolve(string $description, array $dataset): array|null
|
||||||
@ -99,11 +96,11 @@ final class DatasetsRepository
|
|||||||
$datasetCombinations = self::getDatasetsCombinations($dataset);
|
$datasetCombinations = self::getDatasetsCombinations($dataset);
|
||||||
|
|
||||||
$datasetDescriptions = [];
|
$datasetDescriptions = [];
|
||||||
$datasetValues = [];
|
$datasetValues = [];
|
||||||
|
|
||||||
foreach ($datasetCombinations as $datasetCombination) {
|
foreach ($datasetCombinations as $datasetCombination) {
|
||||||
$partialDescriptions = [];
|
$partialDescriptions = [];
|
||||||
$values = [];
|
$values = [];
|
||||||
|
|
||||||
foreach ($datasetCombination as $datasetCombinationElement) {
|
foreach ($datasetCombination as $datasetCombinationElement) {
|
||||||
$partialDescriptions[] = $datasetCombinationElement['label'];
|
$partialDescriptions[] = $datasetCombinationElement['label'];
|
||||||
@ -113,7 +110,7 @@ final class DatasetsRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
$datasetDescriptions[] = implode(' / ', $partialDescriptions);
|
$datasetDescriptions[] = implode(' / ', $partialDescriptions);
|
||||||
$datasetValues[] = $values;
|
$datasetValues[] = $values;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array_count_values($datasetDescriptions) as $descriptionToCheck => $count) {
|
foreach (array_count_values($datasetDescriptions) as $descriptionToCheck => $count) {
|
||||||
@ -136,8 +133,7 @@ final class DatasetsRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<Closure|iterable<int|string, mixed>|string> $datasets
|
* @param array<Closure|iterable<int|string, mixed>|string> $datasets
|
||||||
*
|
|
||||||
* @return array<array<mixed>>
|
* @return array<array<mixed>>
|
||||||
*/
|
*/
|
||||||
private static function processDatasets(array $datasets): array
|
private static function processDatasets(array $datasets): array
|
||||||
@ -148,7 +144,7 @@ final class DatasetsRepository
|
|||||||
$processedDataset = [];
|
$processedDataset = [];
|
||||||
|
|
||||||
if (is_string($data)) {
|
if (is_string($data)) {
|
||||||
if (!array_key_exists($data, self::$datasets)) {
|
if (! array_key_exists($data, self::$datasets)) {
|
||||||
throw new DatasetDoesNotExist($data);
|
throw new DatasetDoesNotExist($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,9 +161,9 @@ final class DatasetsRepository
|
|||||||
|
|
||||||
// @phpstan-ignore-next-line
|
// @phpstan-ignore-next-line
|
||||||
foreach ($datasets[$index] as $key => $values) {
|
foreach ($datasets[$index] as $key => $values) {
|
||||||
$values = is_array($values) ? $values : [$values];
|
$values = is_array($values) ? $values : [$values];
|
||||||
$processedDataset[] = [
|
$processedDataset[] = [
|
||||||
'label' => self::getDatasetDescription($key, $values), // @phpstan-ignore-line
|
'label' => self::getDatasetDescription($key, $values), // @phpstan-ignore-line
|
||||||
'values' => $values,
|
'values' => $values,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -179,8 +175,7 @@ final class DatasetsRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<array<mixed>> $combinations
|
* @param array<array<mixed>> $combinations
|
||||||
*
|
|
||||||
* @return array<array<array<mixed>>>
|
* @return array<array<array<mixed>>>
|
||||||
*/
|
*/
|
||||||
private static function getDatasetsCombinations(array $combinations): array
|
private static function getDatasetsCombinations(array $combinations): array
|
||||||
@ -201,7 +196,7 @@ final class DatasetsRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<int, mixed> $data
|
* @param array<int, mixed> $data
|
||||||
*/
|
*/
|
||||||
private static function getDatasetDescription(int|string $key, array $data): string
|
private static function getDatasetDescription(int|string $key, array $data): string
|
||||||
{
|
{
|
||||||
|
|||||||
@ -9,7 +9,7 @@ namespace Pest\Repositories;
|
|||||||
*/
|
*/
|
||||||
final class TempRepository
|
final class TempRepository
|
||||||
{
|
{
|
||||||
private const FOLDER = __DIR__ . '/../../.temp';
|
private const FOLDER = __DIR__.'/../../.temp';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Temp Repository instance.
|
* Creates a new Temp Repository instance.
|
||||||
@ -35,7 +35,7 @@ final class TempRepository
|
|||||||
*/
|
*/
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
@unlink(self::FOLDER . '/' . $this->filename . '.json'); // @phpstan-ignore-line
|
@unlink(self::FOLDER.'/'.$this->filename.'.json'); // @phpstan-ignore-line
|
||||||
|
|
||||||
$this->save([]);
|
$this->save([]);
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ final class TempRepository
|
|||||||
*/
|
*/
|
||||||
private function all(): array
|
private function all(): array
|
||||||
{
|
{
|
||||||
$contents = file_get_contents(self::FOLDER . '/' . $this->filename . '.json');
|
$contents = file_get_contents(self::FOLDER.'/'.$this->filename.'.json');
|
||||||
|
|
||||||
assert(is_string($contents));
|
assert(is_string($contents));
|
||||||
|
|
||||||
@ -67,12 +67,12 @@ final class TempRepository
|
|||||||
/**
|
/**
|
||||||
* Save the given elements.
|
* Save the given elements.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $elements
|
* @param array<int, string> $elements
|
||||||
*/
|
*/
|
||||||
private function save(array $elements): void
|
private function save(array $elements): void
|
||||||
{
|
{
|
||||||
$contents = json_encode($elements);
|
$contents = json_encode($elements);
|
||||||
|
|
||||||
file_put_contents(self::FOLDER . '/' . $this->filename . '.json', $contents);
|
file_put_contents(self::FOLDER.'/'.$this->filename.'.json', $contents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,15 +54,15 @@ final class TestRepository
|
|||||||
/**
|
/**
|
||||||
* Uses the given `$testCaseClass` on the given `$paths`.
|
* Uses the given `$testCaseClass` on the given `$paths`.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $classOrTraits
|
* @param array<int, string> $classOrTraits
|
||||||
* @param array<int, string> $groups
|
* @param array<int, string> $groups
|
||||||
* @param array<int, string> $paths
|
* @param array<int, string> $paths
|
||||||
* @param array<int, Closure> $hooks
|
* @param array<int, Closure> $hooks
|
||||||
*/
|
*/
|
||||||
public function use(array $classOrTraits, array $groups, array $paths, array $hooks): void
|
public function use(array $classOrTraits, array $groups, array $paths, array $hooks): void
|
||||||
{
|
{
|
||||||
foreach ($classOrTraits as $classOrTrait) {
|
foreach ($classOrTraits as $classOrTrait) {
|
||||||
if (!class_exists($classOrTrait) && !trait_exists($classOrTrait)) {
|
if (! class_exists($classOrTrait) && ! trait_exists($classOrTrait)) {
|
||||||
throw new TestCaseClassOrTraitNotFound($classOrTrait);
|
throw new TestCaseClassOrTraitNotFound($classOrTrait);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ final class TestRepository
|
|||||||
*/
|
*/
|
||||||
public function set(TestCaseMethodFactory $method): void
|
public function set(TestCaseMethodFactory $method): void
|
||||||
{
|
{
|
||||||
if (!array_key_exists($method->filename, $this->testCases)) {
|
if (! array_key_exists($method->filename, $this->testCases)) {
|
||||||
$this->testCases[$method->filename] = new TestCaseFactory($method->filename);
|
$this->testCases[$method->filename] = new TestCaseFactory($method->filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,12 +112,12 @@ final class TestRepository
|
|||||||
*/
|
*/
|
||||||
private function make(TestCaseFactory $testCase): void
|
private function make(TestCaseFactory $testCase): void
|
||||||
{
|
{
|
||||||
$startsWith = static fn (string $target, string $directory): bool => Str::startsWith($target, $directory . DIRECTORY_SEPARATOR);
|
$startsWith = static fn (string $target, string $directory): bool => Str::startsWith($target, $directory.DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
foreach ($this->uses as $path => $uses) {
|
foreach ($this->uses as $path => $uses) {
|
||||||
[$classOrTraits, $groups, $hooks] = $uses;
|
[$classOrTraits, $groups, $hooks] = $uses;
|
||||||
|
|
||||||
if ((!is_dir($path) && $testCase->filename === $path) || (is_dir($path) && $startsWith($testCase->filename, $path))) {
|
if ((! is_dir($path) && $testCase->filename === $path) || (is_dir($path) && $startsWith($testCase->filename, $path))) {
|
||||||
foreach ($classOrTraits as $class) {
|
foreach ($classOrTraits as $class) {
|
||||||
/** @var string $class */
|
/** @var string $class */
|
||||||
if (class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
|
|||||||
@ -12,7 +12,7 @@ final class Arr
|
|||||||
/**
|
/**
|
||||||
* Checks if the given array has the given key.
|
* Checks if the given array has the given key.
|
||||||
*
|
*
|
||||||
* @param array<array-key, mixed> $array
|
* @param array<array-key, mixed> $array
|
||||||
*/
|
*/
|
||||||
public static function has(array $array, string|int $key): bool
|
public static function has(array $array, string|int $key): bool
|
||||||
{
|
{
|
||||||
@ -36,7 +36,7 @@ final class Arr
|
|||||||
/**
|
/**
|
||||||
* Gets the given key value.
|
* Gets the given key value.
|
||||||
*
|
*
|
||||||
* @param array<array-key, mixed> $array
|
* @param array<array-key, mixed> $array
|
||||||
*/
|
*/
|
||||||
public static function get(array $array, string|int $key, mixed $default = null): mixed
|
public static function get(array $array, string|int $key, mixed $default = null): mixed
|
||||||
{
|
{
|
||||||
@ -46,7 +46,7 @@ final class Arr
|
|||||||
return $array[$key];
|
return $array[$key];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!str_contains($key, '.')) {
|
if (! str_contains($key, '.')) {
|
||||||
return $array[$key] ?? $default;
|
return $array[$key] ?? $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,8 +64,7 @@ final class Arr
|
|||||||
/**
|
/**
|
||||||
* Flatten a multi-dimensional associative array with dots.
|
* Flatten a multi-dimensional associative array with dots.
|
||||||
*
|
*
|
||||||
* @param array<array-key, mixed> $array
|
* @param array<array-key, mixed> $array
|
||||||
*
|
|
||||||
* @return array<int|string, mixed>
|
* @return array<int|string, mixed>
|
||||||
*/
|
*/
|
||||||
public static function dot(array $array, string $prepend = ''): array
|
public static function dot(array $array, string $prepend = ''): array
|
||||||
@ -74,9 +73,9 @@ final class Arr
|
|||||||
|
|
||||||
foreach ($array as $key => $value) {
|
foreach ($array as $key => $value) {
|
||||||
if (is_array($value) && count($value) > 0) {
|
if (is_array($value) && count($value) > 0) {
|
||||||
$results = array_merge($results, static::dot($value, $prepend . $key . '.'));
|
$results = array_merge($results, static::dot($value, $prepend.$key.'.'));
|
||||||
} else {
|
} else {
|
||||||
$results[$prepend . $value] = $value;
|
$results[$prepend.$value] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ 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 {
|
||||||
if (!is_object($this)) { // @phpstan-ignore-line
|
if (! is_object($this)) { // @phpstan-ignore-line
|
||||||
throw ShouldNotHappen::fromMessage('$this not bound to chainable closure.');
|
throw ShouldNotHappen::fromMessage('$this not bound to chainable closure.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -35,13 +35,12 @@ final class Container
|
|||||||
/**
|
/**
|
||||||
* Gets a dependency from the container.
|
* Gets a dependency from the container.
|
||||||
*
|
*
|
||||||
* @param class-string $id
|
* @param class-string $id
|
||||||
*
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function get(string $id)
|
public function get(string $id)
|
||||||
{
|
{
|
||||||
if (!array_key_exists($id, $this->instances)) {
|
if (! array_key_exists($id, $this->instances)) {
|
||||||
$this->instances[$id] = $this->build($id);
|
$this->instances[$id] = $this->build($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +50,7 @@ final class Container
|
|||||||
/**
|
/**
|
||||||
* Adds the given instance to the container.
|
* Adds the given instance to the container.
|
||||||
*
|
*
|
||||||
* @param mixed $instance
|
* @param mixed $instance
|
||||||
*/
|
*/
|
||||||
public function add(string $id, $instance): void
|
public function add(string $id, $instance): void
|
||||||
{
|
{
|
||||||
@ -61,7 +60,7 @@ final class Container
|
|||||||
/**
|
/**
|
||||||
* Tries to build the given instance.
|
* Tries to build the given instance.
|
||||||
*
|
*
|
||||||
* @param class-string $id
|
* @param class-string $id
|
||||||
*/
|
*/
|
||||||
private function build(string $id): object
|
private function build(string $id): object
|
||||||
{
|
{
|
||||||
|
|||||||
@ -11,7 +11,6 @@ use SebastianBergmann\CodeCoverage\Node\File;
|
|||||||
use SebastianBergmann\Environment\Runtime;
|
use SebastianBergmann\Environment\Runtime;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Terminal;
|
use Symfony\Component\Console\Terminal;
|
||||||
|
|
||||||
use function Termwind\render;
|
use function Termwind\render;
|
||||||
use function Termwind\renderUsing;
|
use function Termwind\renderUsing;
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ 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()) {
|
if (self::usingXdebug()) {
|
||||||
$output->writeln(
|
$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</>?</>",
|
" <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</>?</>",
|
||||||
@ -80,10 +79,10 @@ final class Coverage
|
|||||||
$report = $codeCoverage->getReport();
|
$report = $codeCoverage->getReport();
|
||||||
|
|
||||||
foreach ($report->getIterator() as $file) {
|
foreach ($report->getIterator() as $file) {
|
||||||
if (!$file instanceof File) {
|
if (! $file instanceof File) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$dirname = dirname($file->id());
|
$dirname = dirname($file->id());
|
||||||
$basename = basename($file->id(), '.php');
|
$basename = basename($file->id(), '.php');
|
||||||
|
|
||||||
$name = $dirname === '.' ? $basename : implode(DIRECTORY_SEPARATOR, [
|
$name = $dirname === '.' ? $basename : implode(DIRECTORY_SEPARATOR, [
|
||||||
@ -106,7 +105,7 @@ final class Coverage
|
|||||||
? '100.0'
|
? '100.0'
|
||||||
: number_format($file->percentageOfExecutedLines()->asFloat(), 1, '.', '');
|
: number_format($file->percentageOfExecutedLines()->asFloat(), 1, '.', '');
|
||||||
|
|
||||||
$takenSize = strlen($rawName . $percentage) + 2 + $linesExecutedTakenSize; // adding 3 space and percent sign
|
$takenSize = strlen($rawName.$percentage) + 2 + $linesExecutedTakenSize; // adding 3 space and percent sign
|
||||||
|
|
||||||
$percentage = sprintf(
|
$percentage = sprintf(
|
||||||
'<fg=%s>%s</>',
|
'<fg=%s>%s</>',
|
||||||
@ -146,8 +145,7 @@ final class Coverage
|
|||||||
* ['11', '20..25', '50', '60..80'];
|
* ['11', '20..25', '50', '60..80'];
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @param File $file
|
* @param File $file
|
||||||
*
|
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
public static function getMissingCoverage($file): array
|
public static function getMissingCoverage($file): array
|
||||||
@ -162,7 +160,7 @@ final class Coverage
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($shouldBeNewLine) {
|
if ($shouldBeNewLine) {
|
||||||
$array[] = (string) $line;
|
$array[] = (string) $line;
|
||||||
$shouldBeNewLine = false;
|
$shouldBeNewLine = false;
|
||||||
|
|
||||||
return $array;
|
return $array;
|
||||||
@ -171,7 +169,7 @@ final class Coverage
|
|||||||
$lastKey = count($array) - 1;
|
$lastKey = count($array) - 1;
|
||||||
|
|
||||||
if (array_key_exists($lastKey, $array) && str_contains($array[$lastKey], '..')) {
|
if (array_key_exists($lastKey, $array) && str_contains($array[$lastKey], '..')) {
|
||||||
[$from] = explode('..', $array[$lastKey]);
|
[$from] = explode('..', $array[$lastKey]);
|
||||||
$array[$lastKey] = $line > $from ? sprintf('%s..%s', $from, $line) : sprintf('%s..%s', $line, $from);
|
$array[$lastKey] = $line > $from ? sprintf('%s..%s', $from, $line) : sprintf('%s..%s', $line, $from);
|
||||||
|
|
||||||
return $array;
|
return $array;
|
||||||
|
|||||||
@ -44,7 +44,7 @@ final class ExceptionTrace
|
|||||||
*/
|
*/
|
||||||
public static function removePestReferences(Throwable $t): void
|
public static function removePestReferences(Throwable $t): void
|
||||||
{
|
{
|
||||||
if (!property_exists($t, 'serializableTrace')) {
|
if (! property_exists($t, 'serializableTrace')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -59,7 +59,7 @@ final class ExpectationPipeline
|
|||||||
/**
|
/**
|
||||||
* Sets the list of pipes.
|
* Sets the list of pipes.
|
||||||
*
|
*
|
||||||
* @param array<int, Closure> $pipes
|
* @param array<int, Closure> $pipes
|
||||||
*/
|
*/
|
||||||
public function through(array $pipes): self
|
public function through(array $pipes): self
|
||||||
{
|
{
|
||||||
|
|||||||
@ -26,7 +26,6 @@ final class HigherOrderCallables
|
|||||||
* Create a new expectation. Callable values will be executed prior to returning the new expectation.
|
* Create a new expectation. Callable values will be executed prior to returning the new expectation.
|
||||||
*
|
*
|
||||||
* @param (Closure():TValue)|TValue $value
|
* @param (Closure():TValue)|TValue $value
|
||||||
*
|
|
||||||
* @return Expectation<TValue>
|
* @return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function expect(mixed $value): Expectation
|
public function expect(mixed $value): Expectation
|
||||||
@ -42,8 +41,7 @@ final class HigherOrderCallables
|
|||||||
*
|
*
|
||||||
* Create a new expectation. Callable values will be executed prior to returning the new expectation.
|
* Create a new expectation. Callable values will be executed prior to returning the new expectation.
|
||||||
*
|
*
|
||||||
* @param callable|TValue $value
|
* @param callable|TValue $value
|
||||||
*
|
|
||||||
* @return Expectation<(callable(): mixed)|TValue>
|
* @return Expectation<(callable(): mixed)|TValue>
|
||||||
*/
|
*/
|
||||||
public function and(mixed $value)
|
public function and(mixed $value)
|
||||||
|
|||||||
@ -25,7 +25,7 @@ final class HigherOrderMessage
|
|||||||
/**
|
/**
|
||||||
* Creates a new higher order message.
|
* Creates a new higher order message.
|
||||||
*
|
*
|
||||||
* @param array<int, mixed> $arguments
|
* @param array<int, mixed> $arguments
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $filename,
|
public string $filename,
|
||||||
@ -41,7 +41,7 @@ final class HigherOrderMessage
|
|||||||
*
|
*
|
||||||
* @template TValue of object
|
* @template TValue of object
|
||||||
*
|
*
|
||||||
* @param TValue $target
|
* @param TValue $target
|
||||||
*/
|
*/
|
||||||
public function call(object $target): mixed
|
public function call(object $target): mixed
|
||||||
{
|
{
|
||||||
@ -77,7 +77,7 @@ final class HigherOrderMessage
|
|||||||
/**
|
/**
|
||||||
* Indicates that this message should only be called when the given condition is true.
|
* Indicates that this message should only be called when the given condition is true.
|
||||||
*
|
*
|
||||||
* @param callable(): bool $condition
|
* @param callable(): bool $condition
|
||||||
*/
|
*/
|
||||||
public function when(callable $condition): self
|
public function when(callable $condition): self
|
||||||
{
|
{
|
||||||
|
|||||||
@ -17,7 +17,7 @@ final class HigherOrderMessageCollection
|
|||||||
/**
|
/**
|
||||||
* Adds a new higher order message to the collection.
|
* Adds a new higher order message to the collection.
|
||||||
*
|
*
|
||||||
* @param array<int, mixed>|null $arguments
|
* @param array<int, mixed>|null $arguments
|
||||||
*/
|
*/
|
||||||
public function add(string $filename, int $line, string $name, ?array $arguments): void
|
public function add(string $filename, int $line, string $name, ?array $arguments): void
|
||||||
{
|
{
|
||||||
@ -27,7 +27,7 @@ final class HigherOrderMessageCollection
|
|||||||
/**
|
/**
|
||||||
* Adds a new higher order message to the collection if the callable condition is does not return false.
|
* Adds a new higher order message to the collection if the callable condition is does not return false.
|
||||||
*
|
*
|
||||||
* @param array<int, mixed>|null $arguments
|
* @param array<int, mixed>|null $arguments
|
||||||
*/
|
*/
|
||||||
public function addWhen(callable $condition, string $filename, int $line, string $name, ?array $arguments): void
|
public function addWhen(callable $condition, string $filename, int $line, string $name, ?array $arguments): void
|
||||||
{
|
{
|
||||||
@ -58,7 +58,7 @@ final class HigherOrderMessageCollection
|
|||||||
/**
|
/**
|
||||||
* Count the number of messages with the given name.
|
* Count the number of messages with the given name.
|
||||||
*
|
*
|
||||||
* @param string $name A higher order message name (usually a method name)
|
* @param string $name A higher order message name (usually a method name)
|
||||||
*/
|
*/
|
||||||
public function count(string $name): int
|
public function count(string $name): int
|
||||||
{
|
{
|
||||||
|
|||||||
@ -27,7 +27,7 @@ final class HigherOrderTapProxy
|
|||||||
/**
|
/**
|
||||||
* Dynamically sets properties on the target.
|
* Dynamically sets properties on the target.
|
||||||
*
|
*
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*/
|
*/
|
||||||
public function __set(string $property, $value): void
|
public function __set(string $property, $value): void
|
||||||
{
|
{
|
||||||
@ -60,14 +60,13 @@ final class HigherOrderTapProxy
|
|||||||
/**
|
/**
|
||||||
* Dynamically pass method calls to the target.
|
* Dynamically pass method calls to the target.
|
||||||
*
|
*
|
||||||
* @param array<int, mixed> $arguments
|
* @param array<int, mixed> $arguments
|
||||||
*
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function __call(string $methodName, array $arguments)
|
public function __call(string $methodName, array $arguments)
|
||||||
{
|
{
|
||||||
$filename = Backtrace::file();
|
$filename = Backtrace::file();
|
||||||
$line = Backtrace::line();
|
$line = Backtrace::line();
|
||||||
|
|
||||||
return (new HigherOrderMessage($filename, $line, $methodName, $arguments))
|
return (new HigherOrderMessage($filename, $line, $methodName, $arguments))
|
||||||
->call($this->target);
|
->call($this->target);
|
||||||
|
|||||||
@ -33,7 +33,7 @@ abstract class Printer implements \PHPUnit\Util\Printer
|
|||||||
|
|
||||||
$this->isPhpStream = str_starts_with($out, 'php://');
|
$this->isPhpStream = str_starts_with($out, 'php://');
|
||||||
|
|
||||||
if (!$this->isPhpStream && !Filesystem::createDirectory(dirname($out))) {
|
if (! $this->isPhpStream && ! Filesystem::createDirectory(dirname($out))) {
|
||||||
throw new Exception(sprintf('Directory "%s" was not created', dirname($out)));
|
throw new Exception(sprintf('Directory "%s" was not created', dirname($out)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,8 +22,7 @@ final class Reflection
|
|||||||
/**
|
/**
|
||||||
* Calls the given method with args on the given object.
|
* Calls the given method with args on the given object.
|
||||||
*
|
*
|
||||||
* @param array<int, mixed> $args
|
* @param array<int, mixed> $args
|
||||||
*
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function call(object $object, string $method, array $args = [])
|
public static function call(object $object, string $method, array $args = [])
|
||||||
@ -52,8 +51,7 @@ final class Reflection
|
|||||||
/**
|
/**
|
||||||
* Bind a callable to the TestCase and return the result.
|
* Bind a callable to the TestCase and return the result.
|
||||||
*
|
*
|
||||||
* @param array<int, mixed> $args
|
* @param array<int, mixed> $args
|
||||||
*
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function bindCallable(callable $callable, array $args = [])
|
public static function bindCallable(callable $callable, array $args = [])
|
||||||
@ -104,7 +102,7 @@ final class Reflection
|
|||||||
} catch (ReflectionException $reflectionException) {
|
} catch (ReflectionException $reflectionException) {
|
||||||
$reflectionClass = $reflectionClass->getParentClass();
|
$reflectionClass = $reflectionClass->getParentClass();
|
||||||
|
|
||||||
if (!$reflectionClass instanceof ReflectionClass) {
|
if (! $reflectionClass instanceof ReflectionClass) {
|
||||||
throw new ShouldNotHappen($reflectionException);
|
throw new ShouldNotHappen($reflectionException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,8 +118,8 @@ final class Reflection
|
|||||||
*
|
*
|
||||||
* @template TValue of object
|
* @template TValue of object
|
||||||
*
|
*
|
||||||
* @param TValue $object
|
* @param TValue $object
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*/
|
*/
|
||||||
public static function setPropertyValue(object $object, string $property, $value): void
|
public static function setPropertyValue(object $object, string $property, $value): void
|
||||||
{
|
{
|
||||||
@ -137,7 +135,7 @@ final class Reflection
|
|||||||
} catch (ReflectionException $reflectionException) {
|
} catch (ReflectionException $reflectionException) {
|
||||||
$reflectionClass = $reflectionClass->getParentClass();
|
$reflectionClass = $reflectionClass->getParentClass();
|
||||||
|
|
||||||
if (!$reflectionClass instanceof ReflectionClass) {
|
if (! $reflectionClass instanceof ReflectionClass) {
|
||||||
throw new ShouldNotHappen($reflectionException);
|
throw new ShouldNotHappen($reflectionException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,7 +154,7 @@ final class Reflection
|
|||||||
{
|
{
|
||||||
$type = $parameter->getType();
|
$type = $parameter->getType();
|
||||||
|
|
||||||
if (!$type instanceof ReflectionNamedType || $type->isBuiltin()) {
|
if (! $type instanceof ReflectionNamedType || $type->isBuiltin()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +181,7 @@ final class Reflection
|
|||||||
public static function getFunctionArguments(Closure $function): array
|
public static function getFunctionArguments(Closure $function): array
|
||||||
{
|
{
|
||||||
$parameters = (new ReflectionFunction($function))->getParameters();
|
$parameters = (new ReflectionFunction($function))->getParameters();
|
||||||
$arguments = [];
|
$arguments = [];
|
||||||
|
|
||||||
foreach ($parameters as $parameter) {
|
foreach ($parameters as $parameter) {
|
||||||
/** @var ReflectionNamedType|ReflectionUnionType|null $types */
|
/** @var ReflectionNamedType|ReflectionUnionType|null $types */
|
||||||
|
|||||||
@ -19,7 +19,7 @@ final class Str
|
|||||||
* Create a (unsecure & non-cryptographically safe) random alpha-numeric
|
* Create a (unsecure & non-cryptographically safe) random alpha-numeric
|
||||||
* string value.
|
* string value.
|
||||||
*
|
*
|
||||||
* @param int $length the length of the resulting randomized string
|
* @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
|
* @see https://github.com/laravel/framework/blob/4.2/src/Illuminate/Support/Str.php#L240-L242
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -70,11 +70,11 @@ final class TestSuite
|
|||||||
string $rootPath,
|
string $rootPath,
|
||||||
public string $testPath)
|
public string $testPath)
|
||||||
{
|
{
|
||||||
$this->beforeAll = new BeforeAllRepository();
|
$this->beforeAll = new BeforeAllRepository();
|
||||||
$this->beforeEach = new BeforeEachRepository();
|
$this->beforeEach = new BeforeEachRepository();
|
||||||
$this->tests = new TestRepository();
|
$this->tests = new TestRepository();
|
||||||
$this->afterEach = new AfterEachRepository();
|
$this->afterEach = new AfterEachRepository();
|
||||||
$this->afterAll = new AfterAllRepository();
|
$this->afterAll = new AfterAllRepository();
|
||||||
$this->retryTempRepository = new TempRepository('retry');
|
$this->retryTempRepository = new TempRepository('retry');
|
||||||
|
|
||||||
$this->rootPath = (string) realpath($rootPath);
|
$this->rootPath = (string) realpath($rootPath);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$file = __DIR__ . DIRECTORY_SEPARATOR . 'after-all-test';
|
$file = __DIR__.DIRECTORY_SEPARATOR.'after-all-test';
|
||||||
|
|
||||||
beforeAll(function () use ($file) {
|
beforeAll(function () use ($file) {
|
||||||
@unlink($file);
|
@unlink($file);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$foo = new \stdClass();
|
$foo = new \stdClass();
|
||||||
$foo->bar = 0;
|
$foo->bar = 0;
|
||||||
|
|
||||||
beforeAll(function () use ($foo) {
|
beforeAll(function () use ($foo) {
|
||||||
|
|||||||
@ -35,16 +35,17 @@ it('adds coverage if --min exist', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('generates coverage based on file input', function () {
|
it('generates coverage based on file input', function () {
|
||||||
expect(Coverage::getMissingCoverage(new class() {
|
expect(Coverage::getMissingCoverage(new class()
|
||||||
|
{
|
||||||
public function lineCoverageData(): array
|
public function lineCoverageData(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
1 => ['foo'],
|
1 => ['foo'],
|
||||||
2 => ['bar'],
|
2 => ['bar'],
|
||||||
4 => [],
|
4 => [],
|
||||||
5 => [],
|
5 => [],
|
||||||
6 => [],
|
6 => [],
|
||||||
7 => null,
|
7 => null,
|
||||||
100 => null,
|
100 => null,
|
||||||
101 => ['foo'],
|
101 => ['foo'],
|
||||||
102 => [],
|
102 => [],
|
||||||
|
|||||||
@ -46,7 +46,7 @@ test('it truncates the description', function () {
|
|||||||
// it gets tested by the integration test
|
// it gets tested by the integration test
|
||||||
})->with([str_repeat('Fooo', 10)]);
|
})->with([str_repeat('Fooo', 10)]);
|
||||||
|
|
||||||
$state = new stdClass();
|
$state = new stdClass();
|
||||||
$state->text = '';
|
$state->text = '';
|
||||||
|
|
||||||
$datasets = [[1], [2]];
|
$datasets = [[1], [2]];
|
||||||
@ -148,7 +148,7 @@ $datasets_a = [[1], [2]];
|
|||||||
$datasets_b = [[3], [4]];
|
$datasets_b = [[3], [4]];
|
||||||
|
|
||||||
test('lazy multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) {
|
test('lazy multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) {
|
||||||
$state->text .= $text_a . $text_b;
|
$state->text .= $text_a.$text_b;
|
||||||
expect($datasets_a)->toContain([$text_a]);
|
expect($datasets_a)->toContain([$text_a]);
|
||||||
expect($datasets_b)->toContain([$text_b]);
|
expect($datasets_b)->toContain([$text_b]);
|
||||||
})->with($datasets_a, $datasets_b);
|
})->with($datasets_a, $datasets_b);
|
||||||
@ -160,7 +160,7 @@ test('lazy multiple datasets did the job right', function () use ($state) {
|
|||||||
$state->text = '';
|
$state->text = '';
|
||||||
|
|
||||||
test('eager multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) {
|
test('eager multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) {
|
||||||
$state->text .= $text_a . $text_b;
|
$state->text .= $text_a.$text_b;
|
||||||
expect($datasets_a)->toContain([$text_a]);
|
expect($datasets_a)->toContain([$text_a]);
|
||||||
expect($datasets_b)->toContain([$text_b]);
|
expect($datasets_b)->toContain([$text_b]);
|
||||||
})->with(function () use ($datasets_a) {
|
})->with(function () use ($datasets_a) {
|
||||||
@ -174,7 +174,7 @@ test('eager multiple datasets did the job right', function () use ($state) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('lazy registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) {
|
test('lazy registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) {
|
||||||
$state->text .= $text_a . $text_b;
|
$state->text .= $text_a.$text_b;
|
||||||
expect($datasets)->toContain([$text_a]);
|
expect($datasets)->toContain([$text_a]);
|
||||||
expect($datasets)->toContain([$text_b]);
|
expect($datasets)->toContain([$text_b]);
|
||||||
})->with('numbers.array')->with('numbers.array');
|
})->with('numbers.array')->with('numbers.array');
|
||||||
@ -184,7 +184,7 @@ test('lazy registered multiple datasets did the job right', function () use ($st
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('eager registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) {
|
test('eager registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) {
|
||||||
$state->text .= $text_a . $text_b;
|
$state->text .= $text_a.$text_b;
|
||||||
expect($datasets)->toContain([$text_a]);
|
expect($datasets)->toContain([$text_a]);
|
||||||
expect($datasets)->toContain([$text_b]);
|
expect($datasets)->toContain([$text_b]);
|
||||||
})->with('numbers.array')->with('numbers.closure');
|
})->with('numbers.array')->with('numbers.closure');
|
||||||
@ -194,7 +194,7 @@ test('eager registered multiple datasets did the job right', function () use ($s
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('eager wrapped registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) {
|
test('eager wrapped registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) {
|
||||||
$state->text .= $text_a . $text_b;
|
$state->text .= $text_a.$text_b;
|
||||||
expect($datasets)->toContain([$text_a]);
|
expect($datasets)->toContain([$text_a]);
|
||||||
expect($datasets)->toContain([$text_b]);
|
expect($datasets)->toContain([$text_b]);
|
||||||
})->with('numbers.closure.wrapped')->with('numbers.closure');
|
})->with('numbers.closure.wrapped')->with('numbers.closure');
|
||||||
@ -204,7 +204,7 @@ test('eager wrapped registered multiple datasets did the job right', function ()
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('named multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) {
|
test('named multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) {
|
||||||
$state->text .= $text_a . $text_b;
|
$state->text .= $text_a.$text_b;
|
||||||
expect($datasets_a)->toContain([$text_a]);
|
expect($datasets_a)->toContain([$text_a]);
|
||||||
expect($datasets_b)->toContain([$text_b]);
|
expect($datasets_b)->toContain([$text_b]);
|
||||||
})->with([
|
})->with([
|
||||||
@ -212,7 +212,7 @@ test('named multiple datasets', function ($text_a, $text_b) use ($state, $datase
|
|||||||
'two' => [2],
|
'two' => [2],
|
||||||
])->with([
|
])->with([
|
||||||
'three' => [3],
|
'three' => [3],
|
||||||
'four' => [4],
|
'four' => [4],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
test('named multiple datasets did the job right', function () use ($state) {
|
test('named multiple datasets did the job right', function () use ($state) {
|
||||||
@ -220,7 +220,7 @@ test('named multiple datasets did the job right', function () use ($state) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('more than two datasets', function ($text_a, $text_b, $text_c) use ($state, $datasets_a, $datasets_b) {
|
test('more than two datasets', function ($text_a, $text_b, $text_c) use ($state, $datasets_a, $datasets_b) {
|
||||||
$state->text .= $text_a . $text_b . $text_c;
|
$state->text .= $text_a.$text_b.$text_c;
|
||||||
expect($datasets_a)->toContain([$text_a]);
|
expect($datasets_a)->toContain([$text_a]);
|
||||||
expect($datasets_b)->toContain([$text_b]);
|
expect($datasets_b)->toContain([$text_b]);
|
||||||
expect([5, 6])->toContain($text_c);
|
expect([5, 6])->toContain($text_c);
|
||||||
|
|||||||
@ -131,7 +131,7 @@ class HasMethods
|
|||||||
public function attributes()
|
public function attributes()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => $this->name(),
|
'name' => $this->name(),
|
||||||
'quantity' => $this->quantity(),
|
'quantity' => $this->quantity(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -141,11 +141,11 @@ class HasMethods
|
|||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
'title' => 'Foo',
|
'title' => 'Foo',
|
||||||
'cost' => 20,
|
'cost' => 20,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Bar',
|
'title' => 'Bar',
|
||||||
'cost' => 30,
|
'cost' => 30,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,11 +72,11 @@ class HasMethodsAndProperties
|
|||||||
public $posts = [
|
public $posts = [
|
||||||
[
|
[
|
||||||
'is_published' => true,
|
'is_published' => true,
|
||||||
'title' => 'Foo',
|
'title' => 'Foo',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'is_published' => true,
|
'is_published' => true,
|
||||||
'title' => 'Bar',
|
'title' => 'Bar',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -85,11 +85,11 @@ class HasMethodsAndProperties
|
|||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
'title' => 'Foo',
|
'title' => 'Foo',
|
||||||
'cost' => 20,
|
'cost' => 20,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Bar',
|
'title' => 'Bar',
|
||||||
'cost' => 30,
|
'cost' => 30,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,11 +86,11 @@ class HasProperties
|
|||||||
public $posts = [
|
public $posts = [
|
||||||
[
|
[
|
||||||
'is_published' => true,
|
'is_published' => true,
|
||||||
'title' => 'Foo',
|
'title' => 'Foo',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'is_published' => true,
|
'is_published' => true,
|
||||||
'title' => 'Bar',
|
'title' => 'Bar',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -128,7 +128,7 @@ it('runs with falsy closure condition', function () {
|
|||||||
it('can be passed non-callable values', function () {
|
it('can be passed non-callable values', function () {
|
||||||
expect('foo')
|
expect('foo')
|
||||||
->match('pest', [
|
->match('pest', [
|
||||||
'bar' => 'foo',
|
'bar' => 'foo',
|
||||||
'pest' => 'baz',
|
'pest' => 'baz',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|||||||
@ -48,10 +48,10 @@ class State
|
|||||||
public function reset(): void
|
public function reset(): void
|
||||||
{
|
{
|
||||||
$this->appliedCount = $this->runCount = [
|
$this->appliedCount = $this->runCount = [
|
||||||
'char' => 0,
|
'char' => 0,
|
||||||
'number' => 0,
|
'number' => 0,
|
||||||
'wildcard' => 0,
|
'wildcard' => 0,
|
||||||
'symbol' => 0,
|
'symbol' => 0,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,16 +133,16 @@ test('pipe is applied and can stop pipeline', function () use ($state) {
|
|||||||
expect($char)->toBe(new Char('A'))
|
expect($char)->toBe(new Char('A'))
|
||||||
->and($state)
|
->and($state)
|
||||||
->runCount->toMatchArray([
|
->runCount->toMatchArray([
|
||||||
'char' => 1,
|
'char' => 1,
|
||||||
'number' => 0,
|
'number' => 0,
|
||||||
'wildcard' => 0,
|
'wildcard' => 0,
|
||||||
'symbol' => 0,
|
'symbol' => 0,
|
||||||
])
|
])
|
||||||
->appliedCount->toMatchArray([
|
->appliedCount->toMatchArray([
|
||||||
'char' => 1,
|
'char' => 1,
|
||||||
'number' => 0,
|
'number' => 0,
|
||||||
'wildcard' => 0,
|
'wildcard' => 0,
|
||||||
'symbol' => 0,
|
'symbol' => 0,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -152,16 +152,16 @@ test('pipe is run and can let the pipeline keep going', function () use ($state)
|
|||||||
expect(3)->toBe(3)
|
expect(3)->toBe(3)
|
||||||
->and($state)
|
->and($state)
|
||||||
->runCount->toMatchArray([
|
->runCount->toMatchArray([
|
||||||
'char' => 1,
|
'char' => 1,
|
||||||
'number' => 0,
|
'number' => 0,
|
||||||
'wildcard' => 0,
|
'wildcard' => 0,
|
||||||
'symbol' => 1,
|
'symbol' => 1,
|
||||||
])
|
])
|
||||||
->appliedCount->toMatchArray([
|
->appliedCount->toMatchArray([
|
||||||
'char' => 0,
|
'char' => 0,
|
||||||
'number' => 0,
|
'number' => 0,
|
||||||
'wildcard' => 0,
|
'wildcard' => 0,
|
||||||
'symbol' => 0,
|
'symbol' => 0,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -173,16 +173,16 @@ test('pipe works with negated expectation', function () use ($state) {
|
|||||||
expect($char)->not->toBe(new Char('B'))
|
expect($char)->not->toBe(new Char('B'))
|
||||||
->and($state)
|
->and($state)
|
||||||
->runCount->toMatchArray([
|
->runCount->toMatchArray([
|
||||||
'char' => 1,
|
'char' => 1,
|
||||||
'number' => 0,
|
'number' => 0,
|
||||||
'wildcard' => 0,
|
'wildcard' => 0,
|
||||||
'symbol' => 0,
|
'symbol' => 0,
|
||||||
])
|
])
|
||||||
->appliedCount->toMatchArray([
|
->appliedCount->toMatchArray([
|
||||||
'char' => 1,
|
'char' => 1,
|
||||||
'number' => 0,
|
'number' => 0,
|
||||||
'wildcard' => 0,
|
'wildcard' => 0,
|
||||||
'symbol' => 0,
|
'symbol' => 0,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -205,16 +205,16 @@ test('interceptor stops the pipeline', function () use ($state) {
|
|||||||
expect($number)->toBe(new Number(1))
|
expect($number)->toBe(new Number(1))
|
||||||
->and($state)
|
->and($state)
|
||||||
->runCount->toMatchArray([
|
->runCount->toMatchArray([
|
||||||
'char' => 1,
|
'char' => 1,
|
||||||
'number' => 1,
|
'number' => 1,
|
||||||
'wildcard' => 0,
|
'wildcard' => 0,
|
||||||
'symbol' => 0,
|
'symbol' => 0,
|
||||||
])
|
])
|
||||||
->appliedCount->toMatchArray([
|
->appliedCount->toMatchArray([
|
||||||
'char' => 0,
|
'char' => 0,
|
||||||
'number' => 1,
|
'number' => 1,
|
||||||
'wildcard' => 0,
|
'wildcard' => 0,
|
||||||
'symbol' => 0,
|
'symbol' => 0,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use PHPUnit\Framework\ExpectationFailedException;
|
|||||||
expect(true)->toBeTrue()->and(false)->toBeFalse();
|
expect(true)->toBeTrue()->and(false)->toBeFalse();
|
||||||
|
|
||||||
test('strict comparisons', function () {
|
test('strict comparisons', function () {
|
||||||
$nuno = new stdClass();
|
$nuno = new stdClass();
|
||||||
$dries = new stdClass();
|
$dries = new stdClass();
|
||||||
|
|
||||||
expect($nuno)->toBe($nuno)->not->toBe($dries);
|
expect($nuno)->toBe($nuno)->not->toBe($dries);
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
touch($this->tempFile = sys_get_temp_dir() . '/fake.file');
|
touch($this->tempFile = sys_get_temp_dir().'/fake.file');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
touch($this->tempFile = sys_get_temp_dir() . '/fake.file');
|
touch($this->tempFile = sys_get_temp_dir().'/fake.file');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
touch($this->tempFile = sys_get_temp_dir() . '/fake.file');
|
touch($this->tempFile = sys_get_temp_dir().'/fake.file');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
|
|||||||
@ -3,24 +3,24 @@
|
|||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
test('pass', function () {
|
test('pass', function () {
|
||||||
$object = new stdClass();
|
$object = new stdClass();
|
||||||
$object->name = 'Jhon';
|
$object->name = 'Jhon';
|
||||||
$object->age = 21;
|
$object->age = 21;
|
||||||
|
|
||||||
expect($object)->toHaveProperties(['name', 'age']);
|
expect($object)->toHaveProperties(['name', 'age']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('failures', function () {
|
test('failures', function () {
|
||||||
$object = new stdClass();
|
$object = new stdClass();
|
||||||
$object->name = 'Jhon';
|
$object->name = 'Jhon';
|
||||||
|
|
||||||
expect($object)->toHaveProperties(['name', 'age']);
|
expect($object)->toHaveProperties(['name', 'age']);
|
||||||
})->throws(ExpectationFailedException::class);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
test('not failures', function () {
|
test('not failures', function () {
|
||||||
$object = new stdClass();
|
$object = new stdClass();
|
||||||
$object->name = 'Jhon';
|
$object->name = 'Jhon';
|
||||||
$object->age = 21;
|
$object->age = 21;
|
||||||
|
|
||||||
expect($object)->not->toHaveProperties(['name', 'age']);
|
expect($object)->not->toHaveProperties(['name', 'age']);
|
||||||
})->throws(ExpectationFailedException::class);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
$obj = new stdClass();
|
$obj = new stdClass();
|
||||||
$obj->foo = 'bar';
|
$obj->foo = 'bar';
|
||||||
$obj->fooNull = null;
|
$obj->fooNull = null;
|
||||||
|
|
||||||
test('pass', function () use ($obj) {
|
test('pass', function () use ($obj) {
|
||||||
|
|||||||
@ -4,22 +4,22 @@ use PHPUnit\Framework\ExpectationFailedException;
|
|||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
$this->user = [
|
$this->user = [
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'name' => 'Nuno',
|
'name' => 'Nuno',
|
||||||
'email' => 'enunomaduro@gmail.com',
|
'email' => 'enunomaduro@gmail.com',
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
test('pass', function () {
|
test('pass', function () {
|
||||||
expect($this->user)->toMatchArray([
|
expect($this->user)->toMatchArray([
|
||||||
'name' => 'Nuno',
|
'name' => 'Nuno',
|
||||||
'email' => 'enunomaduro@gmail.com',
|
'email' => 'enunomaduro@gmail.com',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('failures', function () {
|
test('failures', function () {
|
||||||
expect($this->user)->toMatchArray([
|
expect($this->user)->toMatchArray([
|
||||||
'name' => 'Not the same name',
|
'name' => 'Not the same name',
|
||||||
'email' => 'enunomaduro@gmail.com',
|
'email' => 'enunomaduro@gmail.com',
|
||||||
]);
|
]);
|
||||||
})->throws(ExpectationFailedException::class);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|||||||
@ -4,33 +4,34 @@ use PHPUnit\Framework\ExpectationFailedException;
|
|||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
$this->user = (object) [
|
$this->user = (object) [
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'name' => 'Nuno',
|
'name' => 'Nuno',
|
||||||
'email' => 'enunomaduro@gmail.com',
|
'email' => 'enunomaduro@gmail.com',
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
test('pass', function () {
|
test('pass', function () {
|
||||||
expect($this->user)->toMatchObject([
|
expect($this->user)->toMatchObject([
|
||||||
'name' => 'Nuno',
|
'name' => 'Nuno',
|
||||||
'email' => 'enunomaduro@gmail.com',
|
'email' => 'enunomaduro@gmail.com',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('pass with class', function () {
|
test('pass with class', function () {
|
||||||
expect(new class() {
|
expect(new class()
|
||||||
|
{
|
||||||
public $name = 'Nuno';
|
public $name = 'Nuno';
|
||||||
|
|
||||||
public $email = 'enunomaduro@gmail.com';
|
public $email = 'enunomaduro@gmail.com';
|
||||||
})->toMatchObject([
|
})->toMatchObject([
|
||||||
'name' => 'Nuno',
|
'name' => 'Nuno',
|
||||||
'email' => 'enunomaduro@gmail.com',
|
'email' => 'enunomaduro@gmail.com',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('failures', function () {
|
test('failures', function () {
|
||||||
expect($this->user)->toMatchObject([
|
expect($this->user)->toMatchObject([
|
||||||
'name' => 'Not the same name',
|
'name' => 'Not the same name',
|
||||||
'email' => 'enunomaduro@gmail.com',
|
'email' => 'enunomaduro@gmail.com',
|
||||||
]);
|
]);
|
||||||
})->throws(ExpectationFailedException::class);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|||||||
@ -38,13 +38,13 @@ test('passes', function () {
|
|||||||
test('failures 1', function () {
|
test('failures 1', function () {
|
||||||
expect(function () {
|
expect(function () {
|
||||||
})->toThrow(RuntimeException::class);
|
})->toThrow(RuntimeException::class);
|
||||||
})->throws(ExpectationFailedException::class, 'Exception "' . RuntimeException::class . '" not thrown.');
|
})->throws(ExpectationFailedException::class, 'Exception "'.RuntimeException::class.'" not thrown.');
|
||||||
|
|
||||||
test('failures 2', function () {
|
test('failures 2', function () {
|
||||||
expect(function () {
|
expect(function () {
|
||||||
})->toThrow(function (RuntimeException $e) {
|
})->toThrow(function (RuntimeException $e) {
|
||||||
});
|
});
|
||||||
})->throws(ExpectationFailedException::class, 'Exception "' . RuntimeException::class . '" not thrown.');
|
})->throws(ExpectationFailedException::class, 'Exception "'.RuntimeException::class.'" not thrown.');
|
||||||
|
|
||||||
test('failures 3', function () {
|
test('failures 3', function () {
|
||||||
expect(function () {
|
expect(function () {
|
||||||
|
|||||||
@ -3,9 +3,9 @@
|
|||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
$this->unlessObject = new stdClass();
|
$this->unlessObject = new stdClass();
|
||||||
$this->unlessObject->trueValue = true;
|
$this->unlessObject->trueValue = true;
|
||||||
$this->unlessObject->foo = 'foo';
|
$this->unlessObject->foo = 'foo';
|
||||||
});
|
});
|
||||||
|
|
||||||
it('pass', function () {
|
it('pass', function () {
|
||||||
|
|||||||
@ -3,9 +3,9 @@
|
|||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
$this->whenObject = new stdClass();
|
$this->whenObject = new stdClass();
|
||||||
$this->whenObject->trueValue = true;
|
$this->whenObject->trueValue = true;
|
||||||
$this->whenObject->foo = 'foo';
|
$this->whenObject->foo = 'foo';
|
||||||
});
|
});
|
||||||
|
|
||||||
it('pass', function () {
|
it('pass', function () {
|
||||||
|
|||||||
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
use function PHPUnit\Framework\assertFalse;
|
use function PHPUnit\Framework\assertFalse;
|
||||||
|
|
||||||
$foo = new stdClass();
|
$foo = new stdClass();
|
||||||
$foo->beforeAll = false;
|
$foo->beforeAll = false;
|
||||||
$foo->beforeEach = false;
|
$foo->beforeEach = false;
|
||||||
$foo->afterEach = false;
|
$foo->afterEach = false;
|
||||||
$foo->afterAll = false;
|
$foo->afterAll = false;
|
||||||
|
|
||||||
beforeAll(function () {
|
beforeAll(function () {
|
||||||
$foo->beforeAll = true;
|
$foo->beforeAll = true;
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use Pest\Support\Str;
|
|||||||
|
|
||||||
// HACK: we have to determine our $_SERVER['globalHook-]>calls baseline. This is because
|
// HACK: we have to determine our $_SERVER['globalHook-]>calls baseline. This is because
|
||||||
// two other tests are executed before this one due to filename ordering.
|
// two other tests are executed before this one due to filename ordering.
|
||||||
$args = $_SERVER['argv'] ?? [];
|
$args = $_SERVER['argv'] ?? [];
|
||||||
$single = (isset($args[1]) && Str::endsWith(__FILE__, $args[1])) || ($_SERVER['PEST_PARALLEL'] ?? false);
|
$single = (isset($args[1]) && Str::endsWith(__FILE__, $args[1])) || ($_SERVER['PEST_PARALLEL'] ?? false);
|
||||||
$offset = $single ? 0 : 2;
|
$offset = $single ? 0 : 2;
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||||||
namespace Tests\CustomTestCase;
|
namespace Tests\CustomTestCase;
|
||||||
|
|
||||||
use function PHPUnit\Framework\assertTrue;
|
use function PHPUnit\Framework\assertTrue;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
abstract class CustomTestCase extends TestCase
|
abstract class CustomTestCase extends TestCase
|
||||||
|
|||||||
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||||||
namespace Tests\CustomTestCase;
|
namespace Tests\CustomTestCase;
|
||||||
|
|
||||||
use function PHPUnit\Framework\assertTrue;
|
use function PHPUnit\Framework\assertTrue;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ExecutedTest extends TestCase
|
class ExecutedTest extends TestCase
|
||||||
|
|||||||
@ -34,7 +34,7 @@ it('show only the names of multiple named datasets in their description', functi
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'three' => [3],
|
'three' => [3],
|
||||||
'four' => [[4]],
|
'four' => [[4]],
|
||||||
],
|
],
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Pest\Plugins\Version;
|
use Pest\Plugins\Version;
|
||||||
|
|
||||||
use function Pest\version;
|
use function Pest\version;
|
||||||
|
|
||||||
use Symfony\Component\Console\Output\BufferedOutput;
|
use Symfony\Component\Console\Output\BufferedOutput;
|
||||||
|
|
||||||
it('outputs the version when --version is used', function () {
|
it('outputs the version when --version is used', function () {
|
||||||
@ -11,7 +9,7 @@ it('outputs the version when --version is used', function () {
|
|||||||
$plugin = new Version($output);
|
$plugin = new Version($output);
|
||||||
|
|
||||||
$plugin->handleArguments(['foo', '--version']);
|
$plugin->handleArguments(['foo', '--version']);
|
||||||
expect($output->fetch())->toContain('Pest ' . version());
|
expect($output->fetch())->toContain('Pest '.version());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('do not outputs version when --version is not used', function () {
|
it('do not outputs version when --version is not used', function () {
|
||||||
|
|||||||
@ -10,7 +10,8 @@ it('gets file name from closure', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('gets property values', function () {
|
it('gets property values', function () {
|
||||||
$class = new class() {
|
$class = new class()
|
||||||
|
{
|
||||||
private $foo = 'bar';
|
private $foo = 'bar';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ use Pest\TestSuite;
|
|||||||
|
|
||||||
it('does not allow to add the same test description twice', function () {
|
it('does not allow to add the same test description twice', function () {
|
||||||
$testSuite = new TestSuite(getcwd(), 'tests');
|
$testSuite = new TestSuite(getcwd(), 'tests');
|
||||||
$method = new TestCaseMethodFactory('foo', 'bar', null);
|
$method = new TestCaseMethodFactory('foo', 'bar', null);
|
||||||
|
|
||||||
$testSuite->tests->set($method);
|
$testSuite->tests->set($method);
|
||||||
$testSuite->tests->set($method);
|
$testSuite->tests->set($method);
|
||||||
@ -44,7 +44,7 @@ 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 () {
|
it('can filter the test suite filenames to those with the only method', function () {
|
||||||
$testSuite = new TestSuite(getcwd(), 'tests');
|
$testSuite = new TestSuite(getcwd(), 'tests');
|
||||||
|
|
||||||
$testWithOnly = new TestCaseMethodFactory('a', 'b', null);
|
$testWithOnly = new TestCaseMethodFactory('a', 'b', null);
|
||||||
$testWithOnly->only = true;
|
$testWithOnly->only = true;
|
||||||
$testSuite->tests->set($testWithOnly);
|
$testSuite->tests->set($testWithOnly);
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ it('does not filter the test suite filenames to those with the only method when
|
|||||||
$test = function () {
|
$test = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
$testWithOnly = new TestCaseMethodFactory('a', 'b', null);
|
$testWithOnly = new TestCaseMethodFactory('a', 'b', null);
|
||||||
$testWithOnly->only = true;
|
$testWithOnly->only = true;
|
||||||
$testSuite->tests->set($testWithOnly);
|
$testSuite->tests->set($testWithOnly);
|
||||||
|
|
||||||
|
|||||||
@ -4,18 +4,18 @@ use Pest\Console\Help;
|
|||||||
use Symfony\Component\Console\Output\BufferedOutput;
|
use Symfony\Component\Console\Output\BufferedOutput;
|
||||||
|
|
||||||
test('visual snapshot of help command output', function () {
|
test('visual snapshot of help command output', function () {
|
||||||
$snapshot = __DIR__ . '/../.snapshots/help-command.txt';
|
$snapshot = __DIR__.'/../.snapshots/help-command.txt';
|
||||||
|
|
||||||
if (getenv('REBUILD_SNAPSHOTS')) {
|
if (getenv('REBUILD_SNAPSHOTS')) {
|
||||||
$outputBuffer = new BufferedOutput();
|
$outputBuffer = new BufferedOutput();
|
||||||
$plugin = new Help($outputBuffer);
|
$plugin = new Help($outputBuffer);
|
||||||
|
|
||||||
$plugin();
|
$plugin();
|
||||||
|
|
||||||
file_put_contents($snapshot, $outputBuffer->fetch());
|
file_put_contents($snapshot, $outputBuffer->fetch());
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = function () {
|
$output = function () {
|
||||||
$process = (new Symfony\Component\Process\Process(['php', 'bin/pest', '--help'], null, ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true']));
|
$process = (new Symfony\Component\Process\Process(['php', 'bin/pest', '--help'], null, ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true']));
|
||||||
|
|
||||||
$process->run();
|
$process->run();
|
||||||
|
|||||||
@ -6,11 +6,11 @@ use PHPUnit\Framework\TestSuite;
|
|||||||
use PHPUnit\Framework\Warning;
|
use PHPUnit\Framework\Warning;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
file_put_contents(__DIR__ . '/junit.html', '');
|
file_put_contents(__DIR__.'/junit.html', '');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is can successfully call all public methods', function () {
|
it('is can successfully call all public methods', function () {
|
||||||
$junit = new JUnit(__DIR__ . '/junit.html');
|
$junit = new JUnit(__DIR__.'/junit.html');
|
||||||
$junit->startTestSuite(new TestSuite());
|
$junit->startTestSuite(new TestSuite());
|
||||||
$junit->startTest($this);
|
$junit->startTest($this);
|
||||||
$junit->addError($this, new Exception(), 0);
|
$junit->addError($this, new Exception(), 0);
|
||||||
@ -25,5 +25,5 @@ it('is can successfully call all public methods', function () {
|
|||||||
})->skip('Not supported yet.');
|
})->skip('Not supported yet.');
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
unlink(__DIR__ . '/junit.html');
|
unlink(__DIR__.'/junit.html');
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
$run = function (string $target, $decorated = false) {
|
$run = function (string $target, $decorated = false) {
|
||||||
$process = new Process(['php', 'bin/pest', $target, '--colors=always'], dirname(__DIR__, 2),
|
$process = new Process(['php', 'bin/pest', $target, '--colors=always'], dirname(__DIR__, 2),
|
||||||
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'],
|
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'],
|
||||||
);
|
);
|
||||||
@ -12,7 +12,7 @@ $run = function (string $target, $decorated = false) {
|
|||||||
return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||||
};
|
};
|
||||||
|
|
||||||
$snapshot = function ($name) {
|
$snapshot = function ($name) {
|
||||||
$testsPath = dirname(__DIR__);
|
$testsPath = dirname(__DIR__);
|
||||||
|
|
||||||
return file_get_contents(implode(DIRECTORY_SEPARATOR, [
|
return file_get_contents(implode(DIRECTORY_SEPARATOR, [
|
||||||
|
|||||||
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
test('visual snapshot of test suite on success', function () {
|
test('visual snapshot of test suite on success', function () {
|
||||||
$testsPath = dirname(__DIR__);
|
$testsPath = dirname(__DIR__);
|
||||||
$snapshot = implode(DIRECTORY_SEPARATOR, [
|
$snapshot = implode(DIRECTORY_SEPARATOR, [
|
||||||
$testsPath,
|
$testsPath,
|
||||||
'.snapshots',
|
'.snapshots',
|
||||||
'success.txt',
|
'success.txt',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$output = function () use ($testsPath) {
|
$output = function () use ($testsPath) {
|
||||||
$process = (new Symfony\Component\Process\Process(
|
$process = (new Symfony\Component\Process\Process(
|
||||||
['php', 'bin/pest'],
|
['php', 'bin/pest'],
|
||||||
dirname($testsPath),
|
dirname($testsPath),
|
||||||
@ -31,12 +31,12 @@ test('visual snapshot of test suite on success', function () {
|
|||||||
$outputContent = preg_replace('/Time\: \s+\d+\.\d+s\s+/m', '', $output());
|
$outputContent = preg_replace('/Time\: \s+\d+\.\d+s\s+/m', '', $output());
|
||||||
|
|
||||||
file_put_contents($snapshot, $outputContent);
|
file_put_contents($snapshot, $outputContent);
|
||||||
} elseif (!getenv('EXCLUDE')) {
|
} elseif (! getenv('EXCLUDE')) {
|
||||||
$output = explode("\n", $output());
|
$output = explode("\n", $output());
|
||||||
array_pop($output);
|
array_pop($output);
|
||||||
array_pop($output);
|
array_pop($output);
|
||||||
|
|
||||||
expect(implode("\n", $output))->toContain(file_get_contents($snapshot));
|
expect(implode("\n", $output))->toContain(file_get_contents($snapshot));
|
||||||
}
|
}
|
||||||
})->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE'))
|
})->skip(! getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE'))
|
||||||
->skip(PHP_OS_FAMILY === 'Windows');
|
->skip(PHP_OS_FAMILY === 'Windows');
|
||||||
|
|||||||
@ -8,11 +8,11 @@ use PHPUnit\Framework\Warning;
|
|||||||
use PHPUnit\TextUI\DefaultResultPrinter;
|
use PHPUnit\TextUI\DefaultResultPrinter;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
file_put_contents(__DIR__ . '/output.txt', '');
|
file_put_contents(__DIR__.'/output.txt', '');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is can successfully call all public methods', function () {
|
it('is can successfully call all public methods', function () {
|
||||||
$teamCity = new TeamCity(__DIR__ . '/output.txt', false, DefaultResultPrinter::COLOR_ALWAYS);
|
$teamCity = new TeamCity(__DIR__.'/output.txt', false, DefaultResultPrinter::COLOR_ALWAYS);
|
||||||
expect($teamCity::isPestTest($this))->toBeTrue();
|
expect($teamCity::isPestTest($this))->toBeTrue();
|
||||||
$teamCity->startTestSuite(new TestSuite());
|
$teamCity->startTestSuite(new TestSuite());
|
||||||
$teamCity->startTest($this);
|
$teamCity->startTest($this);
|
||||||
@ -28,5 +28,5 @@ it('is can successfully call all public methods', function () {
|
|||||||
})->skip('Not supported yet.');
|
})->skip('Not supported yet.');
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
unlink(__DIR__ . '/output.txt');
|
unlink(__DIR__.'/output.txt');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user