mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 17:57:23 +01:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 23eebc8127 | |||
| 3b435e460e | |||
| b52e9826e7 | |||
| ba49dd0499 | |||
| f9f6f28950 | |||
| f017015d1e | |||
| 29b4ee33bb | |||
| 03dc11c2f6 |
@ -4,6 +4,14 @@ 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/).
|
||||||
|
|
||||||
|
## [v0.3.15 (2020-12-04)](https://github.com/pestphp/pest/compare/v0.3.14...v0.3.15)
|
||||||
|
### Added
|
||||||
|
- Support for PHPUnit 9.5.0 ([#234](https://github.com/pestphp/pest/pull/234))
|
||||||
|
- Support for extending expectation API ([#232](https://github.com/pestphp/pest/pull/232))
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Static analysis while using string as key for datasets ([#233](https://github.com/pestphp/pest/pull/233))
|
||||||
|
|
||||||
## [v0.3.14 (2020-11-28)](https://github.com/pestphp/pest/compare/v0.3.13...v0.3.14)
|
## [v0.3.14 (2020-11-28)](https://github.com/pestphp/pest/compare/v0.3.13...v0.3.14)
|
||||||
### Added
|
### Added
|
||||||
- `pest:dusk` command ([#223](https://github.com/pestphp/pest/pull/223))
|
- `pest:dusk` command ([#223](https://github.com/pestphp/pest/pull/223))
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
"pestphp/pest-plugin": "^0.3",
|
"pestphp/pest-plugin": "^0.3",
|
||||||
"pestphp/pest-plugin-coverage": "^0.3",
|
"pestphp/pest-plugin-coverage": "^0.3",
|
||||||
"pestphp/pest-plugin-init": "^0.3",
|
"pestphp/pest-plugin-init": "^0.3",
|
||||||
"phpunit/phpunit": ">= 9.3.7 <= 9.4.3"
|
"phpunit/phpunit": ">= 9.3.7 <= 9.5.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
55
src/Concerns/Extendable.php
Normal file
55
src/Concerns/Extendable.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest\Concerns;
|
||||||
|
|
||||||
|
use BadMethodCallException;
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
trait Extendable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var array<string, Closure>
|
||||||
|
*/
|
||||||
|
private static $extends = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a custom extend.
|
||||||
|
*/
|
||||||
|
public static function extend(string $name, Closure $extend): void
|
||||||
|
{
|
||||||
|
static::$extends[$name] = $extend;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if extend is registered.
|
||||||
|
*/
|
||||||
|
public static function hasExtend(string $name): bool
|
||||||
|
{
|
||||||
|
return array_key_exists($name, static::$extends);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dynamically handle calls to the class.
|
||||||
|
*
|
||||||
|
* @param array<int, mixed> $parameters
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*
|
||||||
|
* @throws BadMethodCallException
|
||||||
|
*/
|
||||||
|
public function __call(string $method, array $parameters)
|
||||||
|
{
|
||||||
|
if (!static::hasExtend($method)) {
|
||||||
|
throw new BadMethodCallException(sprintf('Method %s::%s does not exist.', static::class, $method));
|
||||||
|
}
|
||||||
|
|
||||||
|
$extend = static::$extends[$method]->bindTo($this, static::class);
|
||||||
|
|
||||||
|
return $extend(...$parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -51,7 +51,7 @@ final class Datasets
|
|||||||
/**
|
/**
|
||||||
* Resolves the current dataset to an array value.
|
* Resolves the current dataset to an array value.
|
||||||
*
|
*
|
||||||
* @param Traversable<int, mixed>|Closure|iterable<int, mixed>|string|null $data
|
* @param Traversable<int|string, mixed>|Closure|iterable<int|string, mixed>|string|null $data
|
||||||
*
|
*
|
||||||
* @return array<string, mixed>
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest;
|
namespace Pest;
|
||||||
|
|
||||||
|
use Pest\Concerns\Extendable;
|
||||||
use PHPUnit\Framework\Assert;
|
use PHPUnit\Framework\Assert;
|
||||||
use PHPUnit\Framework\Constraint\Constraint;
|
use PHPUnit\Framework\Constraint\Constraint;
|
||||||
use SebastianBergmann\Exporter\Exporter;
|
use SebastianBergmann\Exporter\Exporter;
|
||||||
@ -15,6 +16,8 @@ use SebastianBergmann\Exporter\Exporter;
|
|||||||
*/
|
*/
|
||||||
final class Expectation
|
final class Expectation
|
||||||
{
|
{
|
||||||
|
use Extendable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The expectation value.
|
* The expectation value.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -59,7 +59,7 @@ final class TestCaseFactory
|
|||||||
/**
|
/**
|
||||||
* Holds the dataset, if any.
|
* Holds the dataset, if any.
|
||||||
*
|
*
|
||||||
* @var Closure|iterable<int, mixed>|string|null
|
* @var Closure|iterable<int|string, mixed>|string|null
|
||||||
*/
|
*/
|
||||||
public $dataset;
|
public $dataset;
|
||||||
|
|
||||||
|
|||||||
@ -78,7 +78,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 \Closure|iterable<int, mixed>|string $data
|
* @param \Closure|iterable<int|string, mixed>|string $data
|
||||||
*/
|
*/
|
||||||
public function with($data): TestCall
|
public function with($data): TestCall
|
||||||
{
|
{
|
||||||
|
|||||||
@ -6,5 +6,5 @@ namespace Pest;
|
|||||||
|
|
||||||
function version(): string
|
function version(): string
|
||||||
{
|
{
|
||||||
return '0.3.14';
|
return '0.3.15';
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/Support/Extendable.php
Normal file
33
src/Support/Extendable.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest\Support;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
final class Extendable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The extendable class.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $extendableClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new extendable instance.
|
||||||
|
*/
|
||||||
|
public function __construct(string $extendableClass)
|
||||||
|
{
|
||||||
|
$this->extendableClass = $extendableClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a custom extend.
|
||||||
|
*/
|
||||||
|
public function extend(string $name, Closure $extend): void
|
||||||
|
{
|
||||||
|
$this->extendableClass::extend($name, $extend);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,6 +9,7 @@ use Pest\PendingObjects\BeforeEachCall;
|
|||||||
use Pest\PendingObjects\TestCall;
|
use Pest\PendingObjects\TestCall;
|
||||||
use Pest\PendingObjects\UsesCall;
|
use Pest\PendingObjects\UsesCall;
|
||||||
use Pest\Support\Backtrace;
|
use Pest\Support\Backtrace;
|
||||||
|
use Pest\Support\Extendable;
|
||||||
use Pest\Support\HigherOrderTapProxy;
|
use Pest\Support\HigherOrderTapProxy;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
@ -111,9 +112,13 @@ function afterAll(Closure $closure = null): void
|
|||||||
*
|
*
|
||||||
* @param mixed $value the Value
|
* @param mixed $value the Value
|
||||||
*
|
*
|
||||||
* @return Expectation
|
* @return Expectation|Extendable
|
||||||
*/
|
*/
|
||||||
function expect($value)
|
function expect($value = null)
|
||||||
{
|
{
|
||||||
|
if (func_num_args() === 0) {
|
||||||
|
return new Extendable(Expectation::class);
|
||||||
|
}
|
||||||
|
|
||||||
return test()->expect($value);
|
return test()->expect($value);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,12 @@
|
|||||||
PASS Tests\CustomTestCase\ExecutedTest
|
PASS Tests\CustomTestCase\ExecutedTest
|
||||||
✓ that gets executed
|
✓ that gets executed
|
||||||
|
|
||||||
|
PASS Tests\Expect\extend
|
||||||
|
✓ it macros true is true
|
||||||
|
✓ it macros false is not true
|
||||||
|
✓ it macros true is true with argument
|
||||||
|
✓ it macros false is not true with argument
|
||||||
|
|
||||||
PASS Tests\Expect\not
|
PASS Tests\Expect\not
|
||||||
✓ not property calls
|
✓ not property calls
|
||||||
|
|
||||||
@ -404,5 +410,5 @@
|
|||||||
✓ depends run test only once
|
✓ depends run test only once
|
||||||
✓ depends works with the correct test name
|
✓ depends works with the correct test name
|
||||||
|
|
||||||
Tests: 7 skipped, 238 passed
|
Tests: 7 skipped, 242 passed
|
||||||
|
|
||||||
29
tests/Expect/extend.php
Normal file
29
tests/Expect/extend.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
expect()->extend('toBeAMacroExpectation', function () {
|
||||||
|
$this->toBeTrue();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect()->extend('toBeAMacroExpectationWithArguments', function (bool $value) {
|
||||||
|
$this->toBe($value);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('macros true is true', function () {
|
||||||
|
expect(true)->toBeAMacroExpectation();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('macros false is not true', function () {
|
||||||
|
expect(false)->not->toBeAMacroExpectation();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('macros true is true with argument', function () {
|
||||||
|
expect(true)->toBeAMacroExpectationWithArguments(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('macros false is not true with argument', function () {
|
||||||
|
expect(false)->not->toBeAMacroExpectationWithArguments(true);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user