Created
March 20, 2011 00:12
-
-
Save lstrojny/877933 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env php | |
<?php | |
if ($_SERVER['argc'] != 2) { | |
printf("%s: Converts assertType() into assertInternalType() or assertInstanceOf()\n\n", basename(__FILE__)); | |
printf("Usage: %s <tests directory>\n", basename(__FILE__)); | |
exit(11); | |
} | |
$directories = new RegexIterator( | |
new RecursiveIteratorIterator( | |
new RecursiveDirectoryIterator($_SERVER['argv'][1]) | |
), | |
'/^.*test(case)?\.php$/i' | |
); | |
foreach ($directories as $file) { | |
$contents = file_get_contents($file->getPathName()); | |
$contents = preg_replace( | |
'/assertType\s*\((\s*["\'](string|integer|float|array|object|resource))/im', | |
'assertInternalType(\1', | |
$contents | |
); | |
$contents = preg_replace( | |
"/assertType/", | |
"assertInstanceOf", | |
$contents | |
); | |
file_put_contents($file->getPathName(), $contents); | |
} |
Removed the u modifier to do no harm to those without unicode enabled PCRE
Added "resource" to the list of internal types
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot for the gist! That saved me quite some time with +2k assertType calls :)
For whatever strange reason it wiped some files completely clean until i removed the
m
oru
modifier, not matter which. Can't explain why it did but that did the trick for me.