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

PHPStan improvements #100

Merged
merged 11 commits into from
Jan 13, 2025
Merged

Conversation

uuf6429
Copy link
Member

@uuf6429 uuf6429 commented Jan 5, 2025

No description provided.

@@ -11,6 +11,9 @@

class FixturesKernel implements HttpKernelInterface
{
public const WEB_FIXTURES_DIR = __DIR__ . '/../web-fixtures';
public const KERNEL_FIXTURES_DIR = __DIR__ . '/../http-kernel-fixtures';
Copy link
Member

Choose a reason for hiding this comment

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

why making those public constants ?

Copy link
Member Author

@uuf6429 uuf6429 Jan 6, 2025

Choose a reason for hiding this comment

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

That was the main point actually, so that code needing those paths:

  • do not need to define their own path relative to their location
  • we get to see where those paths are used from one central place (instead of searching for 'web-fixtures' string)
  • if the classes using those constants are relocated, the path in constant value remains valid

Copy link
Member

Choose a reason for hiding this comment

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

Are values of these constants used anywhere else outside of this class?

Copy link
Member Author

@uuf6429 uuf6429 Jan 6, 2025

Choose a reason for hiding this comment

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

Yes (WEB_FIXTURES is used by FixturesKernel, GeneralTest and ChangeEventTest), testcases can use them when they need to use a specific fixture.

KERNEL_FIXTURES isn't used elsewhere in this case, it's not entirely clear to me where/when it is needed, but it feels like it should be public too.

Copy link
Member Author

@uuf6429 uuf6429 Jan 6, 2025

Choose a reason for hiding this comment

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

Kernel fixtures doesn't seem to be used outside at all: https://github.com/search?q=%22%2Fhttp-kernel-fixtures%22&type=code

Web fixtures is used also by users:
https://github.com/robertfausk/mink-panther-driver/blob/52aa735bc0cf05f5fd9406f4da56136b00b9c5cb/tests/Custom/EventsTest.php#L145

__DIR__.'/../../vendor/mink/driver-testsuite/web-fixtures/ could be replaced with TestCase::WEB_FIXTURES_DIR

Copy link
Member

Choose a reason for hiding this comment

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

what mink-panther-driver does is a huge hack though. They are altering the shared testsuite, meaning that what they run is not actually the shared testsuite (and so their driver might not respect the expected shared behavior, creating interoperability issues). I don't think we should consider this a valid use case.

Copy link
Member Author

@uuf6429 uuf6429 Jan 7, 2025

Choose a reason for hiding this comment

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

It's a hack, yes, but the intention is clear - they want to extend tests, not alter existing ones (they're adding a new fixture and the original tests are unaltered nor excluded in the config).

From user-perspective, there could be better ways (e.g. putting the fixture in a "custom" directory or somehow altering the php server), but that feels like it's also our responsibility to provide that.

In this case, for example, we could have provided a CUSTOM_WEB_FIXTURES constant which is exactly for this case. There might still be uses for WEB_FIXTURES... but in any case being public is just one side of that constant.

tests/Basic/CookieTest.php Outdated Show resolved Hide resolved
tests/Basic/CookieTest.php Outdated Show resolved Hide resolved
@@ -189,7 +191,7 @@ public function testAdvancedForm(): void
$notes->setValue('new notes');
$this->assertEquals('new notes', $notes->getValue());

$about->attachFile($this->mapRemoteFilePath(__DIR__ . '/../../web-fixtures/some_file.txt'));
$about->attachFile($this->mapRemoteFilePath(FixturesKernel::WEB_FIXTURES_DIR . '/some_file.txt'));
Copy link
Member

Choose a reason for hiding this comment

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

Making GeneralTest depend on the kernel is bad, because this introduces a hard dependency on symfony/http-kernel, while it is currently an optional dependency (this FixturesKernel is currently only used by the browserkit-driver testsuite, when running it with a KernelBrowser instead of doing actual HTTP requests to the test server).

Copy link
Member Author

Choose a reason for hiding this comment

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

In the beginning I was going to do it the other way round:

class TestCase {
    public const XXXXX;
}

class FixturesKernel {
    ...
    TestCase::XXXXX;
    ...
}

But then I figured that tests/ is normally expected not be exported (although that is not the case in this project).

That begs the follow-up question...since this test suite IS the main point of project, shouldn't everything in tests/ actually be in src/?

Anyway, we have these options:

  1. keep it as is with the FixturesKernel (feels like a bad idea, from your description)
  2. put it in TestCase (should be fine considering that tests/ must be exported)
  3. make a separate class in src/ just for these constants

I'll go for option 2, let me know if 3 sounds better or you have a different idea.

Copy link
Member

Choose a reason for hiding this comment

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

That begs the follow-up question...since this test suite IS the main point of project, shouldn't everything in tests/ actually be in src/?

no. I'd rather keep the shared testsuite under a tests folder for consistency (and also to avoid breaking the test setup of all drivers by forcing them to change the path to tests in their phpunit.xml)

Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't suggesting to merge src/ and tests/ now, I was more curious if there were specific reasons other than historical/compatibility. But this is a bit off-topic anyway.

I'd just like to know out of those 3 options if option 2 is fine.

tests/TestCase.php Outdated Show resolved Hide resolved
}
}

/**
* @return AbstractConfig
*
* @throws \UnexpectedValueException if the global driver_config_factory returns an invalid object
Copy link
Member

Choose a reason for hiding this comment

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

the description should probably be kept

Copy link
Member Author

@uuf6429 uuf6429 Jan 6, 2025

Choose a reason for hiding this comment

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

I wasn't sure if it would make sense to move it to createConfig or have it in both cases, but now that I think about it, it doesn't make sense at all: this is a private method of a class (not a trait even) so we don't really need to document it. Plus, the exception message is understandable enough.
(e.g. it would have made more sense to have it for createDriver and the like)

Copy link
Member

Choose a reason for hiding this comment

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

I'm also for keeping the description. It's now always clear when an exception is thrown just by looking at the DocBlock itself.

If the method is private it doesn't mean it should be less documented, because same documentation is also used by maintainers.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm also for keeping the description. It's now always clear when an exception is thrown just by looking at the DocBlock itself.

That will only apply to createConfig() which I expect to be rarely seen. getConfig would be more common and protected/public usages of getConfig even more than that.

If we care about documentation, then we should mention that exception in all cases (like I said, especially the API ones) not just to the internal one that no will ever actually see.

Otherwise I don't see the point of a 4-line comment explaining verbatim what the next 10 lines of code clearly do.

tests/Js/EventsTest.php Outdated Show resolved Hide resolved
http-kernel-fixtures/sub-folder/cookie_page4.php Outdated Show resolved Hide resolved
src/FixturesKernel.php Outdated Show resolved Hide resolved
tests/Basic/BasicAuthTest.php Show resolved Hide resolved
tests/Basic/BestPracticesTest.php Show resolved Hide resolved
tests/Form/GeneralTest.php Outdated Show resolved Hide resolved
tests/Js/ChangeEventTest.php Outdated Show resolved Hide resolved
@uuf6429 uuf6429 requested review from aik099 and stof January 7, 2025 15:02
tests/Basic/BasicAuthTest.php Show resolved Hide resolved
src/FixturesKernel.php Outdated Show resolved Hide resolved
src/FixturesKernel.php Outdated Show resolved Hide resolved
@uuf6429 uuf6429 requested a review from aik099 January 8, 2025 17:46
@aik099
Copy link
Member

aik099 commented Jan 8, 2025

There no issues left except for that exception comment in a DocBlock.

@uuf6429 , please test this new version of the driver test suite with all active Mink drivers using the lowest possible dependency version (likely you need to use PHP 7.2 for that).

@uuf6429
Copy link
Member Author

uuf6429 commented Jan 8, 2025

There no issues left except for that exception comment in a DocBlock.

@aik099 I'd like to see some go-ahead from @stof first, anyway.

please test this new version of the driver test suite with all active Mink drivers...

That's a whole lot of work (also because I don't know which are these active versions.. how about we add a new GH workflow (that is triggered manually) to do that? (as a separate PR of course, we could merge it before this one)

@aik099
Copy link
Member

aik099 commented Jan 9, 2025

Here are test suite tests (with changes from this PR) on the drivers:

  • MinkSelenium2Driver - no new failures (the right click test on Selenium 3 was already failing before)
  • webdriver-classic-driver - passed
  • MinkBrowserKitDriver - passed

.

Separate workflow for testing test suite changes for all active drivers is implemented in #103 .

@aik099 aik099 merged commit d549552 into minkphp:master Jan 13, 2025
2 checks passed
@uuf6429 uuf6429 deleted the chore/phpstan-improvements branch January 13, 2025 15:52
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.

3 participants