https://github.com/usox/hackmock
Mock objects for hacklang
https://github.com/usox/hackmock
hack hacklang hhvm mock testing tests
Last synced: 11 months ago
JSON representation
Mock objects for hacklang
- Host: GitHub
- URL: https://github.com/usox/hackmock
- Owner: usox
- License: mit
- Created: 2018-05-19T09:36:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-01-21T07:32:29.000Z (about 5 years ago)
- Last Synced: 2025-02-08T05:44:41.639Z (about 1 year ago)
- Topics: hack, hacklang, hhvm, mock, testing, tests
- Language: Hack
- Homepage:
- Size: 74.2 KB
- Stars: 7
- Watchers: 3
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/usox/hackmock)
# 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.
```php
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'));
}
}
```