mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 17:57:23 +01:00
feat(mock): adds work in progress
This commit is contained in:
@ -63,6 +63,7 @@
|
||||
✓ it allows to call underlying protected/private methods
|
||||
✓ it throws error if method do not exist
|
||||
✓ it can forward unexpected calls to any global function
|
||||
✓ it can use helpers from helpers file
|
||||
|
||||
PASS Tests\Features\HigherOrderTests
|
||||
✓ it proxies calls to object
|
||||
@ -77,7 +78,8 @@
|
||||
✓ it will throw exception from call if no macro exists
|
||||
|
||||
PASS Tests\Features\Mocks
|
||||
✓ it has bar
|
||||
✓ it can mock methods
|
||||
✓ access to the mock object
|
||||
|
||||
PASS Tests\Features\PendingHigherOrderTests
|
||||
✓ get 'foo' → get 'bar' → expect true → toBeTrue
|
||||
@ -221,5 +223,9 @@
|
||||
✓ it is a test
|
||||
✓ it uses correct parent class
|
||||
|
||||
<<<<<<< HEAD
|
||||
Tests: 7 skipped, 119 passed
|
||||
=======
|
||||
Tests: 7 skipped, 117 passed
|
||||
>>>>>>> feat(mock): adds work in progress
|
||||
|
||||
@ -42,3 +42,5 @@ it('throws error if method do not exist', function () {
|
||||
})->throws(\ReflectionException::class, 'Call to undefined method PHPUnit\Framework\TestCase::name()');
|
||||
|
||||
it('can forward unexpected calls to any global function')->_assertThat();
|
||||
|
||||
it('can use helpers from helpers file')->myAssertTrue(true);
|
||||
|
||||
@ -1,17 +1,24 @@
|
||||
<?php
|
||||
|
||||
use function Tests\mock;
|
||||
use Mockery\CompositeExpectation;
|
||||
use Mockery\MockInterface;
|
||||
|
||||
interface Foo
|
||||
interface Http
|
||||
{
|
||||
public function bar(): int;
|
||||
public function get(): string;
|
||||
}
|
||||
|
||||
it('has bar', function () {
|
||||
$mock = mock(Foo::class);
|
||||
$mock->shouldReceive('bar')
|
||||
->times(1)
|
||||
->andReturn(2);
|
||||
it('can mock methods', function () {
|
||||
$mock = mock(Http::class)->expect(
|
||||
get: 'foo',
|
||||
);
|
||||
|
||||
$mock->bar();
|
||||
});
|
||||
expect($mock->get())->toBe('foo');
|
||||
})->skip(((float) phpversion()) < 8.0);
|
||||
|
||||
test('access to the mock object', function () {
|
||||
$mock = mock(Http::class);
|
||||
expect($mock->expect())->toBeInstanceOf(MockInterface::class);
|
||||
|
||||
expect($mock->shouldReceive())->toBeInstanceOf(CompositeExpectation::class);
|
||||
})->skip(((float) phpversion()) < 8.0);
|
||||
|
||||
@ -1,11 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
|
||||
function mock(string $class): MockInterface
|
||||
function myAssertTrue($value)
|
||||
{
|
||||
return Mockery::mock($class);
|
||||
test()->assertTrue($value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user