Skip to content

Commit

Permalink
fixup! Various path normalisations
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Apr 1, 2024
1 parent 390f272 commit 9e04ff2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions moodle/Sniffs/PHPUnit/TestCaseNamesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function process(File $file, $pointer) {
if (!MoodleUtil::isUnitTest($file) && !$runningPHPUnit) {
return; // @codeCoverageIgnore
}
$fileName = basename(MoodleUtil::getStandardisedFilename($file));
$fileName = basename($file->getFilename());
$path = MoodleUtil::getStandardisedFilename($file);

// In order to cover the duplicates detection, we need to set some
// properties (caches) here. It's extremely hard to do
Expand Down Expand Up @@ -195,7 +196,7 @@ public function process(File $file, $pointer) {

// Add the new element.
$this->foundClasses[$fdqnClass][] = [
'file' => $fileName,
'file' => $path,
'line' => $tokens[$cStart]['line'],
];

Expand Down Expand Up @@ -234,8 +235,8 @@ public function process(File $file, $pointer) {
$relns = str_replace('\\', '/', substr(trim($namespace, ' \\'), $bspos + 1));

// Calculate the relative path under tests directory.
$dirpos = strripos(trim(dirname($fileName), ' /') . '/', '/tests/');
$reldir = str_replace('\\', '/', substr(trim(dirname($fileName), ' /'), $dirpos + 7));
$dirpos = strripos(trim(dirname($path), ' /') . '/', '/tests/');
$reldir = str_replace('\\', '/', substr(trim(dirname($path), ' /'), $dirpos + 7));

// Warning if the relative namespace does not match the relative directory.
if ($reldir !== $relns) {
Expand Down Expand Up @@ -282,7 +283,7 @@ public function process(File $file, $pointer) {

// Add the new element.
$this->proposedClasses[$fdqnProposed][] = [
'file' => $fileName,
'file' => $path,
'line' => $tokens[$cStart]['line'],
];

Expand Down

0 comments on commit 9e04ff2

Please sign in to comment.