-
Notifications
You must be signed in to change notification settings - Fork 29
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
PHPStan improvements #100
Conversation
src/FixturesKernel.php
Outdated
@@ -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'; |
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.
why making those public constants ?
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.
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
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.
Are values of these constants used anywhere else outside of this class?
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 (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.
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.
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
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.
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.
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.
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/Form/GeneralTest.php
Outdated
@@ -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')); |
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.
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).
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.
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:
- keep it as is with the
FixturesKernel
(feels like a bad idea, from your description) - put it in
TestCase
(should be fine considering thattests/
must be exported) - 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.
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.
That begs the follow-up question...since this test suite IS the main point of project, shouldn't everything in
tests/
actually be insrc/
?
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)
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.
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.
} | ||
} | ||
|
||
/** | ||
* @return AbstractConfig | ||
* | ||
* @throws \UnexpectedValueException if the global driver_config_factory returns an invalid object |
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.
the description should probably be kept
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.
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)
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.
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.
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.
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.
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). |
@aik099 I'd like to see some go-ahead from @stof first, anyway.
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) |
Here are test suite tests (with changes from this PR) on the drivers:
. Separate workflow for testing test suite changes for all active drivers is implemented in #103 . |
No description provided.