Skip to content

Commit

Permalink
Merge pull request #67 from andrewnicols/testsMustHaveNamePattern
Browse files Browse the repository at this point in the history
Test files must be named _test.php
  • Loading branch information
stronk7 authored Sep 22, 2023
2 parents 163c65d + 9d80834 commit 0a4fc09
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
24 changes: 18 additions & 6 deletions moodle/Tests/MoodleUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,27 +476,39 @@ public static function isUnitTestProvider(): array
{
return [
'Not in tests directory' => [
'value' => '/path/to/standard/file.php',
'value' => '/path/to/standard/file_test.php',
'return' => false,
],
'In tests directory' => [
'value' => '/path/to/standard/tests/file.php',
'value' => '/path/to/standard/tests/file_test.php',
'return' => true,
],
'In tests directory but missing _test suffix' => [
'value' => '/path/to/standard/tests/file.php',
'return' => false,
],
'In tests directory but some idiot put a _test.php suffix on a directory' => [
'value' => '/path/to/standard/tests/some_test.php/file.php',
'return' => false,
],
'In test sub-directory' => [
'value' => '/path/to/standard/tests/sub/file.php',
'value' => '/path/to/standard/tests/sub/file_test.php',
'return' => true,
],
'In test sub-directory but missing _test suffix' => [
'value' => '/path/to/standard/tests/sub/file.php',
'return' => false,
],
'Generator' => [
'value' => '/path/to/standard/tests/generator/file.php',
'value' => '/path/to/standard/tests/generator/file_test.php',
'return' => false,
],
'Fixture' => [
'value' => '/path/to/standard/tests/fixtures/file.php',
'value' => '/path/to/standard/tests/fixtures/file_test.php',
'return' => false,
],
'Behat' => [
'value' => '/path/to/standard/tests/behat/behat_test_file.php',
'value' => '/path/to/standard/tests/behat/behat_test_file_test.php',
'return' => false,
],
];
Expand Down
5 changes: 5 additions & 0 deletions moodle/Util/MoodleUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ public static function getMoodleRoot(File $file = null, bool $selfPath = true) {
*/
public static function isUnitTest(File $phpcsFile): bool
{
// If the file isn't called, _test.php, nothing to check.
if (stripos(basename($phpcsFile->getFilename()), '_test.php') === false) {
return false;
}

// If the file isn't under tests directory, nothing to check.
if (stripos($phpcsFile->getFilename(), '/tests/') === false) {
return false;
Expand Down

0 comments on commit 0a4fc09

Please sign in to comment.