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

Assist convertion from SimpleTest mocks to Mockery

Notifications You must be signed in to change notification settings

Enalean/simpletest2mockery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleTest to Mockery

An assistant to ease migration from SimpleTest mocks to Mockery ones.

Build Status

Rational

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.

How to run it

  • 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

How

This is entirely possible thanks to @nikic PHP-Parser especially Formatting-preserving pretty printing.

What

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();

Todo

Format to convert:

  • [] expect
  • [] expectAtLeastOnce
  • [] throwAt
  • [] expect()

About

Assist convertion from SimpleTest mocks to Mockery

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages