Skip to content

Instantly share code, notes, and snippets.

@lstrojny
Created March 20, 2011 00:12
Show Gist options
  • Select an option

  • Save lstrojny/877933 to your computer and use it in GitHub Desktop.

Select an option

Save lstrojny/877933 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);
}
@lstrojny

Copy link
Copy Markdown
Author

Removed the u modifier to do no harm to those without unicode enabled PCRE

@lstrojny

Copy link
Copy Markdown
Author

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