mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
Merge branch 'master' into fix-missing-dataset-errors
This commit is contained in:
15
CHANGELOG.md
15
CHANGELOG.md
@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
## [v1.13.0 (2021-07-28)](https://github.com/pestphp/pest/compare/v1.12.0...v1.13.0)
|
||||||
|
### Added
|
||||||
|
- `toBeIn` expectation ([#363](https://github.com/pestphp/pest/pull/363))
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `skip` with false condition marking test as skipped ([22b822c](https://github.com/pestphp/pest/commit/22b822ce87a3d19d84960fa5c93eb286820b525d))
|
||||||
|
|
||||||
|
## [v1.12.0 (2021-07-26)](https://github.com/pestphp/pest/compare/v1.11.0...v1.12.0)
|
||||||
|
### Added
|
||||||
|
- `--force` option to override tests in `pest:test` artisan command ([#353](https://github.com/pestphp/pest/pull/353))
|
||||||
|
- Support for PHPUnit `^9.3.7` ([ca9d783](https://github.com/pestphp/pest/commit/ca9d783cf942a2caabc85ff7a728c7f28350c67a))
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `beforeAll` and `afterAll` behind called multiple times per test ([#357](https://github.com/pestphp/pest/pull/357))
|
||||||
|
|
||||||
## [v1.11.0 (2021-07-21)](https://github.com/pestphp/pest/compare/v1.10.0...v1.11.0)
|
## [v1.11.0 (2021-07-21)](https://github.com/pestphp/pest/compare/v1.10.0...v1.11.0)
|
||||||
### Added
|
### Added
|
||||||
- Support for interacting with datasets in higher order tests ([#352](https://github.com/pestphp/pest/pull/352))
|
- Support for interacting with datasets in higher order tests ([#352](https://github.com/pestphp/pest/pull/352))
|
||||||
|
|||||||
@ -22,8 +22,9 @@ We would like to extend our thanks to the following sponsors for funding Pest de
|
|||||||
### Premium Sponsors
|
### Premium Sponsors
|
||||||
|
|
||||||
- **[Akaunting](https://akaunting.com)**
|
- **[Akaunting](https://akaunting.com)**
|
||||||
- **[Scout APM](https://scoutapm.com)**
|
- **[Codecourse](https://codecourse.com/)**
|
||||||
- **[Meema](https://meema.io/)**
|
- **[Meema](https://meema.io/)**
|
||||||
|
- **[Scout APM](https://scoutapm.com)**
|
||||||
- **[Spatie](https://spatie.be/)**
|
- **[Spatie](https://spatie.be/)**
|
||||||
|
|
||||||
Pest was created by **[Nuno Maduro](https://twitter.com/enunomaduro)** under the **[Sponsorware license](https://github.com/sponsorware/docs)**. It got open-sourced and is now licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.
|
Pest is an open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
"php": "^7.3 || ^8.0",
|
"php": "^7.3 || ^8.0",
|
||||||
"nunomaduro/collision": "^5.4.0",
|
"nunomaduro/collision": "^5.4.0",
|
||||||
"pestphp/pest-plugin": "^1.0.0",
|
"pestphp/pest-plugin": "^1.0.0",
|
||||||
"phpunit/phpunit": ">= 9.3.7 <= 9.5.6"
|
"phpunit/phpunit": "^9.3.7"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
@ -73,6 +73,8 @@ trait Testable
|
|||||||
{
|
{
|
||||||
$this->__test = $test;
|
$this->__test = $test;
|
||||||
$this->__description = $description;
|
$this->__description = $description;
|
||||||
|
self::$beforeAll = null;
|
||||||
|
self::$afterAll = null;
|
||||||
|
|
||||||
parent::__construct('__test', $data);
|
parent::__construct('__test', $data);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -371,6 +371,18 @@ final class Expectation
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the value is one of the given values.
|
||||||
|
*
|
||||||
|
* @param iterable<int|string, mixed> $values
|
||||||
|
*/
|
||||||
|
public function toBeIn(iterable $values): Expectation
|
||||||
|
{
|
||||||
|
Assert::assertContains($this->value, $values);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the value is infinite.
|
* Asserts that the value is infinite.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -21,7 +21,7 @@ final class PestTestCommand extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
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}';
|
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} {--force : Overwrite the existing test file with the same name}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@ -56,7 +56,7 @@ final class PestTestCommand extends Command
|
|||||||
File::makeDirectory(dirname($target), 0777, true, true);
|
File::makeDirectory(dirname($target), 0777, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (File::exists($target)) {
|
if (File::exists($target) && !(bool) $this->option('force')) {
|
||||||
throw new InvalidConsoleArgument(sprintf('%s already exist', $target));
|
throw new InvalidConsoleArgument(sprintf('%s already exist', $target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -150,6 +150,9 @@ final class TestCall
|
|||||||
? $conditionOrMessage
|
? $conditionOrMessage
|
||||||
: $message;
|
: $message;
|
||||||
|
|
||||||
|
/** @var callable(): bool $condition */
|
||||||
|
$condition = $condition->bindTo(null);
|
||||||
|
|
||||||
$this->testCaseFactory
|
$this->testCaseFactory
|
||||||
->chains
|
->chains
|
||||||
->addWhen($condition, Backtrace::file(), Backtrace::line(), 'markTestSkipped', [$message]);
|
->addWhen($condition, Backtrace::file(), Backtrace::line(), 'markTestSkipped', [$message]);
|
||||||
|
|||||||
@ -6,7 +6,7 @@ namespace Pest;
|
|||||||
|
|
||||||
function version(): string
|
function version(): string
|
||||||
{
|
{
|
||||||
return '1.11.0';
|
return '1.13.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDirectory(string $file = ''): string
|
function testDirectory(string $file = ''): string
|
||||||
|
|||||||
@ -101,6 +101,7 @@
|
|||||||
✓ it gives access the the underlying expectException
|
✓ it gives access the the underlying expectException
|
||||||
✓ it catch exceptions
|
✓ it catch exceptions
|
||||||
✓ it catch exceptions and messages
|
✓ it catch exceptions and messages
|
||||||
|
✓ it can just define the message
|
||||||
|
|
||||||
PASS Tests\Features\Expect\HigherOrder\methods
|
PASS Tests\Features\Expect\HigherOrder\methods
|
||||||
✓ it can access methods
|
✓ it can access methods
|
||||||
@ -112,11 +113,14 @@
|
|||||||
✓ it works with sequence
|
✓ it works with sequence
|
||||||
✓ it can compose complex expectations
|
✓ it can compose complex expectations
|
||||||
✓ it can handle nested method calls
|
✓ it can handle nested method calls
|
||||||
|
✓ it works with higher order tests
|
||||||
|
|
||||||
PASS Tests\Features\Expect\HigherOrder\methodsAndProperties
|
PASS Tests\Features\Expect\HigherOrder\methodsAndProperties
|
||||||
✓ it can access methods and properties
|
✓ it can access methods and properties
|
||||||
✓ it can handle nested methods and properties
|
✓ it can handle nested methods and properties
|
||||||
|
✓ it works with higher order tests
|
||||||
✓ it can start a new higher order expectation using the and syntax
|
✓ it can start a new higher order expectation using the and syntax
|
||||||
|
✓ it can start a new higher order expectation using the and syntax in higher order tests
|
||||||
|
|
||||||
PASS Tests\Features\Expect\HigherOrder\properties
|
PASS Tests\Features\Expect\HigherOrder\properties
|
||||||
✓ it allows properties to be accessed from the value
|
✓ it allows properties to be accessed from the value
|
||||||
@ -128,6 +132,7 @@
|
|||||||
✓ it can compose complex expectations
|
✓ it can compose complex expectations
|
||||||
✓ it works with objects
|
✓ it works with objects
|
||||||
✓ it works with nested properties
|
✓ it works with nested properties
|
||||||
|
✓ it works with higher order tests
|
||||||
|
|
||||||
PASS Tests\Features\Expect\each
|
PASS Tests\Features\Expect\each
|
||||||
✓ an exception is thrown if the the type is not iterable
|
✓ an exception is thrown if the the type is not iterable
|
||||||
@ -216,6 +221,11 @@
|
|||||||
PASS Tests\Features\Expect\toBeGreatherThanOrEqual
|
PASS Tests\Features\Expect\toBeGreatherThanOrEqual
|
||||||
✓ passes
|
✓ passes
|
||||||
✓ failures
|
✓ failures
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Features\Expect\toBeIn
|
||||||
|
✓ passes
|
||||||
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toBeInfinite
|
PASS Tests\Features\Expect\toBeInfinite
|
||||||
@ -411,7 +421,12 @@
|
|||||||
✓ it proxies calls to object
|
✓ it proxies calls to object
|
||||||
✓ it is capable doing multiple assertions
|
✓ it is capable doing multiple assertions
|
||||||
✓ it resolves expect callables correctly
|
✓ it resolves expect callables correctly
|
||||||
|
✓ does not treat method names as callables
|
||||||
✓ it can tap into the test
|
✓ it can tap into the test
|
||||||
|
✓ it can pass datasets into the expect callables with (1, 2, 3)
|
||||||
|
✓ it can pass datasets into the tap callable with (1, 2, 3)
|
||||||
|
✓ it can pass shared datasets into callables with (1)
|
||||||
|
✓ it can pass shared datasets into callables with (2)
|
||||||
|
|
||||||
WARN Tests\Features\Incompleted
|
WARN Tests\Features\Incompleted
|
||||||
… incompleted
|
… incompleted
|
||||||
@ -432,8 +447,8 @@
|
|||||||
|
|
||||||
PASS Tests\Features\PendingHigherOrderTests
|
PASS Tests\Features\PendingHigherOrderTests
|
||||||
✓ get 'foo'
|
✓ get 'foo'
|
||||||
✓ get 'foo' → get 'bar' → expect true → toBeTrue
|
✓ get 'foo' → get 'bar' → expect true → toBeTrue
|
||||||
✓ get 'foo' → expect true → toBeTrue
|
✓ get 'foo' → expect true → toBeTrue
|
||||||
|
|
||||||
WARN Tests\Features\Skip
|
WARN Tests\Features\Skip
|
||||||
✓ it do not skips
|
✓ it do not skips
|
||||||
@ -444,6 +459,8 @@
|
|||||||
✓ it do not skips with falsy closure condition
|
✓ it do not skips with falsy closure condition
|
||||||
- it skips with condition and message → skipped because foo
|
- it skips with condition and message → skipped because foo
|
||||||
- it skips when skip after assertion
|
- it skips when skip after assertion
|
||||||
|
- it can use something in the test case as a condition → This test was skipped
|
||||||
|
- it can user higher order callables and skip
|
||||||
|
|
||||||
PASS Tests\Features\Test
|
PASS Tests\Features\Test
|
||||||
✓ a test
|
✓ a test
|
||||||
@ -457,12 +474,14 @@
|
|||||||
|
|
||||||
PASS Tests\Hooks\AfterAllTest
|
PASS Tests\Hooks\AfterAllTest
|
||||||
✓ global afterAll execution order
|
✓ global afterAll execution order
|
||||||
|
✓ it only gets called once per file
|
||||||
|
|
||||||
PASS Tests\Hooks\AfterEachTest
|
PASS Tests\Hooks\AfterEachTest
|
||||||
✓ global afterEach execution order
|
✓ global afterEach execution order
|
||||||
|
|
||||||
PASS Tests\Hooks\BeforeAllTest
|
PASS Tests\Hooks\BeforeAllTest
|
||||||
✓ global beforeAll execution order
|
✓ global beforeAll execution order
|
||||||
|
✓ it only gets called once per file
|
||||||
|
|
||||||
PASS Tests\Hooks\BeforeEachTest
|
PASS Tests\Hooks\BeforeEachTest
|
||||||
✓ global beforeEach execution order
|
✓ global beforeEach execution order
|
||||||
@ -582,5 +601,5 @@
|
|||||||
✓ it is a test
|
✓ it is a test
|
||||||
✓ it uses correct parent class
|
✓ it uses correct parent class
|
||||||
|
|
||||||
Tests: 4 incompleted, 7 skipped, 365 passed
|
Tests: 4 incompleted, 9 skipped, 381 passed
|
||||||
|
|
||||||
16
tests/Features/Expect/toBeIn.php
Normal file
16
tests/Features/Expect/toBeIn.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
test('passes', function () {
|
||||||
|
expect('a')->toBeIn(['a', 'b', 'c']);
|
||||||
|
expect('d')->not->toBeIn(['a', 'b', 'c']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('failures', function () {
|
||||||
|
expect('d')->toBeIn(['a', 'b', 'c']);
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('not failures', function () {
|
||||||
|
expect('a')->not->toBeIn(['a', 'b', 'c']);
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
@ -2,26 +2,50 @@
|
|||||||
|
|
||||||
global $globalHook;
|
global $globalHook;
|
||||||
|
|
||||||
|
// NOTE: this test does not have a $globalHook->calls offset since it is first
|
||||||
|
// in the directory and thus will always run before the others. See also the
|
||||||
|
// BeforeAllTest.php for details.
|
||||||
|
|
||||||
uses()->afterAll(function () use ($globalHook) {
|
uses()->afterAll(function () use ($globalHook) {
|
||||||
expect($globalHook)
|
expect($globalHook)
|
||||||
->toHaveProperty('afterAll')
|
->toHaveProperty('afterAll')
|
||||||
->and($globalHook->afterAll)
|
->and($globalHook->afterAll)
|
||||||
->toBe(0);
|
->toBe(0)
|
||||||
|
->and($globalHook->calls)
|
||||||
|
->afterAll
|
||||||
|
->toBe(1);
|
||||||
|
|
||||||
$globalHook->afterAll = 1;
|
$globalHook->afterAll = 1;
|
||||||
|
$globalHook->calls->afterAll++;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(function () use ($globalHook) {
|
afterAll(function () use ($globalHook) {
|
||||||
expect($globalHook)
|
expect($globalHook)
|
||||||
->toHaveProperty('afterAll')
|
->toHaveProperty('afterAll')
|
||||||
->and($globalHook->afterAll)
|
->and($globalHook->afterAll)
|
||||||
->toBe(1);
|
->toBe(1)
|
||||||
|
->and($globalHook->calls)
|
||||||
|
->afterAll
|
||||||
|
->toBe(2);
|
||||||
|
|
||||||
$globalHook->afterAll = 2;
|
$globalHook->afterAll = 2;
|
||||||
|
$globalHook->calls->afterAll++;
|
||||||
});
|
});
|
||||||
|
|
||||||
test('global afterAll execution order', function () use ($globalHook) {
|
test('global afterAll execution order', function () use ($globalHook) {
|
||||||
expect($globalHook)
|
expect($globalHook)
|
||||||
->not()
|
->not()
|
||||||
->toHaveProperty('afterAll');
|
->toHaveProperty('afterAll')
|
||||||
|
->and($globalHook->calls)
|
||||||
|
->afterAll
|
||||||
|
->toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('only gets called once per file', function () use ($globalHook) {
|
||||||
|
expect($globalHook)
|
||||||
|
->not()
|
||||||
|
->toHaveProperty('afterAll')
|
||||||
|
->and($globalHook->calls)
|
||||||
|
->afterAll
|
||||||
|
->toBe(0);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,28 +1,56 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Pest\Support\Str;
|
||||||
|
|
||||||
global $globalHook;
|
global $globalHook;
|
||||||
|
|
||||||
uses()->beforeAll(function () use ($globalHook) {
|
// HACK: we have to determine our $globalHook->calls baseline. This is because
|
||||||
|
// two other tests are executed before this one due to filename ordering.
|
||||||
|
$args = $_SERVER['argv'] ?? [];
|
||||||
|
$single = isset($args[1]) && Str::endsWith(__FILE__, $args[1]);
|
||||||
|
$offset = $single ? 0 : 2;
|
||||||
|
|
||||||
|
uses()->beforeAll(function () use ($globalHook, $offset) {
|
||||||
expect($globalHook)
|
expect($globalHook)
|
||||||
->toHaveProperty('beforeAll')
|
->toHaveProperty('beforeAll')
|
||||||
->and($globalHook->beforeAll)
|
->and($globalHook->beforeAll)
|
||||||
->toBe(0);
|
->toBe(0)
|
||||||
|
->and($globalHook->calls)
|
||||||
|
->beforeAll
|
||||||
|
->toBe(1 + $offset);
|
||||||
|
|
||||||
$globalHook->beforeAll = 1;
|
$globalHook->beforeAll = 1;
|
||||||
|
$globalHook->calls->beforeAll++;
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeAll(function () use ($globalHook) {
|
beforeAll(function () use ($globalHook, $offset) {
|
||||||
expect($globalHook)
|
expect($globalHook)
|
||||||
->toHaveProperty('beforeAll')
|
->toHaveProperty('beforeAll')
|
||||||
->and($globalHook->beforeAll)
|
->and($globalHook->beforeAll)
|
||||||
->toBe(1);
|
->toBe(1)
|
||||||
|
->and($globalHook->calls)
|
||||||
|
->beforeAll
|
||||||
|
->toBe(2 + $offset);
|
||||||
|
|
||||||
$globalHook->beforeAll = 2;
|
$globalHook->beforeAll = 2;
|
||||||
|
$globalHook->calls->beforeAll++;
|
||||||
});
|
});
|
||||||
|
|
||||||
test('global beforeAll execution order', function () use ($globalHook) {
|
test('global beforeAll execution order', function () use ($globalHook, $offset) {
|
||||||
expect($globalHook)
|
expect($globalHook)
|
||||||
->toHaveProperty('beforeAll')
|
->toHaveProperty('beforeAll')
|
||||||
->and($globalHook->beforeAll)
|
->and($globalHook->beforeAll)
|
||||||
->toBe(2);
|
->toBe(2)
|
||||||
|
->and($globalHook->calls)
|
||||||
|
->beforeAll
|
||||||
|
->toBe(3 + $offset);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('only gets called once per file', function () use ($globalHook, $offset) {
|
||||||
|
expect($globalHook)
|
||||||
|
->beforeAll
|
||||||
|
->toBe(2)
|
||||||
|
->and($globalHook->calls)
|
||||||
|
->beforeAll
|
||||||
|
->toBe(3 + $offset);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
uses()->group('integration')->in('Visual');
|
uses()->group('integration')->in('Visual');
|
||||||
|
|
||||||
$globalHook = (object) []; // NOTE: global test value container to be mutated and checked across files, as needed
|
// NOTE: global test value container to be mutated and checked across files, as needed
|
||||||
|
$globalHook = (object) ['calls' => (object) ['beforeAll' => 0, 'afterAll' => 0]];
|
||||||
|
|
||||||
uses()
|
uses()
|
||||||
->beforeEach(function () {
|
->beforeEach(function () {
|
||||||
@ -10,11 +11,13 @@ uses()
|
|||||||
})
|
})
|
||||||
->beforeAll(function () use ($globalHook) {
|
->beforeAll(function () use ($globalHook) {
|
||||||
$globalHook->beforeAll = 0;
|
$globalHook->beforeAll = 0;
|
||||||
|
$globalHook->calls->beforeAll++;
|
||||||
})
|
})
|
||||||
->afterEach(function () {
|
->afterEach(function () {
|
||||||
$this->ith = 0;
|
$this->ith = 0;
|
||||||
})
|
})
|
||||||
->afterAll(function () use ($globalHook) {
|
->afterAll(function () use ($globalHook) {
|
||||||
$globalHook->afterAll = 0;
|
$globalHook->afterAll = 0;
|
||||||
|
$globalHook->calls->afterAll++;
|
||||||
})
|
})
|
||||||
->in('Hooks');
|
->in('Hooks');
|
||||||
|
|||||||
Reference in New Issue
Block a user