- 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>
96 lines
3.5 KiB
PHP
96 lines
3.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Behat MinkExtension.
|
|
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Behat\MinkExtension\ServiceContainer\Driver;
|
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
|
use Symfony\Component\DependencyInjection\Definition;
|
|
|
|
class SauceLabsFactory extends Selenium2Factory
|
|
{
|
|
public function getDriverName(): string
|
|
{
|
|
return 'sauce_labs';
|
|
}
|
|
|
|
public function configure(ArrayNodeDefinition $builder): void
|
|
{
|
|
$builder
|
|
->children()
|
|
->scalarNode('username')->defaultValue(getenv('SAUCE_USERNAME'))->end()
|
|
->scalarNode('access_key')->defaultValue(getenv('SAUCE_ACCESS_KEY'))->end()
|
|
->booleanNode('connect')->defaultFalse()->end()
|
|
->scalarNode('browser')->defaultValue('firefox')->end()
|
|
->append($this->getCapabilitiesNode())
|
|
->end()
|
|
;
|
|
}
|
|
|
|
/**
|
|
* @param array<mixed> $config
|
|
*/
|
|
public function buildDriver(array $config): Definition
|
|
{
|
|
$host = 'ondemand.saucelabs.com';
|
|
if ((bool) $config['connect']) {
|
|
$host = 'localhost:4445';
|
|
}
|
|
|
|
$config['wd_host'] = sprintf('%s:%s@%s/wd/hub', is_string($config['username']) ? $config['username'] : '', is_string($config['access_key']) ? $config['access_key'] : '', $host);
|
|
|
|
return parent::buildDriver($config);
|
|
}
|
|
|
|
protected function getCapabilitiesNode(): ArrayNodeDefinition
|
|
{
|
|
$node = parent::getCapabilitiesNode();
|
|
|
|
$node
|
|
->children()
|
|
->scalarNode('platform')->defaultValue('Linux')->end()
|
|
->scalarNode('selenium-version')->end()
|
|
->scalarNode('max-duration')->end()
|
|
->scalarNode('command-timeout')->end()
|
|
->scalarNode('idle-timeout')->end()
|
|
->scalarNode('build')->info('will be set automatically based on the TRAVIS_BUILD_NUMBER environment variable if available')->end()
|
|
->arrayNode('custom-data')
|
|
->useAttributeAsKey('')
|
|
->prototype('variable')->end()
|
|
->end()
|
|
->scalarNode('screen-resolution')->end()
|
|
->scalarNode('tunnel-identifier')->info('will be set automatically based on the TRAVIS_JOB_NUMBER environment variable if available')->end()
|
|
->arrayNode('prerun')
|
|
->children()
|
|
->scalarNode('executable')->isRequired()->end()
|
|
->arrayNode('args')->prototype('scalar')->end()->end()
|
|
->booleanNode('background')->defaultFalse()->end()
|
|
->end()
|
|
->end()
|
|
->booleanNode('record-video')->end()
|
|
->booleanNode('record-screenshots')->end()
|
|
->booleanNode('capture-html')->end()
|
|
->booleanNode('disable-popup-handler')->end()
|
|
->end()
|
|
->validate()
|
|
->ifTrue(function (mixed $v): bool {return !is_array($v) || empty($v['custom-data']); })
|
|
->then(function (mixed $v): mixed {
|
|
if (is_array($v)) {
|
|
unset($v['custom-data']);
|
|
}
|
|
|
|
return $v;
|
|
})
|
|
->end()
|
|
;
|
|
|
|
return $node;
|
|
}
|
|
}
|