@@ -21,15 +21,11 @@ |
||
| 21 | 21 | |
| 22 | 22 | namespace Kenjis\MonkeyPatch\Patcher\FunctionPatcher; |
| 23 | 23 | |
| 24 | -use ReflectionFunction; |
|
| 25 | -use ReflectionException; |
|
| 26 | - |
|
| 27 | 24 | use PhpParser\Node; |
| 28 | 25 | use PhpParser\Node\Expr\FuncCall; |
| 29 | 26 | use PhpParser\Node\Name; |
| 30 | 27 | use PhpParser\Node\Name\FullyQualified; |
| 31 | 28 | use PhpParser\NodeVisitorAbstract; |
| 32 | - |
|
| 33 | 29 | use Kenjis\MonkeyPatch\Patcher\FunctionPatcher; |
| 34 | 30 | |
| 35 | 31 | class NodeVisitor extends NodeVisitorAbstract |
@@ -13,7 +13,6 @@ |
||
| 13 | 13 | use PhpParser\Node; |
| 14 | 14 | use PhpParser\Node\Stmt\ClassMethod; |
| 15 | 15 | use PhpParser\NodeVisitorAbstract; |
| 16 | - |
|
| 17 | 16 | use Kenjis\MonkeyPatch\Patcher\MethodPatcher; |
| 18 | 17 | |
| 19 | 18 | class NodeVisitor extends NodeVisitorAbstract |
@@ -13,7 +13,6 @@ |
||
| 13 | 13 | use PhpParser\Node; |
| 14 | 14 | use PhpParser\Node\Stmt\ClassMethod; |
| 15 | 15 | use PhpParser\NodeVisitorAbstract; |
| 16 | - |
|
| 17 | 16 | use Kenjis\MonkeyPatch\Patcher\MethodPatcher; |
| 18 | 17 | |
| 19 | 18 | class NodeVisitor extends NodeVisitorAbstract |
@@ -251,10 +251,10 @@ |
||
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
| 254 | - * Recursive Unlink |
|
| 255 | - * |
|
| 256 | - * @param string $dir |
|
| 257 | - */ |
|
| 254 | + * Recursive Unlink |
|
| 255 | + * |
|
| 256 | + * @param string $dir |
|
| 257 | + */ |
|
| 258 | 258 | protected static function recursiveUnlink($dir) |
| 259 | 259 | { |
| 260 | 260 | if (! is_dir($dir)) |
@@ -13,7 +13,6 @@ |
||
| 13 | 13 | use PhpParser\Node; |
| 14 | 14 | use PhpParser\Node\Stmt\ClassMethod; |
| 15 | 15 | use PhpParser\NodeVisitorAbstract; |
| 16 | - |
|
| 17 | 16 | use Kenjis\MonkeyPatch\Patcher\MethodPatcher; |
| 18 | 17 | |
| 19 | 18 | class NodeVisitor extends NodeVisitorAbstract |
@@ -11,7 +11,6 @@ |
||
| 11 | 11 | namespace Kenjis\MonkeyPatch; |
| 12 | 12 | |
| 13 | 13 | use LogicException; |
| 14 | -use RuntimeException; |
|
| 15 | 14 | use PhpParser\ParserFactory; |
| 16 | 15 | use Kenjis\MonkeyPatch\Patcher\FunctionPatcher; |
| 17 | 16 | |
@@ -52,71 +52,71 @@ |
||
| 52 | 52 | */ |
| 53 | 53 | final class TestSuiteProvider |
| 54 | 54 | { |
| 55 | - /** |
|
| 56 | - * phpunit configuration file |
|
| 57 | - * |
|
| 58 | - * @var string |
|
| 59 | - */ |
|
| 60 | - private static $file; |
|
| 55 | + /** |
|
| 56 | + * phpunit configuration file |
|
| 57 | + * |
|
| 58 | + * @var string |
|
| 59 | + */ |
|
| 60 | + private static $file; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * constructor |
|
| 64 | - */ |
|
| 65 | - private function __construct() {} |
|
| 62 | + /** |
|
| 63 | + * constructor |
|
| 64 | + */ |
|
| 65 | + private function __construct() {} |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * set the phpunit configuration file |
|
| 69 | - * |
|
| 70 | - * @param string $file the path or filename of the phunit configuration file |
|
| 71 | - */ |
|
| 72 | - public static function setConfigurationFile($file) |
|
| 73 | - { |
|
| 74 | - static::$file = $file; |
|
| 75 | - } |
|
| 67 | + /** |
|
| 68 | + * set the phpunit configuration file |
|
| 69 | + * |
|
| 70 | + * @param string $file the path or filename of the phunit configuration file |
|
| 71 | + */ |
|
| 72 | + public static function setConfigurationFile($file) |
|
| 73 | + { |
|
| 74 | + static::$file = $file; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * get the phpunit test suite instance |
|
| 79 | - * |
|
| 80 | - * @return PHPUnit_Framework_TestSuite returns the phpunit test suite instance |
|
| 81 | - * @throws FileNotFoundException if the file is not found |
|
| 82 | - */ |
|
| 83 | - public static function suite() |
|
| 84 | - { |
|
| 85 | - $file = static::checkConfigurationFile( |
|
| 86 | - static::getConfigurationFile() |
|
| 87 | - ); |
|
| 77 | + /** |
|
| 78 | + * get the phpunit test suite instance |
|
| 79 | + * |
|
| 80 | + * @return PHPUnit_Framework_TestSuite returns the phpunit test suite instance |
|
| 81 | + * @throws FileNotFoundException if the file is not found |
|
| 82 | + */ |
|
| 83 | + public static function suite() |
|
| 84 | + { |
|
| 85 | + $file = static::checkConfigurationFile( |
|
| 86 | + static::getConfigurationFile() |
|
| 87 | + ); |
|
| 88 | 88 | |
| 89 | - return PHPUnit_Util_Configuration::getInstance($file) |
|
| 90 | - ->getTestSuiteConfiguration(); |
|
| 91 | - } |
|
| 89 | + return PHPUnit_Util_Configuration::getInstance($file) |
|
| 90 | + ->getTestSuiteConfiguration(); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * get the phpunit configuration file |
|
| 95 | - * |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 98 | - private static function getConfigurationFile() |
|
| 99 | - { |
|
| 100 | - static::$file = isset(static::$file) |
|
| 101 | - ? static::$file |
|
| 102 | - : APPPATH.'tests/phpunit.xml'; |
|
| 93 | + /** |
|
| 94 | + * get the phpunit configuration file |
|
| 95 | + * |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | + private static function getConfigurationFile() |
|
| 99 | + { |
|
| 100 | + static::$file = isset(static::$file) |
|
| 101 | + ? static::$file |
|
| 102 | + : APPPATH.'tests/phpunit.xml'; |
|
| 103 | 103 | |
| 104 | - return static::$file; |
|
| 105 | - } |
|
| 104 | + return static::$file; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * check the given file |
|
| 109 | - * |
|
| 110 | - * @param string $file file to check |
|
| 111 | - * @return string returns the file if it is valid |
|
| 112 | - * @throws FileNotFoundException if the file is not found |
|
| 113 | - */ |
|
| 114 | - private static function checkConfigurationFile($file) |
|
| 115 | - { |
|
| 116 | - if (!file_exists($file)) { |
|
| 117 | - throw new \RuntimeException("The requested phpunit configuration was not found at $file"); |
|
| 118 | - } |
|
| 107 | + /** |
|
| 108 | + * check the given file |
|
| 109 | + * |
|
| 110 | + * @param string $file file to check |
|
| 111 | + * @return string returns the file if it is valid |
|
| 112 | + * @throws FileNotFoundException if the file is not found |
|
| 113 | + */ |
|
| 114 | + private static function checkConfigurationFile($file) |
|
| 115 | + { |
|
| 116 | + if (!file_exists($file)) { |
|
| 117 | + throw new \RuntimeException("The requested phpunit configuration was not found at $file"); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - return $file; |
|
| 121 | - } |
|
| 120 | + return $file; |
|
| 121 | + } |
|
| 122 | 122 | } |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | |
| 13 | 13 | $app = 'application'; |
| 14 | 14 | if ($argv && $argv[1] && is_dir($argv[1])) { |
| 15 | - $app = $argv[1]; |
|
| 15 | + $app = $argv[1]; |
|
| 16 | 16 | } |
| 17 | 17 | $installer = new Installer(); |
| 18 | 18 | $installer->update($app); |
@@ -13,7 +13,6 @@ |
||
| 13 | 13 | use PhpParser\Node; |
| 14 | 14 | use PhpParser\Node\Stmt\ClassMethod; |
| 15 | 15 | use PhpParser\NodeVisitorAbstract; |
| 16 | - |
|
| 17 | 16 | use Kenjis\MonkeyPatch\Patcher\MethodPatcher; |
| 18 | 17 | |
| 19 | 18 | class NodeVisitor extends NodeVisitorAbstract |
@@ -10,136 +10,136 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Installer |
| 12 | 12 | { |
| 13 | - const TEST_FOLDER = 'tests'; |
|
| 13 | + const TEST_FOLDER = 'tests'; |
|
| 14 | 14 | |
| 15 | - public static function install($app = 'application') |
|
| 16 | - { |
|
| 17 | - self::recursiveCopy( |
|
| 18 | - dirname(__FILE__) . '/application/tests', |
|
| 19 | - $app . '/' . static::TEST_FOLDER |
|
| 20 | - ); |
|
| 21 | - self::fixPath($app); |
|
| 22 | - } |
|
| 15 | + public static function install($app = 'application') |
|
| 16 | + { |
|
| 17 | + self::recursiveCopy( |
|
| 18 | + dirname(__FILE__) . '/application/tests', |
|
| 19 | + $app . '/' . static::TEST_FOLDER |
|
| 20 | + ); |
|
| 21 | + self::fixPath($app); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Fix paths in Bootstrap.php |
|
| 26 | - */ |
|
| 27 | - private static function fixPath($app = 'application') |
|
| 28 | - { |
|
| 29 | - $file = $app . '/' . static::TEST_FOLDER . '/Bootstrap.php'; |
|
| 30 | - $contents = file_get_contents($file); |
|
| 24 | + /** |
|
| 25 | + * Fix paths in Bootstrap.php |
|
| 26 | + */ |
|
| 27 | + private static function fixPath($app = 'application') |
|
| 28 | + { |
|
| 29 | + $file = $app . '/' . static::TEST_FOLDER . '/Bootstrap.php'; |
|
| 30 | + $contents = file_get_contents($file); |
|
| 31 | 31 | |
| 32 | - if (! file_exists('system')) { |
|
| 33 | - if (file_exists('vendor/codeigniter/framework/system')) { |
|
| 34 | - $contents = str_replace( |
|
| 35 | - '$system_path = \'../../system\';', |
|
| 36 | - '$system_path = \'../../vendor/codeigniter/framework/system\';', |
|
| 37 | - $contents |
|
| 38 | - ); |
|
| 39 | - } else { |
|
| 40 | - throw new Exception('Can\'t find "system" folder.'); |
|
| 41 | - } |
|
| 42 | - } |
|
| 32 | + if (! file_exists('system')) { |
|
| 33 | + if (file_exists('vendor/codeigniter/framework/system')) { |
|
| 34 | + $contents = str_replace( |
|
| 35 | + '$system_path = \'../../system\';', |
|
| 36 | + '$system_path = \'../../vendor/codeigniter/framework/system\';', |
|
| 37 | + $contents |
|
| 38 | + ); |
|
| 39 | + } else { |
|
| 40 | + throw new Exception('Can\'t find "system" folder.'); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - if (! file_exists('index.php')) { |
|
| 45 | - if (file_exists('public/index.php')) { |
|
| 46 | - // CodeIgniter 3.0.6 and after |
|
| 47 | - $contents = str_replace( |
|
| 48 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
| 49 | - "define('FCPATH', realpath(dirname(__FILE__).'/../../public').DIRECTORY_SEPARATOR);", |
|
| 50 | - $contents |
|
| 51 | - ); |
|
| 52 | - // CodeIgniter 3.0.5 and before |
|
| 53 | - $contents = str_replace( |
|
| 54 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
| 55 | - "define('FCPATH', realpath(dirname(__FILE__).'/../../public').'/');", |
|
| 56 | - $contents |
|
| 57 | - ); |
|
| 58 | - } elseif (file_exists($app . '/public/index.php')) { |
|
| 59 | - // CodeIgniter 3.0.6 and after |
|
| 60 | - $contents = str_replace( |
|
| 61 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
| 62 | - "define('FCPATH', realpath(dirname(__FILE__).'/../public').DIRECTORY_SEPARATOR);", |
|
| 63 | - $contents |
|
| 64 | - ); |
|
| 65 | - // CodeIgniter 3.0.5 and before |
|
| 66 | - $contents = str_replace( |
|
| 67 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
| 68 | - "define('FCPATH', realpath(dirname(__FILE__).'/../public').'/');", |
|
| 69 | - $contents |
|
| 70 | - ); |
|
| 71 | - if ($app != 'application') { |
|
| 72 | - $contents = str_replace( |
|
| 73 | - "\$application_folder = '../../application';", |
|
| 74 | - "\$application_folder = '../../{$app}';", |
|
| 75 | - $contents |
|
| 76 | - ); |
|
| 77 | - } |
|
| 78 | - } else { |
|
| 79 | - throw new Exception('Can\'t find "index.php".'); |
|
| 80 | - } |
|
| 81 | - } |
|
| 44 | + if (! file_exists('index.php')) { |
|
| 45 | + if (file_exists('public/index.php')) { |
|
| 46 | + // CodeIgniter 3.0.6 and after |
|
| 47 | + $contents = str_replace( |
|
| 48 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
| 49 | + "define('FCPATH', realpath(dirname(__FILE__).'/../../public').DIRECTORY_SEPARATOR);", |
|
| 50 | + $contents |
|
| 51 | + ); |
|
| 52 | + // CodeIgniter 3.0.5 and before |
|
| 53 | + $contents = str_replace( |
|
| 54 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
| 55 | + "define('FCPATH', realpath(dirname(__FILE__).'/../../public').'/');", |
|
| 56 | + $contents |
|
| 57 | + ); |
|
| 58 | + } elseif (file_exists($app . '/public/index.php')) { |
|
| 59 | + // CodeIgniter 3.0.6 and after |
|
| 60 | + $contents = str_replace( |
|
| 61 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
| 62 | + "define('FCPATH', realpath(dirname(__FILE__).'/../public').DIRECTORY_SEPARATOR);", |
|
| 63 | + $contents |
|
| 64 | + ); |
|
| 65 | + // CodeIgniter 3.0.5 and before |
|
| 66 | + $contents = str_replace( |
|
| 67 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
| 68 | + "define('FCPATH', realpath(dirname(__FILE__).'/../public').'/');", |
|
| 69 | + $contents |
|
| 70 | + ); |
|
| 71 | + if ($app != 'application') { |
|
| 72 | + $contents = str_replace( |
|
| 73 | + "\$application_folder = '../../application';", |
|
| 74 | + "\$application_folder = '../../{$app}';", |
|
| 75 | + $contents |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | + } else { |
|
| 79 | + throw new Exception('Can\'t find "index.php".'); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - file_put_contents($file, $contents); |
|
| 84 | - } |
|
| 83 | + file_put_contents($file, $contents); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - public static function update($app = 'application') |
|
| 87 | - { |
|
| 88 | - $target_dir = $app . '/' . static::TEST_FOLDER . '/_ci_phpunit_test'; |
|
| 89 | - self::recursiveUnlink($target_dir); |
|
| 90 | - self::recursiveCopy( |
|
| 91 | - dirname(__FILE__) . '/application/tests/_ci_phpunit_test', |
|
| 92 | - $target_dir |
|
| 93 | - ); |
|
| 94 | - } |
|
| 86 | + public static function update($app = 'application') |
|
| 87 | + { |
|
| 88 | + $target_dir = $app . '/' . static::TEST_FOLDER . '/_ci_phpunit_test'; |
|
| 89 | + self::recursiveUnlink($target_dir); |
|
| 90 | + self::recursiveCopy( |
|
| 91 | + dirname(__FILE__) . '/application/tests/_ci_phpunit_test', |
|
| 92 | + $target_dir |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Recursive Copy |
|
| 98 | - * |
|
| 99 | - * @param string $src |
|
| 100 | - * @param string $dst |
|
| 101 | - */ |
|
| 102 | - private static function recursiveCopy($src, $dst) |
|
| 103 | - { |
|
| 104 | - @mkdir($dst, 0755); |
|
| 96 | + /** |
|
| 97 | + * Recursive Copy |
|
| 98 | + * |
|
| 99 | + * @param string $src |
|
| 100 | + * @param string $dst |
|
| 101 | + */ |
|
| 102 | + private static function recursiveCopy($src, $dst) |
|
| 103 | + { |
|
| 104 | + @mkdir($dst, 0755); |
|
| 105 | 105 | |
| 106 | - $iterator = new \RecursiveIteratorIterator( |
|
| 107 | - new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
| 108 | - \RecursiveIteratorIterator::SELF_FIRST |
|
| 109 | - ); |
|
| 106 | + $iterator = new \RecursiveIteratorIterator( |
|
| 107 | + new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
| 108 | + \RecursiveIteratorIterator::SELF_FIRST |
|
| 109 | + ); |
|
| 110 | 110 | |
| 111 | - foreach ($iterator as $file) { |
|
| 112 | - if ($file->isDir()) { |
|
| 113 | - @mkdir($dst . '/' . $iterator->getSubPathName()); |
|
| 114 | - } else { |
|
| 115 | - $success = copy($file, $dst . '/' . $iterator->getSubPathName()); |
|
| 116 | - if ($success) { |
|
| 117 | - echo 'copied: ' . $dst . '/' . $iterator->getSubPathName() . PHP_EOL; |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - } |
|
| 111 | + foreach ($iterator as $file) { |
|
| 112 | + if ($file->isDir()) { |
|
| 113 | + @mkdir($dst . '/' . $iterator->getSubPathName()); |
|
| 114 | + } else { |
|
| 115 | + $success = copy($file, $dst . '/' . $iterator->getSubPathName()); |
|
| 116 | + if ($success) { |
|
| 117 | + echo 'copied: ' . $dst . '/' . $iterator->getSubPathName() . PHP_EOL; |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Recursive Unlink |
|
| 125 | - * |
|
| 126 | - * @param string $dir |
|
| 127 | - */ |
|
| 128 | - private static function recursiveUnlink($dir) |
|
| 129 | - { |
|
| 130 | - $iterator = new \RecursiveIteratorIterator( |
|
| 131 | - new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
| 132 | - \RecursiveIteratorIterator::CHILD_FIRST |
|
| 133 | - ); |
|
| 123 | + /** |
|
| 124 | + * Recursive Unlink |
|
| 125 | + * |
|
| 126 | + * @param string $dir |
|
| 127 | + */ |
|
| 128 | + private static function recursiveUnlink($dir) |
|
| 129 | + { |
|
| 130 | + $iterator = new \RecursiveIteratorIterator( |
|
| 131 | + new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
| 132 | + \RecursiveIteratorIterator::CHILD_FIRST |
|
| 133 | + ); |
|
| 134 | 134 | |
| 135 | - foreach ($iterator as $file) { |
|
| 136 | - if ($file->isDir()) { |
|
| 137 | - rmdir($file); |
|
| 138 | - } else { |
|
| 139 | - unlink($file); |
|
| 140 | - } |
|
| 141 | - } |
|
| 135 | + foreach ($iterator as $file) { |
|
| 136 | + if ($file->isDir()) { |
|
| 137 | + rmdir($file); |
|
| 138 | + } else { |
|
| 139 | + unlink($file); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - rmdir($dir); |
|
| 144 | - } |
|
| 143 | + rmdir($dir); |
|
| 144 | + } |
|
| 145 | 145 | } |