Files
pest/tests/Features/Helpers.php
2021-05-14 23:52:24 +01:00

47 lines
1.0 KiB
PHP

<?php
function addUser()
{
test()->user = 'nuno';
}
it('can set/get properties on $this', function () {
addUser();
expect($this->user)->toBe('nuno');
});
it('throws error if property do not exist', function () {
test()->user;
})->throws(\Whoops\Exception\ErrorException::class, 'Undefined property PHPUnit\Framework\TestCase::$user');
class User
{
public function getName()
{
return 'nuno';
}
}
function mockUser()
{
$mock = test()->createMock(User::class);
$mock->method('getName')
->willReturn('maduro');
return $mock;
}
it('allows to call underlying protected/private methods', function () {
$user = mockUser();
expect($user->getName())->toBe('maduro');
});
it('throws error if method do not exist', function () {
test()->name();
})->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);