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