-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from creative-commoners/pulls/main/file-exists
FIX Use check_file_exists()
- Loading branch information
Showing
2 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class ScriptsTest extends TestCase | ||
{ | ||
/** | ||
* This is a weird unit-test as it's essentially linting, though it's useful to ensure that the scripts are valid | ||
* | ||
* Ensure that file_exists() isn't used any scripts as it it's a native PHP function that does not use $MODULE_DIR | ||
* Instead you need to use check_file_exists() which does use $MODULE_DIR | ||
*/ | ||
public function testNoFileExists() | ||
{ | ||
$scripts = glob(__DIR__ . '/../scripts/**/*.php'); | ||
foreach ($scripts as $script) { | ||
$contents = file_get_contents($script); | ||
$found = (bool) preg_match('#(?<!check_)file_exists\(#', $contents); | ||
$this->assertFalse($found, "Script $script has file_exists() in it, use check_file_exists() instead"); | ||
} | ||
// need at least one assertion or phpunit says this is a risky test | ||
$this->assertTrue(true); | ||
} | ||
} |