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

Rename Path to BasePath #393

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Rename Path to BasePath #393

wants to merge 5 commits into from

Conversation

danon
Copy link
Contributor

@danon danon commented May 31, 2022

No description provided.

@danon danon requested a review from budziam as a code owner May 31, 2022 08:09
@danon danon marked this pull request as draft May 31, 2022 08:09
@danon danon changed the title [Draft] Rename Path to BasePath Rename Path to BasePath May 31, 2022
@danon danon force-pushed the path branch 6 times, most recently from 9909b3c to 98bf91f Compare May 31, 2022 18:00
// when
$childPath = $path->append($appendant);
// then
$this->assertSameWindows('uno\dos\tres', $childPath->toString());
Copy link
Member

Choose a reason for hiding this comment

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

Please consider making DIRECTORY_SEPARATOR injectable for the Path class. That way unit tests are going to be system agnostic.

Copy link
Contributor Author

@danon danon Jun 12, 2022

Choose a reason for hiding this comment

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

Aren't they now? These tests pass both on windows and unix currently.

Copy link
Member

Choose a reason for hiding this comment

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

However, to be able to test windows behavior you need to run tests on windows VM. You can't be sure this code works correctly with windows when running tests on a unix-based system.

Copy link
Contributor Author

@danon danon Jun 12, 2022

Choose a reason for hiding this comment

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

@budziam Is there a feature request to build Windows paths on Unix and vice-versa? Because if there isn't, there's no way to test it. And to test it, it would mean to require that functionallity. However it seems off, doesn't it?

Perhaps to test it both on windows and unix, we can employ the same strategy we use for testing both php8 and php7, which are github actions. It wouldn't be too hard to create runner-matrix with values runs-on: ubuntu-latest and runs-on: windows-latest (also macos-lates is also available). We can also design the matrix in such a way that tests php5.6-php8.1 run on ubuntu, and only one version of php runs on windows, to save resources and time.

Please consider making DIRECTORY_SEPARATOR injectable for the Path class. That way unit tests are going to be system agnostic.

Tests would become more flexible, yes, but the implementation would become less cohesive.

If you parametrize the separator, a smart way to do would be for example to throw exception if someone passes "|" or "" as a separator, but that's unnecessary logic that will never be used in production, since 100% usages will be "build windows path on windows" or "build unix path on unix".

Copy link
Member

@budziam budziam Jun 13, 2022

Choose a reason for hiding this comment

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

CPU costs money and shop sms was never intended to be run on windows instances. Running tests against windows VMs is not an acceptable approach.

That leaves us with 2 options:

  • pass DIRECTORY_SEPARATOR to the Path class
  • mock DIRECTORY_SEPARATOR on the global level (I don't know if that's even possible)

Copy link
Contributor Author

@danon danon Jun 13, 2022

Choose a reason for hiding this comment

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

Github Actions cost money?

shop sms was never intended to be run on windows instances

We either support windows or we don't.

If we do, running CI/CD on windows is a good idea. If we don't, then this dilema doesn't make sense and making Path work on Windows doesn't make sense anyway.

But I understand - you work on Unix machine, and want to make sure it works on Windows, without running windows yourself. That makes sense.

@danon
Copy link
Contributor Author

danon commented Jun 30, 2022

@budziam Idea of testing code for a given system without that system is not generally a doable thing.

For example, some operations behave differently on 32 and 64 bit systems, and you can't test what application would bahave on it, without actually running it, you can't mock the max integer value for example, there's just no way. This is generally true for all kinds of system dependendencies.

I think DIRECTORY_SEPARATOR is one of them. Yes, you can pass either "/" or "\\" to the class, but I think that's not the best idea. I really don't think parametrizing the Path class is the way to go.

But if you're certain you want to parametrize the separator, then we'll do it that way.

@danon danon force-pushed the path branch 3 times, most recently from abc4177 to 01c91cc Compare July 26, 2022 10:19
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.

None yet

2 participants