mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 18:27:23 +01:00
feat(expect): makes expect work with pending higher order tests
This commit is contained in:
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Concerns;
|
namespace Pest\Concerns;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use Pest\Expectation;
|
||||||
use Pest\Support\ExceptionTrace;
|
use Pest\Support\ExceptionTrace;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use PHPUnit\Util\Test;
|
use PHPUnit\Util\Test;
|
||||||
@ -87,6 +88,16 @@ trait TestCase
|
|||||||
parent::tearDownAfterClass();
|
parent::tearDownAfterClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new expectation.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
*/
|
||||||
|
public function expect($value): Expectation
|
||||||
|
{
|
||||||
|
return new Expectation($value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets executed before the test.
|
* Gets executed before the test.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -30,6 +30,16 @@ final class Expectation
|
|||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new expectation.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
*/
|
||||||
|
public function and($value): Expectation
|
||||||
|
{
|
||||||
|
return new self($value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the opposite expectation for the value.
|
* Creates the opposite expectation for the value.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||||||
namespace Pest\PendingObjects;
|
namespace Pest\PendingObjects;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Pest\Expectation;
|
|
||||||
use Pest\Factories\TestCaseFactory;
|
use Pest\Factories\TestCaseFactory;
|
||||||
use Pest\Support\Backtrace;
|
use Pest\Support\Backtrace;
|
||||||
use Pest\Support\NullClosure;
|
use Pest\Support\NullClosure;
|
||||||
@ -13,6 +12,8 @@ use Pest\TestSuite;
|
|||||||
use SebastianBergmann\Exporter\Exporter;
|
use SebastianBergmann\Exporter\Exporter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @method \Pest\Expectation expect(mixed $value)
|
||||||
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class TestCall
|
final class TestCall
|
||||||
@ -85,16 +86,6 @@ final class TestCall
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new expectation.
|
|
||||||
*
|
|
||||||
* @param mixed $value the Value
|
|
||||||
*/
|
|
||||||
public function expect($value): Expectation
|
|
||||||
{
|
|
||||||
return expect($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the test depends.
|
* Sets the test depends.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -110,8 +110,10 @@ function afterAll(Closure $closure = null): void
|
|||||||
* Creates a new expectation.
|
* Creates a new expectation.
|
||||||
*
|
*
|
||||||
* @param mixed $value the Value
|
* @param mixed $value the Value
|
||||||
|
*
|
||||||
|
* @return Expectation
|
||||||
*/
|
*/
|
||||||
function expect($value): Expectation
|
function expect($value)
|
||||||
{
|
{
|
||||||
return new Expectation($value);
|
return test()->expect($value);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
✓ that gets executed
|
✓ that gets executed
|
||||||
|
|
||||||
PASS Tests\Expect\toBe
|
PASS Tests\Expect\toBe
|
||||||
|
✓ expect true → toBeTrue → and false → toBeFalse
|
||||||
✓ strict comparisons
|
✓ strict comparisons
|
||||||
✓ failures
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
@ -211,9 +212,9 @@
|
|||||||
PASS Tests\Features\HigherOrderTests
|
PASS Tests\Features\HigherOrderTests
|
||||||
✓ it proxies calls to object
|
✓ it proxies calls to object
|
||||||
|
|
||||||
WARN Tests\Features\It
|
PASS Tests\Features\It
|
||||||
✓ it is a test
|
✓ it is a test
|
||||||
! it is a higher order message test → This test did not perform any assertions /Users/nunomaduro/pestphp/pest/src/Factories/TestCaseFactory.php(204) : eval()'d code:4
|
✓ it is a higher order message test
|
||||||
|
|
||||||
PASS Tests\Features\Macro
|
PASS Tests\Features\Macro
|
||||||
✓ it can call chained macro method
|
✓ it can call chained macro method
|
||||||
@ -223,8 +224,8 @@
|
|||||||
✓ it has bar
|
✓ it has bar
|
||||||
|
|
||||||
PASS Tests\Features\PendingHigherOrderTests
|
PASS Tests\Features\PendingHigherOrderTests
|
||||||
✓ get 'foo' → get 'bar'
|
✓ get 'foo' → get 'bar' → expect true → toBeTrue
|
||||||
✓ get 'foo'
|
✓ get 'foo' → expect true → toBeTrue
|
||||||
|
|
||||||
WARN Tests\Features\Skip
|
WARN Tests\Features\Skip
|
||||||
✓ it do not skips
|
✓ it do not skips
|
||||||
@ -235,9 +236,9 @@
|
|||||||
✓ 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
|
||||||
|
|
||||||
WARN Tests\Features\Test
|
PASS Tests\Features\Test
|
||||||
✓ a test
|
✓ a test
|
||||||
! higher order message test → This test did not perform any assertions /Users/nunomaduro/pestphp/pest/src/Factories/TestCaseFactory.php(204) : eval()'d code:4
|
✓ higher order message test
|
||||||
|
|
||||||
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
||||||
✓ it example 1
|
✓ it example 1
|
||||||
@ -307,5 +308,5 @@
|
|||||||
WARN Tests\Visual\Success
|
WARN Tests\Visual\Success
|
||||||
- visual snapshot of test suite on success
|
- visual snapshot of test suite on success
|
||||||
|
|
||||||
Tests: 2 risked, 6 skipped, 178 passed
|
Tests: 6 skipped, 181 passed
|
||||||
Time: 5.70s
|
Time: 5.70s
|
||||||
|
|||||||
@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
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);
|
expect($nuno)->toBe($nuno)->not->toBe($dries);
|
||||||
expect($nuno)->not->toBe($dries);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('failures', function () {
|
test('failures', function () {
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use function PHPUnit\Framework\assertFalse;
|
||||||
|
|
||||||
$foo = new stdClass();
|
$foo = new stdClass();
|
||||||
$foo->beforeAll = false;
|
$foo->beforeAll = false;
|
||||||
$foo->beforeEach = false;
|
$foo->beforeEach = false;
|
||||||
@ -20,8 +22,8 @@ afterAll(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
register_shutdown_function(function () use ($foo) {
|
register_shutdown_function(function () use ($foo) {
|
||||||
expect($foo->beforeAll)->toBeFalse();
|
assertFalse($foo->beforeAll);
|
||||||
expect($foo->beforeEach)->toBeFalse();
|
assertFalse($foo->beforeEach);
|
||||||
expect($foo->afterEach)->toBeFalse();
|
assertFalse($foo->afterEach);
|
||||||
expect($foo->afterAll)->toBeFalse();
|
assertFalse($foo->afterAll);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -22,6 +22,7 @@ test('visual snapshot of test suite on success', function () {
|
|||||||
$output = explode("\n", $output());
|
$output = explode("\n", $output());
|
||||||
array_pop($output);
|
array_pop($output);
|
||||||
array_pop($output);
|
array_pop($output);
|
||||||
|
|
||||||
expect(file_get_contents($snapshot))->toContain(implode("\n", $output));
|
expect(file_get_contents($snapshot))->toContain(implode("\n", $output));
|
||||||
}
|
}
|
||||||
})->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE'))
|
})->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE'))
|
||||||
|
|||||||
Reference in New Issue
Block a user