#!/usr/bin/env php setReturn(?:Value|Reference)\((.+?),\s*(.+?)\);/ims' => '->shouldReceive(\1)->andReturn(\2);', '/->throwOn\((.+?),(.+?)\);/ims' => '->shouldReceive(\1)->andThrow(\2);', '/->expectOnce\(([^,\)]+)\);/ims' => '->shouldReceive(\1)->once();', '/->expectNever\(([^,\)]+)\);/ims' => '->shouldReceive(\1)->never();', '/->expectOnce\((.+?),\s*array\((.+?)\)\s*\);/ims' => '->shouldReceive(\1)->with(\2)->once();', '/->expectCallCount\((.+?),\s*(.+?)\)/ims' => '->shouldReceive(\1)->times(\2);', '/new ([a-z_]*Mock[a-z_]+)\([^\)]*\)/ims' => 'Mockery::mock()', '/new ([a-z_]*Mock[a-z_]+)\;/ims' => 'Mockery::mock();', '/Mock::generate[^;]+;\s*/' => '', '/new AnythingExpectation\(\)/' => '\Mockery::any()', ]; foreach ($patterns as $from => $to) { $php = preg_replace($from, $to, $php); } } // ---------------------------- // Convert SimpleTest classes and assertions $patterns = [ '/assertEquals?/' => 'assertEquals', '/assertNotEquals?/' => 'assertNotEquals', '/assertPattern/' => 'assertRegExp', '/assertIdentical/' => 'assertSame', '/assertNotIdentical/' => 'assertNotSame', '/assertNoPattern/' => 'assertNotRegExp', '/assertReference/' => 'assertSame', '/assertIsA\((.+?),\s*(.+?)(,\s*.+?)?\)/' => 'assertInstanceOf(\2, \1)', '/expectException/' => 'setExpectedException', '/$this->pass()/' => '$this->assertTrue(true)', '/\bUnitTest(Case)?\b/' => 'PHPUnit_Framework_TestCase', '/setup/' => 'setUp', ]; foreach ($patterns as $from => $to) { $php = preg_replace($from, $to, $php); } // ---------------------------- // Output if (in_array('-o', $argv, true)) { echo $php; } else { if (file_get_contents($argv[1]) != $php) { echo "updating {$argv[1]}\n"; file_put_contents($argv[1], $php); } }