Skip to content

Commit

Permalink
adding the possibility to unit test the standard
Browse files Browse the repository at this point in the history
  • Loading branch information
AD7six committed Apr 25, 2012
1 parent 014b461 commit 07911bb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/CakePHPStandardTest.php
@@ -0,0 +1,51 @@
<?php
/**
* CakePHPStandardTest
*/
class CakePHPStandardTest extends PHPUnit_Framework_TestCase {

/**
* testFiles
*
* Run simple syntax checks, if the filename ends with pass.php - expect it to pass
*
* @access public
* @return void
*/
public function testFiles() {
$files = scandir(__DIR__ . '/files');
foreach($files as $file) {
if ($file[0] === '.') {
continue;
}
$expectPass = (bool)strpos('pass.php', $file);
$this->_testFile(__DIR__ . '/files/' . $file, $expectPass);
}
}

/**
* Test a file
*
* @param mixed $file
* @param mixed $expectPass
* @access protected
* @return void
*/
protected function _testFile($file, $expectPass = true) {
exec("phpcs --standard=CakePHP $file", $output, $return);
$outputStr = implode($output, "\n");
if ($expectPass) {
$this->assertRegExp(
"/FAILURES!/",
$outputStr,
basename($file) . ' - expected failures, none reported. ' . $outputStr

This comment has been minimized.

Copy link
@ceeram

ceeram Nov 17, 2012

Contributor

Arent the error mesages swapped here?, if $expectPass is true, the message says "expected failures"

This comment has been minimized.

Copy link
@markstory

markstory Nov 17, 2012

Member

The code does read a bit backwards, but as far as I know its been working so far, unless all the tests are backwards 😖

This comment has been minimized.

Copy link
@ceeram

ceeram Nov 17, 2012

Contributor

This comment has been minimized.

Copy link
@jrbasso

jrbasso Nov 17, 2012

Member

@ceeram is right. The message shows when the assert fail. In this case, we expect the phpcs to fail, so the assert error message is to not expect failure.

);
} else {
$this->assertNotRegExp(
"/FAILURES!/",
$outputStr,
basename($file) . ' - expected no failure, some were reported. ' . $outputStr
);
}
}
}
5 changes: 5 additions & 0 deletions tests/files/space_indented.php
@@ -0,0 +1,5 @@
<?php
$array = array(1, 2, 3);
foreach($array as $i) {
echo $i;
}
5 changes: 5 additions & 0 deletions tests/files/tab_indented_pass.php
@@ -0,0 +1,5 @@
<?php
$array = array(1, 2, 3);
foreach($array as $i) {
echo $i;
}

0 comments on commit 07911bb

Please sign in to comment.