mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
Compare commits
49 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dd2921fd26 | |||
| 977dbb5bcb | |||
| 49de462250 | |||
| 95e8add29b | |||
| b682fe631d | |||
| d32a648af5 | |||
| 50e9978dc3 | |||
| 17d407a26a | |||
| cdc3bd3f45 | |||
| 95b4192c0d | |||
| 4c911cd0eb | |||
| 7408999b0e | |||
| bb13bdaa80 | |||
| 10e7cbe006 | |||
| 0ad232e9de | |||
| 574cd11a40 | |||
| c04d6d946d | |||
| 36c2a985a6 | |||
| 91eff755fd | |||
| c05d287fcc | |||
| ea0be9e7a4 | |||
| 838ac273ab | |||
| 296e1c37e8 | |||
| 3117f11fae | |||
| 294c41f0dc | |||
| 60afbb2c20 | |||
| 19a45c856e | |||
| 3b784060b8 | |||
| dd5a11a61f | |||
| 9133b88d65 | |||
| 93b9afbd27 | |||
| 6c6bba2a04 | |||
| dd24b7e347 | |||
| ce896b9c83 | |||
| a3c1a61b59 | |||
| 98c62f4b1d | |||
| dd78cc9a50 | |||
| 9027411004 | |||
| 9394aa4649 | |||
| 88dc74bbe4 | |||
| 7023cec432 | |||
| 99d6fb9f5f | |||
| c9f723530d | |||
| 3205b571b0 | |||
| 2c4aef5272 | |||
| 4a45a7cc6b | |||
| ea8ab88056 | |||
| 564a21badd | |||
| 41ce87450f |
27
CHANGELOG.md
27
CHANGELOG.md
@ -4,6 +4,33 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [v1.4.0 (2021-06-10)](https://github.com/pestphp/pest/compare/v1.3.2...v1.4.0)
|
||||
### Added
|
||||
- Support for multiple datasets (Matrix) on the `with` method ([#303](https://github.com/pestphp/pest/pull/303))
|
||||
- Support for incompleted tests ([49de462](https://github.com/pestphp/pest/commit/49de462250cf9f65f09e13eaf6dcc0e06865b930))
|
||||
|
||||
## [v1.3.2 (2021-06-07)](https://github.com/pestphp/pest/compare/v1.3.1...v1.3.2)
|
||||
### Fixed
|
||||
- Test cases with the @ symbol in the directory fail ([#308](https://github.com/pestphp/pest/pull/308))
|
||||
|
||||
## [v1.3.1 (2021-06-06)](https://github.com/pestphp/pest/compare/v1.3.0...v1.3.1)
|
||||
### Added
|
||||
- Added for PHPUnit 9.5.5 ([#310](https://github.com/pestphp/pest/pull/310))
|
||||
|
||||
### Changed
|
||||
- Lock minimum Pest plugin versions ([#306](https://github.com/pestphp/pest/pull/306))
|
||||
|
||||
## [v1.3.0 (2021-05-23)](https://github.com/pestphp/pest/compare/v1.2.1...v1.3.0)
|
||||
### Added
|
||||
- Named datasets no longer show the arguments ([#302](https://github.com/pestphp/pest/pull/302))
|
||||
|
||||
### Fixed
|
||||
- Wraps global functions within `function_exists` ([#300](https://github.com/pestphp/pest/pull/300))
|
||||
|
||||
## [v1.2.1 (2021-05-14)](https://github.com/pestphp/pest/compare/v1.2.0...v1.2.1)
|
||||
### Fixed
|
||||
- Laravel commands failing with new `--test-directory` option ([#297](https://github.com/pestphp/pest/pull/297))
|
||||
|
||||
## [v1.2.0 (2021-05-13)](https://github.com/pestphp/pest/compare/v1.1.0...v1.2.0)
|
||||
### Added
|
||||
- Adds JUnit / Infection support ([#291](https://github.com/pestphp/pest/pull/291))
|
||||
|
||||
@ -21,9 +21,9 @@
|
||||
"nunomaduro/collision": "^5.0",
|
||||
"pestphp/pest-plugin": "^1.0",
|
||||
"pestphp/pest-plugin-coverage": "^1.0",
|
||||
"pestphp/pest-plugin-expectations": "^1.0",
|
||||
"pestphp/pest-plugin-init": "^1.0",
|
||||
"phpunit/phpunit": ">= 9.3.7 <= 9.5.4"
|
||||
"pestphp/pest-plugin-expectations": "^1.6",
|
||||
"pestphp/pest-plugin-init": "^1.1",
|
||||
"phpunit/phpunit": ">= 9.3.7 <= 9.5.5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@ -46,7 +46,6 @@
|
||||
"illuminate/console": "^8.32.1",
|
||||
"illuminate/support": "^8.32.1",
|
||||
"laravel/dusk": "^6.13.0",
|
||||
"mockery/mockery": "^1.4.3",
|
||||
"pestphp/pest-dev-tools": "dev-master"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
|
||||
@ -51,36 +51,34 @@ final class Datasets
|
||||
/**
|
||||
* Resolves the current dataset to an array value.
|
||||
*
|
||||
* @param Traversable<int|string, mixed>|Closure|iterable<int|string, mixed>|string|null $data
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $datasets
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function resolve(string $description, $data): array
|
||||
public static function resolve(string $description, array $datasets): array
|
||||
{
|
||||
/* @phpstan-ignore-next-line */
|
||||
if (is_null($data) || empty($data)) {
|
||||
if (empty($datasets)) {
|
||||
return [$description => []];
|
||||
}
|
||||
|
||||
if (is_string($data)) {
|
||||
$data = self::get($data);
|
||||
}
|
||||
$datasets = self::processDatasets($datasets);
|
||||
|
||||
if (is_callable($data)) {
|
||||
$data = call_user_func($data);
|
||||
}
|
||||
|
||||
if ($data instanceof Traversable) {
|
||||
$data = iterator_to_array($data);
|
||||
}
|
||||
$datasetCombinations = self::getDataSetsCombinations($datasets);
|
||||
|
||||
$dataSetDescriptions = [];
|
||||
$dataSetValues = [];
|
||||
|
||||
foreach ($data as $key => $values) {
|
||||
$values = is_array($values) ? $values : [$values];
|
||||
foreach ($datasetCombinations as $datasetCombination) {
|
||||
$partialDescriptions = [];
|
||||
$values = [];
|
||||
|
||||
$dataSetDescriptions[] = $description . self::getDataSetDescription($key, $values);
|
||||
foreach ($datasetCombination as $dataset_data) {
|
||||
$partialDescriptions[] = $dataset_data['label'];
|
||||
$values = array_merge($values, $dataset_data['values']);
|
||||
}
|
||||
|
||||
$dataSetDescriptions[] = $description . ' with ' . implode(' / ', $partialDescriptions);
|
||||
$dataSetValues[] = $values;
|
||||
}
|
||||
|
||||
@ -103,6 +101,65 @@ final class Datasets
|
||||
return $namedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Closure|iterable<int|string, mixed>|string> $datasets
|
||||
*
|
||||
* @return array<array>
|
||||
*/
|
||||
private static function processDatasets(array $datasets): array
|
||||
{
|
||||
$processedDatasets = [];
|
||||
|
||||
foreach ($datasets as $index => $data) {
|
||||
$processedDataset = [];
|
||||
|
||||
if (is_string($data)) {
|
||||
$datasets[$index] = self::get($data);
|
||||
}
|
||||
|
||||
if (is_callable($datasets[$index])) {
|
||||
$datasets[$index] = call_user_func($datasets[$index]);
|
||||
}
|
||||
|
||||
if ($datasets[$index] instanceof Traversable) {
|
||||
$datasets[$index] = iterator_to_array($datasets[$index]);
|
||||
}
|
||||
|
||||
foreach ($datasets[$index] as $key => $values) {
|
||||
$values = is_array($values) ? $values : [$values];
|
||||
$processedDataset[] = [
|
||||
'label' => self::getDataSetDescription($key, $values),
|
||||
'values' => $values,
|
||||
];
|
||||
}
|
||||
|
||||
$processedDatasets[] = $processedDataset;
|
||||
}
|
||||
|
||||
return $processedDatasets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<array> $combinations
|
||||
*
|
||||
* @return array<array>
|
||||
*/
|
||||
private static function getDataSetsCombinations(array $combinations): array
|
||||
{
|
||||
$result = [[]];
|
||||
foreach ($combinations as $index => $values) {
|
||||
$tmp = [];
|
||||
foreach ($result as $resultItem) {
|
||||
foreach ($values as $value) {
|
||||
$tmp[] = array_merge($resultItem, [$index => $value]);
|
||||
}
|
||||
}
|
||||
$result = $tmp;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|string $key
|
||||
* @param array<int, mixed> $data
|
||||
@ -111,8 +168,10 @@ final class Datasets
|
||||
{
|
||||
$exporter = new Exporter();
|
||||
|
||||
$nameInsert = is_string($key) ? \sprintf('data set "%s" ', $key) : '';
|
||||
if (is_int($key)) {
|
||||
return \sprintf('(%s)', $exporter->shortenedRecursiveExport($data));
|
||||
}
|
||||
|
||||
return \sprintf(' with %s(%s)', $nameInsert, $exporter->shortenedRecursiveExport($data));
|
||||
return \sprintf('data set "%s"', $key);
|
||||
}
|
||||
}
|
||||
|
||||
24
src/Exceptions/MissingDependency.php
Normal file
24
src/Exceptions/MissingDependency.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Exceptions;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use NunoMaduro\Collision\Contracts\RenderlessEditor;
|
||||
use NunoMaduro\Collision\Contracts\RenderlessTrace;
|
||||
use Symfony\Component\Console\Exception\ExceptionInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class MissingDependency extends InvalidArgumentException implements ExceptionInterface, RenderlessEditor, RenderlessTrace
|
||||
{
|
||||
/**
|
||||
* Creates a new instance of missing dependency.
|
||||
*/
|
||||
public function __construct(string $feature, string $dependency)
|
||||
{
|
||||
parent::__construct(sprintf('The feature "%s" requires "%s".', $feature, $dependency));
|
||||
}
|
||||
}
|
||||
@ -11,9 +11,9 @@ use Pest\Contracts\HasPrintableTestCaseName;
|
||||
use Pest\Datasets;
|
||||
use Pest\Exceptions\ShouldNotHappen;
|
||||
use Pest\Support\HigherOrderMessageCollection;
|
||||
use Pest\Support\NullClosure;
|
||||
use Pest\Support\Str;
|
||||
use Pest\TestSuite;
|
||||
use PHPUnit\Framework\Assert;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RuntimeException;
|
||||
|
||||
@ -62,9 +62,9 @@ final class TestCaseFactory
|
||||
/**
|
||||
* Holds the dataset, if any.
|
||||
*
|
||||
* @var Closure|iterable<int|string, mixed>|string|null
|
||||
* @var array<Closure|iterable<int|string, mixed>|string>
|
||||
*/
|
||||
public $dataset;
|
||||
public $datasets = [];
|
||||
|
||||
/**
|
||||
* The FQN of the test case class.
|
||||
@ -113,7 +113,11 @@ final class TestCaseFactory
|
||||
{
|
||||
$this->filename = $filename;
|
||||
$this->description = $description;
|
||||
$this->test = $closure ?? NullClosure::create();
|
||||
$this->test = $closure ?? function (): void {
|
||||
if (Assert::getCount() === 0) {
|
||||
self::markTestIncomplete(); // @phpstan-ignore-line
|
||||
}
|
||||
};
|
||||
|
||||
$this->factoryProxies = new HigherOrderMessageCollection();
|
||||
$this->proxies = new HigherOrderMessageCollection();
|
||||
@ -155,7 +159,7 @@ final class TestCaseFactory
|
||||
return $testCase;
|
||||
};
|
||||
|
||||
$datasets = Datasets::resolve($this->description, $this->dataset);
|
||||
$datasets = Datasets::resolve($this->description, $this->datasets);
|
||||
|
||||
return array_map($createTest, array_keys($datasets), $datasets);
|
||||
}
|
||||
|
||||
@ -12,95 +12,111 @@ use Pest\Support\HigherOrderTapProxy;
|
||||
use Pest\TestSuite;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Runs the given closure before all tests in the current file.
|
||||
*/
|
||||
function beforeAll(Closure $closure): void
|
||||
{
|
||||
TestSuite::getInstance()->beforeAll->set($closure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the given closure before each test in the current file.
|
||||
*
|
||||
* @return BeforeEachCall|TestCase|mixed
|
||||
*/
|
||||
function beforeEach(Closure $closure = null): BeforeEachCall
|
||||
{
|
||||
$filename = Backtrace::file();
|
||||
|
||||
return new BeforeEachCall(TestSuite::getInstance(), $filename, $closure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the given dataset.
|
||||
*
|
||||
* @param Closure|iterable<int|string, mixed> $dataset
|
||||
*/
|
||||
function dataset(string $name, $dataset): void
|
||||
{
|
||||
Datasets::set($name, $dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* The uses function binds the given
|
||||
* arguments to test closures.
|
||||
*/
|
||||
function uses(string ...$classAndTraits): UsesCall
|
||||
{
|
||||
$filename = Backtrace::file();
|
||||
|
||||
return new UsesCall($filename, $classAndTraits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given closure as a test. The first argument
|
||||
* is the test description; the second argument is
|
||||
* a closure that contains the test expectations.
|
||||
*
|
||||
* @return TestCall|TestCase|mixed
|
||||
*/
|
||||
function test(string $description = null, Closure $closure = null)
|
||||
{
|
||||
if ($description === null && TestSuite::getInstance()->test !== null) {
|
||||
return new HigherOrderTapProxy(TestSuite::getInstance()->test);
|
||||
if (!function_exists('beforeAll')) {
|
||||
/**
|
||||
* Runs the given closure before all tests in the current file.
|
||||
*/
|
||||
function beforeAll(Closure $closure): void
|
||||
{
|
||||
TestSuite::getInstance()->beforeAll->set($closure);
|
||||
}
|
||||
|
||||
$filename = Backtrace::testFile();
|
||||
|
||||
return new TestCall(TestSuite::getInstance(), $filename, $description, $closure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given closure as a test. The first argument
|
||||
* is the test description; the second argument is
|
||||
* a closure that contains the test expectations.
|
||||
*
|
||||
* @return TestCall|TestCase|mixed
|
||||
*/
|
||||
function it(string $description, Closure $closure = null): TestCall
|
||||
{
|
||||
$description = sprintf('it %s', $description);
|
||||
if (!function_exists('beforeEach')) {
|
||||
/**
|
||||
* Runs the given closure before each test in the current file.
|
||||
*
|
||||
* @return BeforeEachCall|TestCase|mixed
|
||||
*/
|
||||
function beforeEach(Closure $closure = null): BeforeEachCall
|
||||
{
|
||||
$filename = Backtrace::file();
|
||||
|
||||
return test($description, $closure);
|
||||
return new BeforeEachCall(TestSuite::getInstance(), $filename, $closure);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the given closure after each test in the current file.
|
||||
*
|
||||
* @return AfterEachCall|TestCase|mixed
|
||||
*/
|
||||
function afterEach(Closure $closure = null): AfterEachCall
|
||||
{
|
||||
$filename = Backtrace::file();
|
||||
|
||||
return new AfterEachCall(TestSuite::getInstance(), $filename, $closure);
|
||||
if (!function_exists('dataset')) {
|
||||
/**
|
||||
* Registers the given dataset.
|
||||
*
|
||||
* @param Closure|iterable<int|string, mixed> $dataset
|
||||
*/
|
||||
function dataset(string $name, $dataset): void
|
||||
{
|
||||
Datasets::set($name, $dataset);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the given closure after all tests in the current file.
|
||||
*/
|
||||
function afterAll(Closure $closure): void
|
||||
{
|
||||
TestSuite::getInstance()->afterAll->set($closure);
|
||||
if (!function_exists('uses')) {
|
||||
/**
|
||||
* The uses function binds the given
|
||||
* arguments to test closures.
|
||||
*/
|
||||
function uses(string ...$classAndTraits): UsesCall
|
||||
{
|
||||
$filename = Backtrace::file();
|
||||
|
||||
return new UsesCall($filename, $classAndTraits);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('test')) {
|
||||
/**
|
||||
* Adds the given closure as a test. The first argument
|
||||
* is the test description; the second argument is
|
||||
* a closure that contains the test expectations.
|
||||
*
|
||||
* @return TestCall|TestCase|mixed
|
||||
*/
|
||||
function test(string $description = null, Closure $closure = null)
|
||||
{
|
||||
if ($description === null && TestSuite::getInstance()->test !== null) {
|
||||
return new HigherOrderTapProxy(TestSuite::getInstance()->test);
|
||||
}
|
||||
|
||||
$filename = Backtrace::testFile();
|
||||
|
||||
return new TestCall(TestSuite::getInstance(), $filename, $description, $closure);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('it')) {
|
||||
/**
|
||||
* Adds the given closure as a test. The first argument
|
||||
* is the test description; the second argument is
|
||||
* a closure that contains the test expectations.
|
||||
*
|
||||
* @return TestCall|TestCase|mixed
|
||||
*/
|
||||
function it(string $description, Closure $closure = null): TestCall
|
||||
{
|
||||
$description = sprintf('it %s', $description);
|
||||
|
||||
return test($description, $closure);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('afterEach')) {
|
||||
/**
|
||||
* Runs the given closure after each test in the current file.
|
||||
*
|
||||
* @return AfterEachCall|TestCase|mixed
|
||||
*/
|
||||
function afterEach(Closure $closure = null): AfterEachCall
|
||||
{
|
||||
$filename = Backtrace::file();
|
||||
|
||||
return new AfterEachCall(TestSuite::getInstance(), $filename, $closure);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('afterAll')) {
|
||||
/**
|
||||
* Runs the given closure after all tests in the current file.
|
||||
*/
|
||||
function afterAll(Closure $closure): void
|
||||
{
|
||||
TestSuite::getInstance()->afterAll->set($closure);
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
use Pest\Exceptions\InvalidConsoleArgument;
|
||||
use function Pest\testDirectory;
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -20,7 +21,8 @@ final class PestDatasetCommand extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'pest:dataset {name : The name of the dataset}';
|
||||
protected $signature = 'pest:dataset {name : The name of the dataset}
|
||||
{--test-directory=tests : The name of the tests directory}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@ -34,6 +36,9 @@ final class PestDatasetCommand extends Command
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
/* @phpstan-ignore-next-line */
|
||||
TestSuite::getInstance(base_path(), $this->option('test-directory'));
|
||||
|
||||
/** @var string $name */
|
||||
$name = $this->argument('name');
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ use Illuminate\Support\Facades\File;
|
||||
use Pest\Console\Thanks;
|
||||
use Pest\Exceptions\InvalidConsoleArgument;
|
||||
use function Pest\testDirectory;
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -20,7 +21,7 @@ final class PestInstallCommand extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'pest:install';
|
||||
protected $signature = 'pest:install {--test-directory=tests : The name of the tests directory}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@ -34,6 +35,9 @@ final class PestInstallCommand extends Command
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
/* @phpstan-ignore-next-line */
|
||||
TestSuite::getInstance(base_path(), $this->option('test-directory'));
|
||||
|
||||
/* @phpstan-ignore-next-line */
|
||||
$pest = base_path(testDirectory('Pest.php'));
|
||||
$stubs = 'stubs/Laravel';
|
||||
|
||||
@ -9,6 +9,7 @@ use Illuminate\Support\Facades\File;
|
||||
use Pest\Exceptions\InvalidConsoleArgument;
|
||||
use Pest\Support\Str;
|
||||
use function Pest\testDirectory;
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -20,7 +21,7 @@ final class PestTestCommand extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'pest:test {name : The name of the file} {--unit : Create a unit test} {--dusk : Create a Dusk test}';
|
||||
protected $signature = 'pest:test {name : The name of the file} {--unit : Create a unit test} {--dusk : Create a Dusk test} {--test-directory=tests : The name of the tests directory}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@ -34,12 +35,16 @@ final class PestTestCommand extends Command
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
/* @phpstan-ignore-next-line */
|
||||
TestSuite::getInstance(base_path(), $this->option('test-directory'));
|
||||
|
||||
/** @var string $name */
|
||||
$name = $this->argument('name');
|
||||
|
||||
$type = ((bool) $this->option('unit')) ? 'Unit' : (((bool) $this->option('dusk')) ? 'Browser' : 'Feature');
|
||||
|
||||
$relativePath = sprintf(testDirectory('%s/%s.php'),
|
||||
$relativePath = sprintf(
|
||||
testDirectory('%s/%s.php'),
|
||||
$type,
|
||||
ucfirst($name)
|
||||
);
|
||||
|
||||
@ -77,11 +77,13 @@ final class TestCall
|
||||
* Runs the current test multiple times with
|
||||
* each item of the given `iterable`.
|
||||
*
|
||||
* @param \Closure|iterable<int|string, mixed>|string $data
|
||||
* @param array<\Closure|iterable<int|string, mixed>|string> $data
|
||||
*/
|
||||
public function with($data): TestCall
|
||||
public function with(...$data): TestCall
|
||||
{
|
||||
$this->testCaseFactory->dataset = $data;
|
||||
foreach ($data as $dataset) {
|
||||
$this->testCaseFactory->datasets[] = $dataset;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ namespace Pest;
|
||||
|
||||
function version(): string
|
||||
{
|
||||
return '1.2.0';
|
||||
return '1.3.2';
|
||||
}
|
||||
|
||||
function testDirectory(string $file = ''): string
|
||||
|
||||
@ -41,7 +41,6 @@ final class AfterEachRepository
|
||||
|
||||
return ChainableClosure::from(function (): void {
|
||||
if (class_exists(Mockery::class)) {
|
||||
/* @phpstan-ignore-next-line */
|
||||
if ($container = Mockery::getContainer()) {
|
||||
/* @phpstan-ignore-next-line */
|
||||
$this->addToAssertionCount($container->mockery_getExpectationCount());
|
||||
|
||||
@ -19,6 +19,11 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
final class TestRepository
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const SEPARATOR = '>>>';
|
||||
|
||||
/**
|
||||
* @var array<string, TestCaseFactory>
|
||||
*/
|
||||
@ -50,7 +55,7 @@ final class TestRepository
|
||||
[$classOrTraits, $groups, $hooks] = $uses;
|
||||
|
||||
$setClassName = function (TestCaseFactory $testCase, string $key) use ($path, $classOrTraits, $groups, $startsWith, $hooks): void {
|
||||
[$filename] = explode('@', $key);
|
||||
[$filename] = explode(self::SEPARATOR, $key);
|
||||
|
||||
if ((!is_dir($path) && $filename === $path) || (is_dir($path) && $startsWith($filename, $path))) {
|
||||
foreach ($classOrTraits as $class) { /** @var string $class */
|
||||
@ -131,10 +136,10 @@ final class TestRepository
|
||||
throw ShouldNotHappen::fromMessage('Trying to create a test without description.');
|
||||
}
|
||||
|
||||
if (array_key_exists(sprintf('%s@%s', $test->filename, $test->description), $this->state)) {
|
||||
if (array_key_exists(sprintf('%s%s%s', $test->filename, self::SEPARATOR, $test->description), $this->state)) {
|
||||
throw new TestAlreadyExist($test->filename, $test->description);
|
||||
}
|
||||
|
||||
$this->state[sprintf('%s@%s', $test->filename, $test->description)] = $test;
|
||||
$this->state[sprintf('%s%s%s', $test->filename, self::SEPARATOR, $test->description)] = $test;
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,8 +40,8 @@
|
||||
✓ eager wrapped registered datasets with (1)
|
||||
✓ eager wrapped registered datasets with (2)
|
||||
✓ eager registered wrapped datasets did the job right
|
||||
✓ named datasets with data set "one" (1)
|
||||
✓ named datasets with data set "two" (2)
|
||||
✓ named datasets with data set "one"
|
||||
✓ named datasets with data set "two"
|
||||
✓ named datasets did the job right
|
||||
✓ lazy named datasets with (Bar Object (...))
|
||||
✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #1
|
||||
@ -51,6 +51,45 @@
|
||||
✓ it creates unique test case names with ('Name 2', Pest\Plugin Object (), true)
|
||||
✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #3
|
||||
✓ it creates unique test case names - count
|
||||
✓ lazy multiple datasets with (1) / (3)
|
||||
✓ lazy multiple datasets with (1) / (4)
|
||||
✓ lazy multiple datasets with (2) / (3)
|
||||
✓ lazy multiple datasets with (2) / (4)
|
||||
✓ lazy multiple datasets did the job right
|
||||
✓ eager multiple datasets with (1) / (3)
|
||||
✓ eager multiple datasets with (1) / (4)
|
||||
✓ eager multiple datasets with (2) / (3)
|
||||
✓ eager multiple datasets with (2) / (4)
|
||||
✓ eager multiple datasets did the job right
|
||||
✓ lazy registered multiple datasets with (1) / (1)
|
||||
✓ lazy registered multiple datasets with (1) / (2)
|
||||
✓ lazy registered multiple datasets with (2) / (1)
|
||||
✓ lazy registered multiple datasets with (2) / (2)
|
||||
✓ lazy registered multiple datasets did the job right
|
||||
✓ eager registered multiple datasets with (1) / (1)
|
||||
✓ eager registered multiple datasets with (1) / (2)
|
||||
✓ eager registered multiple datasets with (2) / (1)
|
||||
✓ eager registered multiple datasets with (2) / (2)
|
||||
✓ eager registered multiple datasets did the job right
|
||||
✓ eager wrapped registered multiple datasets with (1) / (1)
|
||||
✓ eager wrapped registered multiple datasets with (1) / (2)
|
||||
✓ eager wrapped registered multiple datasets with (2) / (1)
|
||||
✓ eager wrapped registered multiple datasets with (2) / (2)
|
||||
✓ eager wrapped registered multiple datasets did the job right
|
||||
✓ named multiple datasets with data set "one" / data set "three"
|
||||
✓ named multiple datasets with data set "one" / data set "four"
|
||||
✓ named multiple datasets with data set "two" / data set "three"
|
||||
✓ named multiple datasets with data set "two" / data set "four"
|
||||
✓ named multiple datasets did the job right
|
||||
✓ more than two datasets with (1) / (3) / (5)
|
||||
✓ more than two datasets with (1) / (3) / (6)
|
||||
✓ more than two datasets with (1) / (4) / (5)
|
||||
✓ more than two datasets with (1) / (4) / (6)
|
||||
✓ more than two datasets with (2) / (3) / (5)
|
||||
✓ more than two datasets with (2) / (3) / (6)
|
||||
✓ more than two datasets with (2) / (4) / (5)
|
||||
✓ more than two datasets with (2) / (4) / (6)
|
||||
✓ more than two datasets did the job right
|
||||
|
||||
PASS Tests\Features\Exceptions
|
||||
✓ it gives access the the underlying expectException
|
||||
@ -63,11 +102,21 @@
|
||||
✓ it allows to call underlying protected/private methods
|
||||
✓ it throws error if method do not exist
|
||||
✓ it can forward unexpected calls to any global function
|
||||
✓ it can use helpers from helpers file
|
||||
|
||||
PASS Tests\Features\HigherOrderTests
|
||||
✓ it proxies calls to object
|
||||
✓ it is capable doing multiple assertions
|
||||
|
||||
WARN Tests\Features\Incompleted
|
||||
… incompleted
|
||||
… it is incompleted
|
||||
… it is incompleted even with method calls like skip
|
||||
… it is incompleted even with method calls like group
|
||||
✓ it is not incompleted because of expect
|
||||
✓ it is not incompleted because of assert
|
||||
✓ it is not incompleted because of test with assertions
|
||||
|
||||
PASS Tests\Features\It
|
||||
✓ it is a test
|
||||
✓ it is a higher order message test
|
||||
@ -76,10 +125,8 @@
|
||||
✓ it can call chained macro method
|
||||
✓ it will throw exception from call if no macro exists
|
||||
|
||||
PASS Tests\Features\Mocks
|
||||
✓ it has bar
|
||||
|
||||
PASS Tests\Features\PendingHigherOrderTests
|
||||
✓ get 'foo'
|
||||
✓ get 'foo' → get 'bar' → expect true → toBeTrue
|
||||
✓ get 'foo' → expect true → toBeTrue
|
||||
|
||||
@ -124,6 +171,10 @@
|
||||
PASS Tests\PHPUnit\CustomAffixes\AdditionalFileExtensionspec
|
||||
✓ it runs file names like `AdditionalFileExtension.spec.php`
|
||||
|
||||
PASS Tests\PHPUnit\CustomAffixes\FolderWithAn\ExampleTest
|
||||
✓ custom traits can be used
|
||||
✓ trait applied in this file
|
||||
|
||||
PASS Tests\PHPUnit\CustomAffixes\ManyExtensionsclasstest
|
||||
✓ it runs file names like `ManyExtensions.class.test.php`
|
||||
|
||||
@ -170,7 +221,11 @@
|
||||
✓ it outputs the help information when --help is used
|
||||
|
||||
PASS Tests\Unit\Datasets
|
||||
✓ it show the names of named datasets in their description
|
||||
✓ it show only the names of named datasets in their description
|
||||
✓ it show the actual dataset of non-named datasets in their description
|
||||
✓ it show only the names of multiple named datasets in their description
|
||||
✓ it show the actual dataset of multiple non-named datasets in their description
|
||||
✓ it show the correct description for mixed named and not-named datasets
|
||||
|
||||
PASS Tests\Unit\Plugins\Version
|
||||
✓ it outputs the version when --version is used
|
||||
@ -221,5 +276,5 @@
|
||||
✓ it is a test
|
||||
✓ it uses correct parent class
|
||||
|
||||
Tests: 7 skipped, 119 passed
|
||||
Tests: 4 incompleted, 7 skipped, 168 passed
|
||||
|
||||
@ -8,11 +8,11 @@ beforeAll(function () use ($foo) {
|
||||
});
|
||||
|
||||
it('gets executed before tests', function () use ($foo) {
|
||||
expect($foo->bar)->toBe(1);
|
||||
expect($foo)->bar->toBe(1);
|
||||
|
||||
$foo->bar = 'changed';
|
||||
});
|
||||
|
||||
it('do not get executed before each test', function () use ($foo) {
|
||||
expect($foo->bar)->toBe('changed');
|
||||
expect($foo)->bar->toBe('changed');
|
||||
});
|
||||
|
||||
@ -137,3 +137,89 @@ it('creates unique test case names', function (string $name, Plugin $plugin, boo
|
||||
it('creates unique test case names - count', function () use (&$counter) {
|
||||
expect($counter)->toBe(6);
|
||||
});
|
||||
|
||||
$datasets_a = [[1], [2]];
|
||||
$datasets_b = [[3], [4]];
|
||||
|
||||
test('lazy multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) {
|
||||
$state->text .= $text_a . $text_b;
|
||||
expect($datasets_a)->toContain([$text_a]);
|
||||
expect($datasets_b)->toContain([$text_b]);
|
||||
})->with($datasets_a, $datasets_b);
|
||||
|
||||
test('lazy multiple datasets did the job right', function () use ($state) {
|
||||
expect($state->text)->toBe('12121212121213142324');
|
||||
});
|
||||
|
||||
$state->text = '';
|
||||
|
||||
test('eager multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) {
|
||||
$state->text .= $text_a . $text_b;
|
||||
expect($datasets_a)->toContain([$text_a]);
|
||||
expect($datasets_b)->toContain([$text_b]);
|
||||
})->with(function () use ($datasets_a) {
|
||||
return $datasets_a;
|
||||
})->with(function () use ($datasets_b) {
|
||||
return $datasets_b;
|
||||
});
|
||||
|
||||
test('eager multiple datasets did the job right', function () use ($state) {
|
||||
expect($state->text)->toBe('1212121212121314232413142324');
|
||||
});
|
||||
|
||||
test('lazy registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) {
|
||||
$state->text .= $text_a . $text_b;
|
||||
expect($datasets)->toContain([$text_a]);
|
||||
expect($datasets)->toContain([$text_b]);
|
||||
})->with('numbers.array')->with('numbers.array');
|
||||
|
||||
test('lazy registered multiple datasets did the job right', function () use ($state) {
|
||||
expect($state->text)->toBe('121212121212131423241314232411122122');
|
||||
});
|
||||
|
||||
test('eager registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) {
|
||||
$state->text .= $text_a . $text_b;
|
||||
expect($datasets)->toContain([$text_a]);
|
||||
expect($datasets)->toContain([$text_b]);
|
||||
})->with('numbers.array')->with('numbers.closure');
|
||||
|
||||
test('eager registered multiple datasets did the job right', function () use ($state) {
|
||||
expect($state->text)->toBe('12121212121213142324131423241112212211122122');
|
||||
});
|
||||
|
||||
test('eager wrapped registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) {
|
||||
$state->text .= $text_a . $text_b;
|
||||
expect($datasets)->toContain([$text_a]);
|
||||
expect($datasets)->toContain([$text_b]);
|
||||
})->with('numbers.closure.wrapped')->with('numbers.closure');
|
||||
|
||||
test('eager wrapped registered multiple datasets did the job right', function () use ($state) {
|
||||
expect($state->text)->toBe('1212121212121314232413142324111221221112212211122122');
|
||||
});
|
||||
|
||||
test('named multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) {
|
||||
$state->text .= $text_a . $text_b;
|
||||
expect($datasets_a)->toContain([$text_a]);
|
||||
expect($datasets_b)->toContain([$text_b]);
|
||||
})->with([
|
||||
'one' => [1],
|
||||
'two' => [2],
|
||||
])->with([
|
||||
'three' => [3],
|
||||
'four' => [4],
|
||||
]);
|
||||
|
||||
test('named multiple datasets did the job right', function () use ($state) {
|
||||
expect($state->text)->toBe('121212121212131423241314232411122122111221221112212213142324');
|
||||
});
|
||||
|
||||
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;
|
||||
expect($datasets_a)->toContain([$text_a]);
|
||||
expect($datasets_b)->toContain([$text_b]);
|
||||
expect([5, 6])->toContain($text_c);
|
||||
})->with($datasets_a, $datasets_b)->with([5, 6]);
|
||||
|
||||
test('more than two datasets did the job right', function () use ($state) {
|
||||
expect($state->text)->toBe('121212121212131423241314232411122122111221221112212213142324135136145146235236245246');
|
||||
});
|
||||
|
||||
@ -42,3 +42,5 @@ it('throws error if method do not exist', function () {
|
||||
})->throws(\ReflectionException::class, 'Call to undefined method PHPUnit\Framework\TestCase::name()');
|
||||
|
||||
it('can forward unexpected calls to any global function')->_assertThat();
|
||||
|
||||
it('can use helpers from helpers file')->myAssertTrue(true);
|
||||
|
||||
17
tests/Features/Incompleted.php
Normal file
17
tests/Features/Incompleted.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
test('incompleted');
|
||||
|
||||
it('is incompleted');
|
||||
|
||||
it('is incompleted even with method calls like skip')->skip(false);
|
||||
|
||||
it('is incompleted even with method calls like group')->group('wtv');
|
||||
|
||||
it('is not incompleted because of expect')->expect(true)->toBeTrue();
|
||||
|
||||
it('is not incompleted because of assert')->assertTrue(true);
|
||||
|
||||
it('is not incompleted because of test with assertions', function () {
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
it('is a test', function () {
|
||||
$this->assertArrayHasKey('key', ['key' => 'foo']);
|
||||
expect(['key' => 'foo'])->toHaveKey('key')->key->toBeString();
|
||||
});
|
||||
|
||||
it('is a higher order message test')->expect(true)->toBeTrue();
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
use function Tests\mock;
|
||||
|
||||
interface Foo
|
||||
{
|
||||
public function bar(): int;
|
||||
}
|
||||
|
||||
it('has bar', function () {
|
||||
$mock = mock(Foo::class);
|
||||
$mock->shouldReceive('bar')
|
||||
->times(1)
|
||||
->andReturn(2);
|
||||
|
||||
$mock->bar();
|
||||
});
|
||||
@ -26,5 +26,6 @@ trait Gettable
|
||||
}
|
||||
}
|
||||
|
||||
get('foo'); // not incomplete because closure is created...
|
||||
get('foo')->get('bar')->expect(true)->toBeTrue();
|
||||
get('foo')->expect(true)->toBeTrue();
|
||||
|
||||
@ -1,11 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
|
||||
function mock(string $class): MockInterface
|
||||
function myAssertTrue($value)
|
||||
{
|
||||
return Mockery::mock($class);
|
||||
test()->assertTrue($value);
|
||||
}
|
||||
|
||||
19
tests/PHPUnit/CustomAffixes/FolderWithAn@/ExampleTest.php
Normal file
19
tests/PHPUnit/CustomAffixes/FolderWithAn@/ExampleTest.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
class MyCustomClassTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function assertTrueIsTrue()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
uses(MyCustomClassTest::class);
|
||||
|
||||
test('custom traits can be used', function () {
|
||||
$this->assertTrueIsTrue();
|
||||
});
|
||||
|
||||
test('trait applied in this file')->assertTrueIsTrue();
|
||||
@ -2,12 +2,80 @@
|
||||
|
||||
use Pest\Datasets;
|
||||
|
||||
it('show the names of named datasets in their description', function () {
|
||||
it('show only the names of named datasets in their description', function () {
|
||||
$descriptions = array_keys(Datasets::resolve('test description', [
|
||||
'one' => [1],
|
||||
'two' => [[2]],
|
||||
[
|
||||
'one' => [1],
|
||||
'two' => [[2]],
|
||||
],
|
||||
]));
|
||||
|
||||
expect($descriptions[0])->toBe('test description with data set "one" (1)');
|
||||
expect($descriptions[1])->toBe('test description with data set "two" (array(2))');
|
||||
expect($descriptions[0])->toBe('test description with data set "one"');
|
||||
expect($descriptions[1])->toBe('test description with data set "two"');
|
||||
});
|
||||
|
||||
it('show the actual dataset of non-named datasets in their description', function () {
|
||||
$descriptions = array_keys(Datasets::resolve('test description', [
|
||||
[
|
||||
[1],
|
||||
[[2]],
|
||||
],
|
||||
]));
|
||||
|
||||
expect($descriptions[0])->toBe('test description with (1)');
|
||||
expect($descriptions[1])->toBe('test description with (array(2))');
|
||||
});
|
||||
|
||||
it('show only the names of multiple named datasets in their description', function () {
|
||||
$descriptions = array_keys(Datasets::resolve('test description', [
|
||||
[
|
||||
'one' => [1],
|
||||
'two' => [[2]],
|
||||
],
|
||||
[
|
||||
'three' => [3],
|
||||
'four' => [[4]],
|
||||
],
|
||||
]));
|
||||
|
||||
expect($descriptions[0])->toBe('test description with data set "one" / data set "three"');
|
||||
expect($descriptions[1])->toBe('test description with data set "one" / data set "four"');
|
||||
expect($descriptions[2])->toBe('test description with data set "two" / data set "three"');
|
||||
expect($descriptions[3])->toBe('test description with data set "two" / data set "four"');
|
||||
});
|
||||
|
||||
it('show the actual dataset of multiple non-named datasets in their description', function () {
|
||||
$descriptions = array_keys(Datasets::resolve('test description', [
|
||||
[
|
||||
[1],
|
||||
[[2]],
|
||||
],
|
||||
[
|
||||
[3],
|
||||
[[4]],
|
||||
],
|
||||
]));
|
||||
|
||||
expect($descriptions[0])->toBe('test description with (1) / (3)');
|
||||
expect($descriptions[1])->toBe('test description with (1) / (array(4))');
|
||||
expect($descriptions[2])->toBe('test description with (array(2)) / (3)');
|
||||
expect($descriptions[3])->toBe('test description with (array(2)) / (array(4))');
|
||||
});
|
||||
|
||||
it('show the correct description for mixed named and not-named datasets', function () {
|
||||
$descriptions = array_keys(Datasets::resolve('test description', [
|
||||
[
|
||||
'one' => [1],
|
||||
[[2]],
|
||||
],
|
||||
[
|
||||
[3],
|
||||
'four' => [[4]],
|
||||
],
|
||||
]));
|
||||
|
||||
expect($descriptions[0])->toBe('test description with data set "one" / (3)');
|
||||
expect($descriptions[1])->toBe('test description with data set "one" / data set "four"');
|
||||
expect($descriptions[2])->toBe('test description with (array(2)) / (3)');
|
||||
expect($descriptions[3])->toBe('test description with (array(2)) / data set "four"');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user