-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fixed bad base path edge case #3434
Fixed bad base path edge case #3434
Conversation
$relPath = substr($path, $rootPathIndex); | ||
$pathPrefix = substr($pathPrefix, $rootPathIndex); | ||
$basePathArr = explode(DIRECTORY_SEPARATOR, $pathPrefix); | ||
while ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 0 spaces after opening bracket; newline found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... because of overly complex while condition. Please make code simplification suggestions. (@Nitpick-CI, Not you personally, I know you're just an automated tool.)
Thanks for the feedback... I will revise the code as soon as I'm able. |
Thanks, will be waiting for update! |
@DavertMik, Thanks... I will update this PR as soon as I can find time to update it. I didn't see a way to PM you, but wanted to know if you could take a peek at an issue I think I found: 2.2...loren-osborn:losborn_configModsLooksLikeABug It shouldn't be hard to write a unit test to catch this issue... (If a enabled module in the module |
bd4f62f
to
64bec19
Compare
return $path; | ||
} | ||
// peel off optional absoluteness prefixes | ||
$relPath = substr($path, strlen( $pathAbsPrefix)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Expected 1 space after comma in function call; 14 found
- Space after opening parenthesis of function call prohibited
@DavertMik, let me know if you found this much easier to follow. I prefer descriptive variable and method names to comments, but I included good comments too. |
@loren-osborn looks better now, however I still have doubts. I think code still can be simplified but I'm not sure how 😶 Could you add tests to it? They should go to @Naktibalda @sergeyklay what your thoughts of it? |
+1 for tests because it is core functionality |
I'm certainly down with tests... It's more a matter of knowing what kind of tests, and where to find them. I just found the right place for unit tests for this particular issue, and the issue I found with
@DavertMik, @sergeyklay, where else do you suggest I put tests for these two issues. I currently don't have a setup where I can run the tests (might I suggest a |
I found I think that it would be much easier to unit test it, if project dir was passed in as a parameter: function codecept_relative_path($path)
{
return \Codeception\Configuration::getRelativeDir($path, \Codeception\Configuration::projectDir());
} All you need to run ConfigurationTest is PHP, |
@Naktibalda, passing the project directory as an argument is a great idea. I was trying to keep the As far as a dev environment, I currently have limited storage to keep multiple VMs around, and my current VM is missing a PECL module that composer requires for Codeception. (I don't want to alter one project's dev environment VM for development of another.) I'll see what I can put together if I have the time, but I won't make any promises with my looming deadlines. |
I think I took what @Naktibalda said to heart. I rewrote this so I can inject both I'm at dinner now, but hope to |
Status update: Wrote some tests, found some edge casses I missed. I'll address before I push my code. |
* @param string $dirSep | ||
* @return string | ||
*/ | ||
public static function getRelativeDir($path, $projDir, $dirSep = DIRECTORY_SEPARATOR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect spacing between default value and equals sign for argument $dirSep
; expected 1 but found 2
Enabled test cases... disabled code changes... test suite should FAIL |
return substr($path, strlen($projDir)); | ||
} | ||
// Identify any absoluteness prefix (like '/' in Unix or "C:\\" in Windows) | ||
$pathAbsPrefix = self::getPathAbsolutenessPrefix($path, $dirSep); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after comma in function call; 4 found
@DavertMik, @sergeyklay, @Naktibalda, I think the Once I get a signoff from one of you, I can get started on a git rebase squash of this code. (Of course, I'm still open to suggestions. It's far from the most readable thing I've written.) |
...with unit tests (Thanks for suggestions from @DavertMik and @Naktibalda)
a89e345
to
13e668d
Compare
All changed squashed into single commit. Original unsquashed commits are still available here: https://github.com/loren-osborn/Codeception/tree/losborn_badBasePathFix_unsquashed Thanks for all of your help. Do any of you want any additional revisions before merging this? (i.e. It may be a good idea to build the output array returned by |
public static function getRelativeDir($path, $projDir, $dirSep = DIRECTORY_SEPARATOR) | ||
{ | ||
// ensure $projDir ends with a trailing $dirSep | ||
$projDir = preg_replace('/'.preg_quote($dirSep, '/').'*$/', $dirSep, $projDir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not an issue, but my preferred way is $projDir = rtrim($projDir, $dirSep) . $dirSep;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes... Probably clearer your way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, don't use regex here. rtrim is much clearer
@DavertMik, @sergeyklay, @Naktibalda, Status update:
|
Your PR looks good to me, I am waiting for somebody else to review the code before merging it. |
Thanks |
Thanks. I think you did a great job and this PR looks almost perfect to me. Especially tests look great. Sorry for this additional request but that's how we can maintain the clean and sane codebase. |
This seems like a very reasonable request , though I'm leaning toward |
Looks good. Will be waiting for it |
@loren-osborn you are about to miss a release. |
Thanks @loren-osborn |
@DavertMik, @Naktibalda thanks for picking up the slack on this. My last comment in this PR was actually in the few days between when I was laid off from my last employer and when my daughter was born, so you can imagine I was a bit distracted. I ended up being out of work about 6 months and didn't realize you had actually merged this. Thank you for picking up the slack in my absence. |
...with unit tests (Thanks for suggestions from @DavertMik and @Naktibalda)
This is a fix to the issue I brought up in #3433 .
While the code is a bit rough around the edges, it appears to conform to project guidelines, and resolves the issue. Any suggestions to make the code more elegant are welcome.