mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
44 lines
916 B
PHP
44 lines
916 B
PHP
<?php
|
|
|
|
function addUser()
|
|
{
|
|
test()->user = 'nuno';
|
|
}
|
|
|
|
it('can set/get properties on $this', function () {
|
|
addUser();
|
|
assertEquals('nuno', $this->user);
|
|
});
|
|
|
|
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();
|
|
|
|
assertEquals('maduro', $user->getName());
|
|
});
|
|
|
|
it('throws error if method do not exist', function () {
|
|
test()->name();
|
|
})->throws(\ReflectionException::class, 'Call to undefined method PHPUnit\Framework\TestCase::name()');
|