-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[BrowserKit] Fixed BC-break introduced by rename of Client to Browser #31040
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
Conversation
class_alias() doesn't work really well for deprecation layers because the notice is thrown depending on the loading order. Deprecating the service in favor of test.browser might be better? |
It is true that <?php
declare(strict_types=1);
namespace FriendsOfBehat\SymfonyExtension\Driver;
use Behat\Mink\Driver\BrowserKitDriver;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\HttpKernel\KernelInterface;
final class SymfonyDriver extends BrowserKitDriver
{
public function __construct(KernelInterface $kernel, string $baseUrl)
{
if (!$kernel->getContainer()->has('test.client')) {
throw new \RuntimeException(sprintf(
'Kernel "%s" used by Behat with "%s" environment and debug %s does not have "test.client" service. ' . "\n" .
'Please make sure the kernel is using "test" environment or have "framework.test" configuration option enabled.',
get_class($kernel),
$kernel->getEnvironment(),
$kernel->isDebug() ? 'enabled' : 'disabled'
));
}
$testClient = $kernel->getContainer()->get('test.client');
if (!$testClient instanceof Client) {
throw new \RuntimeException(sprintf(
'Service "test.client" should be an instance of "%s", "%s" given.',
Client::class,
get_class($testClient)
));
}
parent::__construct($testClient, $baseUrl);
}
} The service Or do you mean that in addition to the |
I was hopping that creating a new service would be enough but it wouldn't allow passing legacy type hints. |
If I am not mistaken, the Client should also have the same public interface as AbstractBrowser then. I'm not sure if that's worth it? Wouldn't it be against the intent of the original PR? It is possible though, rename AbstractBrowser back to Client. Create a new empty AbstractBrowser extending from Client. Then upon removal of Client drop AbstractBrowser and rename Client to AbstractBrowser. Bit cumbersome, but perhaps the safest way. |
It does have the same public interface, see its implementation, unless I missed something? |
I meant that all methods from AbstractBrowser have to be moved to Client if Client is the top of the hierarchy. Anyway, I am willing to do this. However I am not sure how deprecation will work. We cannot trigger an error in Client then as AbstractBrowser will depend on it? |
We will have to remove the deprecation notice and keep the annotation. DebugClassLoader will still warn ppl that extend Client directly. |
Sounds good. I think I have one last question concerning the deprecation messages. Currently the tests expect them on AbstractBrowser methods.
If I alter the class hierarchy
I can do three things:
I don't know how you guys usually solve this. I don't see evidence of variant 2 or 3 in the code base so far. Solution 1 is the way to go? Thanks for bearing with me and my questions 👍 |
Option 1. makes the most sense to me: all existing code uses |
You are right :). I have pushed a separate commit with the changes we discussed. |
Thank you @Devristo. |
… to Browser (Devristo) This PR was squashed before being merged into the 4.3-dev branch (closes #31040). Discussion ---------- [BrowserKit] Fixed BC-break introduced by rename of Client to Browser | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31039 | License | MIT | Doc PR | Since #30541 the inheritance hierarchy of `\Symfony\Component\BrowserKit\Client` has changed. Notably the test.client no longer is an instance of `\Symfony\Component\BrowserKit\Client`. This PR uses `class_alias` to fix the class hierarchy similarly as has been done in Twig. In this case I copied the approach of `Twig_TokenParser_AutoEscape` and `\Twig\TokenParser\AutoEscapeTokenParser` Commits ------- 6a94dea [BrowserKit] Fixed BC-break introduced by rename of Client to Browser
Since #30541 the inheritance hierarchy of
\Symfony\Component\BrowserKit\Client
has changed. Notably the test.client no longer is an instance of\Symfony\Component\BrowserKit\Client
.This PR uses
class_alias
to fix the class hierarchy similarly as has been done in Twig. In this case I copied the approach ofTwig_TokenParser_AutoEscape
and\Twig\TokenParser\AutoEscapeTokenParser