Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use consistent directory-separator in baseline #700

Merged
merged 18 commits into from
Oct 17, 2021
Merged

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Oct 3, 2021

closes #675

Copy link
Collaborator

@patrickkusebauch patrickkusebauch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the file path from the input in the constructor body? That way there is less chance somebody will forget to use it.

@staabm
Copy link
Contributor Author

staabm commented Oct 3, 2021

Since getcwd() path will be resolved at toString we would need normalization nevertheless in the methods

@staabm
Copy link
Contributor Author

staabm commented Oct 4, 2021

just extracted FileHelper::normalizePath() to de-duplicate the existing logic

src/AstRunner/AstMap/FileName.php Show resolved Hide resolved
@@ -19,13 +21,11 @@ public function toString(): string

$path = false !== $wd && 0 === strpos($this->path, $wd) ? substr($this->path, strlen($wd)) : $this->path;

// make paths/patterns cross-OS compatible
return str_replace('\\', '/', $path);
return FileHelper::normalizePath($path);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I see, the path is already normalized here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't really make a difference, but to compensate your comments I got rid of this ugly ternary and reduced the normalization to the very minimal

public function testPathNormalization(): void
{
$fileName = new AstMap\FileName('/path/to/file.php');
$this->assertSame('/path/to/file.php', $fileName->getFilepath());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we could mock getcwd method call here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? its not necessary for the current test.

it would only be necessary, in case you want to test the already existing functionality which was not changed by this PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it would help with test coverage. That is what I meant by "nice". Also, it makes the test fragile. (not really on GitHub but locally for sure). If I were to run the test in the path directory, it would fail mysteriously. It is a tiny thing, but it is IMHO good practice to mock out system dependencies, like the current working directory.

Copy link
Collaborator

@dbrumann dbrumann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@patrickkusebauch your criticism around mocking getcwd is valid, but I think it's not too pressing. We can cross that bridge when it comes to it.

Thanks @staabm

@dbrumann dbrumann merged commit fdece20 into qossmic:main Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

windows vs. linux baseline
4 participants