Remove inline @var annotations; fix spec session name; fix @var placement
- Replace all local-variable @var annotations with proper type guards:
- MinkExtension configure closure: build inner array directly
($sessions[$driverType] = [$driverType => ...]) to avoid mixed offset access
- MinkExtension loadSessions: add is_array($session) guard inside foreach
so PHPStan narrows $session from mixed to array before key() call
- DriverFactory::buildDriver @param broadened from array<string, mixed>
to array<mixed> — is_array() only narrows to array<mixed> (key type
unknown), so array<string, mixed> was unreachable at the call site
- MinkAwareInitializer: move @var from inside constructor parameter list
to a proper @param on the method docblock
- SessionsListenerSpec: replace 'goutte' (deleted driver) with
'browserkit_http' as the example default session name
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,7 +15,7 @@ class SessionsListenerSpec extends ObjectBehavior
|
||||
{
|
||||
public function let(Mink $mink, ScenarioTested $event, FeatureNode $feature, ScenarioNode $scenario, Suite $suite)
|
||||
{
|
||||
$this->beConstructedWith($mink, 'goutte', 'selenium2', ['selenium2', 'sahi']);
|
||||
$this->beConstructedWith($mink, 'browserkit_http', 'selenium2', ['selenium2', 'sahi']);
|
||||
|
||||
$event->getSuite()->willReturn($suite);
|
||||
$event->getFeature()->willReturn($feature);
|
||||
@@ -38,7 +38,7 @@ class SessionsListenerSpec extends ObjectBehavior
|
||||
public function it_resets_the_default_session_before_scenarios($event, $mink)
|
||||
{
|
||||
$mink->resetSessions()->shouldBeCalled();
|
||||
$mink->setDefaultSessionName('goutte')->shouldBeCalled();
|
||||
$mink->setDefaultSessionName('browserkit_http')->shouldBeCalled();
|
||||
|
||||
$this->prepareDefaultMinkSession($event);
|
||||
}
|
||||
@@ -120,7 +120,7 @@ class SessionsListenerSpec extends ObjectBehavior
|
||||
public function it_fails_when_the_javascript_session_is_used_but_not_defined($event, $mink, $feature, $suite)
|
||||
{
|
||||
$suite->hasSetting('mink_javascript_session')->willReturn(false);
|
||||
$this->beConstructedWith($mink, 'goutte', null);
|
||||
$this->beConstructedWith($mink, 'browserkit_http', null);
|
||||
$feature->getTags()->willReturn(['javascript']);
|
||||
|
||||
$this->shouldThrow(new ProcessingException('The @javascript tag cannot be used without enabling a javascript session'))
|
||||
@@ -151,7 +151,7 @@ class SessionsListenerSpec extends ObjectBehavior
|
||||
{
|
||||
$scenario->hasTag('insulated')->willReturn(true);
|
||||
$mink->stopSessions()->shouldBeCalled();
|
||||
$mink->setDefaultSessionName('goutte')->shouldBeCalled();
|
||||
$mink->setDefaultSessionName('browserkit_http')->shouldBeCalled();
|
||||
|
||||
$this->prepareDefaultMinkSession($event);
|
||||
}
|
||||
@@ -160,7 +160,7 @@ class SessionsListenerSpec extends ObjectBehavior
|
||||
{
|
||||
$feature->hasTag('insulated')->willReturn(true);
|
||||
$mink->stopSessions()->shouldBeCalled();
|
||||
$mink->setDefaultSessionName('goutte')->shouldBeCalled();
|
||||
$mink->setDefaultSessionName('browserkit_http')->shouldBeCalled();
|
||||
|
||||
$this->prepareDefaultMinkSession($event);
|
||||
}
|
||||
|
||||
@@ -23,9 +23,11 @@ use Behat\MinkExtension\Context\MinkAwareContext;
|
||||
*/
|
||||
class MinkAwareInitializer implements ContextInitializer
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly Mink $mink,
|
||||
/** @var array<string, mixed> */
|
||||
private readonly array $parameters,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class AppiumFactory extends Selenium2Factory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
* @param array<mixed> $config
|
||||
*/
|
||||
public function buildDriver(array $config): Definition
|
||||
{
|
||||
|
||||
@@ -41,7 +41,7 @@ class BrowserKitFactory implements DriverFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
* @param array<mixed> $config
|
||||
*/
|
||||
public function buildDriver(array $config): Definition
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ class BrowserStackFactory extends Selenium2Factory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
* @param array<mixed> $config
|
||||
*/
|
||||
public function buildDriver(array $config): Definition
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ interface DriverFactory
|
||||
public function configure(ArrayNodeDefinition $builder): void;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
* @param array<mixed> $config
|
||||
*/
|
||||
public function buildDriver(array $config): Definition;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class SahiFactory implements DriverFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
* @param array<mixed> $config
|
||||
*/
|
||||
public function buildDriver(array $config): Definition
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ class SauceLabsFactory extends Selenium2Factory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
* @param array<mixed> $config
|
||||
*/
|
||||
public function buildDriver(array $config): Definition
|
||||
{
|
||||
|
||||
@@ -39,7 +39,7 @@ class Selenium2Factory implements DriverFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
* @param array<mixed> $config
|
||||
*/
|
||||
public function buildDriver(array $config): Definition
|
||||
{
|
||||
@@ -47,9 +47,7 @@ class Selenium2Factory implements DriverFactory
|
||||
throw new \RuntimeException(sprintf('Install MinkSelenium2Driver in order to use %s driver.', $this->getDriverName()));
|
||||
}
|
||||
|
||||
/** @var array<string, mixed> $capabilities */
|
||||
$capabilities = is_array($config['capabilities']) ? $config['capabilities'] : [];
|
||||
/** @var array<string, mixed> $extraCapabilities */
|
||||
$extraCapabilities = is_array($capabilities['extra_capabilities']) ? $capabilities['extra_capabilities'] : [];
|
||||
unset($capabilities['extra_capabilities']);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class Selenium4Factory implements DriverFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
* @param array<mixed> $config
|
||||
*/
|
||||
public function buildDriver(array $config): Definition
|
||||
{
|
||||
|
||||
@@ -37,7 +37,7 @@ class SeleniumFactory implements DriverFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
* @param array<mixed> $config
|
||||
*/
|
||||
public function buildDriver(array $config): Definition
|
||||
{
|
||||
|
||||
@@ -34,6 +34,9 @@ class WebdriverClassicFactory implements DriverFactory
|
||||
->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<mixed> $config
|
||||
*/
|
||||
public function buildDriver(array $config): Definition
|
||||
{
|
||||
if (!class_exists(WebdriverClassicDriver::class)) {
|
||||
|
||||
@@ -40,7 +40,7 @@ class ZombieFactory implements DriverFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
* @param array<mixed> $config
|
||||
*/
|
||||
public function buildDriver(array $config): Definition
|
||||
{
|
||||
|
||||
@@ -124,13 +124,12 @@ class MinkExtension implements ExtensionInterface
|
||||
if (!array_key_exists($driverType, $v)) {
|
||||
continue;
|
||||
}
|
||||
/** @var array<string, array<string, mixed>> $sessions */
|
||||
$sessions = is_array($v['sessions']) ? $v['sessions'] : [];
|
||||
if (isset($sessions[$driverType])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sessions[$driverType][$driverType] = $v[$driverType];
|
||||
$sessions[$driverType] = [$driverType => $v[$driverType]];
|
||||
$v['sessions'] = $sessions;
|
||||
unset($v[$driverType]);
|
||||
}
|
||||
@@ -223,28 +222,25 @@ class MinkExtension implements ExtensionInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
* @param array<mixed> $config
|
||||
*/
|
||||
private function loadSessions(ContainerBuilder $container, array $config): void
|
||||
{
|
||||
/** @var string|null $defaultSession */
|
||||
$defaultSession = is_string($config['default_session']) ? $config['default_session'] : null;
|
||||
/** @var string|null $javascriptSession */
|
||||
$javascriptSession = is_string($config['javascript_session']) ? $config['javascript_session'] : null;
|
||||
/** @var string[] $javascriptSessions */
|
||||
$javascriptSessions = [];
|
||||
/** @var string[] $nonJavascriptSessions */
|
||||
$nonJavascriptSessions = [];
|
||||
|
||||
$minkDefinition = $container->getDefinition(self::MINK_ID);
|
||||
|
||||
/** @var array<string, array<string, mixed>> $sessions */
|
||||
$sessions = is_array($config['sessions']) ? $config['sessions'] : [];
|
||||
foreach ($sessions as $name => $session) {
|
||||
if (!is_array($session)) {
|
||||
continue;
|
||||
}
|
||||
$driver = (string) key($session);
|
||||
$factory = $this->driverFactories[$driver];
|
||||
|
||||
/** @var array<string, mixed> $driverConfig */
|
||||
$driverConfig = is_array($session[$driver]) ? $session[$driver] : [];
|
||||
$definition = new Definition('Behat\Mink\Session', [
|
||||
$factory->buildDriver($driverConfig),
|
||||
|
||||
Reference in New Issue
Block a user