Created
October 18, 2012 06:00
-
-
Save bazilio91/3910116 to your computer and use it in GitHub Desktop.
PhpUnit image assert function
This file contains hidden or 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
protected function assertImage($expected, $actual, $message = '') | |
{ | |
$descriptors = array( | |
array('pipe', 'r'), | |
array('pipe', 'w'), | |
array('pipe', 'w'), | |
); | |
$command = 'compare -metric RMSE ' . escapeshellarg($expected) . ' ' . escapeshellarg($actual) . ' /dev/null'; | |
$proc = proc_open($command, $descriptors, $pipes); | |
$diff = stream_get_contents($pipes[2]); | |
fclose($pipes[0]); | |
fclose($pipes[1]); | |
fclose($pipes[2]); | |
preg_match('#\((.+)\)#', $diff, $match); | |
$threshold = floatval($match[1]); | |
$this->assertLessThan(0.05, $threshold, $message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires imagemagick installed (not PHP Imagick extension)