| 1 |
<?php |
| 2 |
|
| 3 |
use SebastianBergmann\FileIterator\Facade; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class StructureTest extends \PHPUnit\Framework\TestCase { |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
public function testUnitTestFileNamesEndWithTest() { |
| 17 |
|
| 18 |
$rootPath = realpath( __DIR__ . '/..' ); |
| 19 |
$suitesPath = realpath( __DIR__ . '/../suites/' ); |
| 20 |
$testClassRegex = '/^(final )?class .* extends [\S]*(TestCase|TestBase)\\b/m'; |
| 21 |
|
| 22 |
$results = $this->recurseFiles( $rootPath ); |
| 23 |
|
| 24 |
$results = array_filter( |
| 25 |
$results, |
| 26 |
static function ( $filename ) use ( $testClassRegex, $suitesPath ) { |
| 27 |
|
| 28 |
if ( str_starts_with( $filename, $suitesPath ) || |
| 29 |
str_ends_with( $filename, 'Test.php' ) |
| 30 |
) { |
| 31 |
return false; |
| 32 |
} |
| 33 |
$contents = file_get_contents( $filename ); |
| 34 |
return preg_match( $testClassRegex, $contents ); |
| 35 |
} |
| 36 |
); |
| 37 |
$strip = strlen( $rootPath ) + 1; |
| 38 |
foreach ( $results as $k => $v ) { |
| 39 |
$results[$k] = substr( $v, $strip ); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
$results = array_values( $results ); |
| 44 |
|
| 45 |
$this->assertEquals( |
| 46 |
[], |
| 47 |
$results, |
| 48 |
"Unit test file in $rootPath must end with Test." |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
private function recurseFiles( $dir ) { |
| 53 |
return ( new Facade() )->getFilesAsArray( $dir, [ '.php' ] ); |
| 54 |
} |
| 55 |
} |