feat: adds support for global helpers

This commit is contained in:
Nuno Maduro
2020-05-13 22:51:50 +02:00
parent 2d85842777
commit 6fc55becc8
6 changed files with 151 additions and 3 deletions

View File

@ -47,6 +47,12 @@
✓ it catch exceptions
✓ it catch exceptions and messages
PASS Tests\Features\Helpers
✓ it can set/get properties on $this
✓ it throws error if property do not exist
✓ it allows to call underlying protected/private methods
✓ it throws error if method do not exist
PASS Tests\Features\HigherOrderMessages
✓ it proxies calls to object
@ -126,5 +132,5 @@
WARN Tests\Visual\Success
s visual snapshot of test suite on success
Tests: 6 skipped, 65 passed
Time: 2.50s
Tests: 6 skipped, 69 passed
Time: 2.63s

View File

@ -0,0 +1,43 @@
<?php
function addName()
{
test()->user = 'nuno';
}
it('can set/get properties on $this', function () {
addName();
assertEquals('nuno', $this->name);
});
it('throws error if property do not exist', function () {
test()->user;
})->throws(\Whoops\Exception\ErrorException::class, 'Undefined property PHPUnit\Framework\TestCase::$name');
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()');