mirror of
https://github.com/pestphp/pest.git
synced 2026-03-12 02:37:22 +01:00
Merge pull request #344 from pestphp/callable-expect-fix
Forces higher order test callable expects to be closures
This commit is contained in:
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Support;
|
namespace Pest\Support;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
use Pest\Expectation;
|
use Pest\Expectation;
|
||||||
use Pest\PendingObjects\TestCall;
|
use Pest\PendingObjects\TestCall;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
@ -34,7 +35,7 @@ final class HigherOrderCallables
|
|||||||
*/
|
*/
|
||||||
public function expect($value)
|
public function expect($value)
|
||||||
{
|
{
|
||||||
return new Expectation(is_callable($value) ? Reflection::bindCallable($value) : $value);
|
return new Expectation($value instanceof Closure ? Reflection::bindCallable($value) : $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -18,6 +18,9 @@ it('resolves expect callables correctly')
|
|||||||
->toBeString()
|
->toBeString()
|
||||||
->toBe('bar');
|
->toBe('bar');
|
||||||
|
|
||||||
|
test('does not treat method names as callables')
|
||||||
|
->expect('it')->toBeString();
|
||||||
|
|
||||||
it('can tap into the test')
|
it('can tap into the test')
|
||||||
->expect('foo')->toBeString()
|
->expect('foo')->toBeString()
|
||||||
->tap(function () { expect($this)->toBeInstanceOf(TestCase::class); })
|
->tap(function () { expect($this)->toBeInstanceOf(TestCase::class); })
|
||||||
|
|||||||
Reference in New Issue
Block a user