An assistant to ease migration from SimpleTest mocks to Mockery ones.
Last versions of SimpleTest struggle to have stable mock generation. On the other hand, Mockery has a quite robust mock generation framework and it's more advanced than ST one. Hence the intend of migration.
- Clone this repository.
- Run composer install
- Then ./run.php /path/to/test/file.php
Then get a failure and contribute here with a PR to workaround the issue you got :)
Launch tests with the following command:
vendor/bin/phpunit --configuration phpunit.xml
This is entirely possible thanks to @nikic PHP-Parser especially Formatting-preserving pretty printing.
At the moment, the current transformations are supported:
- Convert class level Mock::generate('XYZ') + new MockXYZ into \Mockery::spy(XYZ::class) in each test
- Convert class level Mock::generatePartial('XYZ') + new MockXYZ into \Mockery::mock(XYZ::class)->makePartial()->shouldAllowMockingProtectedMethods() in each test
- Remove top level Mock::generate*
- Convert setReturnValue, setReturnReference, expectOnce, expectNever, expectCallCount
- Inject parent::setUp() and parent::tearDown() when they are missing
- Convert dirname(FILE) to DIR (because why not...)
- (specific to Tuleap test suite) Convert Tuleap mock() and partial_mock() wrappers
Plus, at the moment, it assume that you have a parent class as an intermediate for SimpleTest TestCase so you can have
in your tearDown
method the mockery closing code:
// Include mocker assertions into SimpleTest results
if ($container = \Mockery::getContainer()) {
for ($i = 0; $i < $container->mockery_getExpectationCount(); $i++) {
$this->pass();
}
}
\Mockery::close();
Format to convert:
- [] expect
- [] expectAtLeastOnce
- [] throwAt
- [] expect()