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);
}
@edorian

edorian commented Mar 25, 2011

Copy link
Copy Markdown

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 or u modifier, not matter which. Can't explain why it did but that did the trick for me.

@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