Skip to content

Instantly share code, notes, and snippets.

@b3cft
Forked from lstrojny/phpunit-type-api.php
Created January 10, 2012 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b3cft/1589801 to your computer and use it in GitHub Desktop.
Save b3cft/1589801 to your computer and use it in GitHub Desktop.
#! /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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment