8000 GitHub - usox/hackmock: Mock objects for hacklang
[go: up one dir, main page]

Skip to content
This repository has been archived by the owner on Feb 21, 2025. It is now read-only.
/ hackmock Public archive

Mock objects for hacklang

License

Notifications You must be signed in to change notification settings

usox/hackmock

Repository files navigation

Build Status

HackMock

Creating mock objects for hacklang - yes, seriously.

Note

Due to the use of eval, hackmock may stop working in future hhvm versions.

What works?

  • Strict mode
  • Creating mocks of interfaces and concrete classes
  • Defining basic method expectations (parameter validation, return value definition)

What does not work?

  • Everything else, especially rare and/or untested cases involving generics, etc.
use function Usox\HackMock\{mock, prospect};

class SomethingTest extends \Usox\HackMock\HackMock {

  public function testSomething() {
    $my_fine_class = mock(SomeInterface::class);

    prospect($my_fine_class, 'someMethodName')
      ->once()
      ->andReturn('some-fine-value');

    prospect($my_fine_class, 'someOtherMethodName')
      ->andThrow(new \Exception('foobar'));
  }
}
0