Skip to content

Commit 3ed86d7

Browse files
authored
Merge pull request #217 from loic425/fix/lazy-object-with-sf-7.3
Fix Mink lazy object with SF7.3 and PHP 8.4
2 parents 814dc0e + 08c7d24 commit 3ed86d7

File tree

14 files changed

+105
-28
lines changed

14 files changed

+105
-28
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
php-version:
20-
- '8.1'
2120
- '8.2'
21+
- '8.3'
22+
- '8.4'
2223
symfony-version:
23-
- '6.2.*'
24-
- '6.4.*'
2524
- '7.0.*'
26-
exclude:
25+
- '7.3.*'
26+
include:
2727
- php-version: '8.1'
28-
symfony-version: '7.0.*'
28+
symfony-version: '6.4.*'
2929
steps:
3030
- name: Checkout
3131
uses: actions/checkout@v3

.php-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.3

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
],
1313
"require": {
1414
"php": "^8.1",
15-
"behat/behat": "^3.6.1",
16-
"symfony/dependency-injection": "^6.2 || ^7.0",
17-
"symfony/http-kernel": "^6.2 || ^7.0"
15+
"behat/behat": "^3.22",
16+
"symfony/dependency-injection": "^6.4 || ^7.0",
17+
"symfony/http-kernel": "^6.4 || ^7.0"
1818
},
1919
"require-dev": {
2020
"behat/mink-browserkit-driver": "^2.0",
@@ -24,11 +24,11 @@
2424
"friends-of-behat/page-object-extension": "^0.3.2",
2525
"friends-of-behat/service-container-extension": "^1.1",
2626
"sylius-labs/coding-standard": ">=4.1.1, <=4.2.1",
27-
"symfony/browser-kit": "^6.2 || ^7.0",
28-
"symfony/framework-bundle": "^6.2 || ^7.0",
29-
"symfony/process": "^6.2 || ^7.0",
30-
"symfony/yaml": "^6.2 || ^7.0",
31-
"vimeo/psalm": "4.30.0"
27+
"symfony/browser-kit": "^6.4 || ^7.0",
28+
"symfony/framework-bundle": "^6.4 || ^7.0",
29+
"symfony/process": "^6.4 || ^7.0",
30+
"symfony/yaml": "^6.4 || ^7.0",
31+
"vimeo/psalm": "^6.0"
3232
},
3333
"suggest": {
3434
"behat/mink-browserkit-driver": "^2.0",

psalm.xml

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,62 @@
1414
</projectFiles>
1515

1616
<issueHandlers>
17-
<UndefinedClass>
18-
<errorLevel type="suppress">
19-
<referencedClass name="Symfony\Component\BrowserKit\AbstractBrowser" />
20-
<referencedClass name="Symfony\Component\BrowserKit\Client" />
21-
<referencedClass name="Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator" />
22-
</errorLevel>
23-
</UndefinedClass>
2417
<InvalidAttribute>
2518
<errorLevel type="suppress">
2619
<file name="src/Mink/MinkParameters.php" />
2720
</errorLevel>
2821
</InvalidAttribute>
2922

23+
<InvalidOperand>
24+
<errorLevel type="suppress">
25+
<file name="src/ServiceContainer/SymfonyExtension.php" />
26+
</errorLevel>
27+
</InvalidOperand>
28+
29+
<InvalidReturnStatement>
30+
<errorLevel type="suppress">
31+
<file name="src/Context/Environment/InitializedSymfonyExtensionEnvironment.php" />
32+
</errorLevel>
33+
</InvalidReturnStatement>
34+
35+
<InvalidReturnType>
36+
<errorLevel type="suppress">
37+
<file name="src/Context/Environment/InitializedSymfonyExtensionEnvironment.php" />
38+
</errorLevel>
39+
</InvalidReturnType>
40+
41+
<MissingTemplateParam>
42+
<errorLevel type="suppress">
43+
<file name="src/Mink/MinkParameters.php" />
44+
</errorLevel>
45+
</MissingTemplateParam>
46+
3047
<!-- Workaround for https://github.com/vimeo/psalm/issues/7026 -->
3148
<ReservedWord>
3249
<errorLevel type="suppress">
3350
<directory name="src" />
3451
</errorLevel>
3552
</ReservedWord>
53+
54+
<UndefinedClass>
55+
<errorLevel type="suppress">
56+
<referencedClass name="Symfony\Component\BrowserKit\AbstractBrowser" />
57+
<referencedClass name="Symfony\Component\BrowserKit\Client" />
58+
<referencedClass name="Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator" />
59+
</errorLevel>
60+
</UndefinedClass>
61+
62+
<UndefinedInterfaceMethod>
63+
<errorLevel type="suppress">
64+
<file name="src/ServiceContainer/SymfonyExtension.php" />
65+
</errorLevel>
66+
</UndefinedInterfaceMethod>
67+
68+
<UnusedForeachValue>
69+
<errorLevel type="suppress">
70+
<file name="src/Bundle/DependencyInjection/FriendsOfBehatSymfonyExtensionExtension.php" />
71+
<file name="src/ServiceContainer/SymfonyExtension.php" />
72+
</errorLevel>
73+
</UnusedForeachValue>
3674
</issueHandlers>
3775
</psalm>

src/Bundle/DependencyInjection/FriendsOfBehatSymfonyExtensionExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
final class FriendsOfBehatSymfonyExtensionExtension extends Extension implements CompilerPassInterface
2424
{
25+
#[\Override]
2526
public function load(array $configs, ContainerBuilder $container): void
2627
{
2728
$this->provideMinkIntegration($container);
@@ -31,6 +32,7 @@ public function load(array $configs, ContainerBuilder $container): void
3132
$container->registerForAutoconfiguration(Context::class)->addTag('fob.context');
3233
}
3334

35+
#[\Override]
3436
public function process(ContainerBuilder $container): void
3537
{
3638
$this->provideBrowserKitIntegration($container);

src/Context/Environment/Handler/ContextServiceEnvironmentHandler.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ public function registerContextInitializer(ContextInitializer $contextInitialize
5151
$this->contextInitializers[] = $contextInitializer;
5252
}
5353

54+
#[\Override]
5455
public function supportsSuite(Suite $suite): bool
5556
{
5657
return $suite->hasSetting('contexts');
5758
}
5859

60+
#[\Override]
5961
public function buildEnvironment(Suite $suite): Environment
6062
{
6163
$symfonyContexts = [];
@@ -65,7 +67,6 @@ public function buildEnvironment(Suite $suite): Environment
6567
continue;
6668
}
6769

68-
/** @var object $service */
6970
$service = $this->getContainer()->get($serviceId);
7071

7172
$symfonyContexts[$serviceId] = get_class($service);
@@ -79,6 +80,7 @@ public function buildEnvironment(Suite $suite): Environment
7980
return new UninitializedSymfonyExtensionEnvironment($suite, $symfonyContexts, $delegatedEnvironment);
8081
}
8182

83+
#[\Override]
8284
public function supportsEnvironmentAndSubject(Environment $environment, $testSubject = null): bool
8385
{
8486
return $environment instanceof UninitializedSymfonyExtensionEnvironment;
@@ -87,6 +89,7 @@ public function supportsEnvironmentAndSubject(Environment $environment, $testSub
8789
/**
8890
* @throws EnvironmentIsolationException
8991
*/
92+
#[\Override]
9093
public function isolateEnvironment(Environment $environment, $testSubject = null): Environment
9194
{
9295
$this->assertEnvironmentCanBeIsolated($environment, $testSubject);
@@ -158,7 +161,12 @@ private function cloneSuiteWithoutContexts(Suite $suite, array $contextsToRemove
158161
return new GenericSuite($suite->getName(), array_merge($suite->getSettings(), ['contexts' => $contexts]));
159162
}
160163

161-
private function normalizeContext($context): string
164+
/**
165+
* @return (int|string)|false
166+
*
167+
* @psalm-return array-key|false
168+
*/
169+
private function normalizeContext($context)
162170
{
163171
if (is_array($context)) {
164172
return current(array_keys($context));

src/Context/Environment/InitializedSymfonyExtensionEnvironment.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ public function registerContext(Context $context): void
4343
$this->contexts[get_class($context)] = $context;
4444
}
4545

46+
#[\Override]
4647
public function getSuite(): Suite
4748
{
4849
return $this->suite;
4950
}
5051

52+
#[\Override]
5153
public function bindCallee(Callee $callee): callable
5254
{
5355
$callable = $callee->getCallable();
@@ -59,16 +61,24 @@ public function bindCallee(Callee $callee): callable
5961
return $callable;
6062
}
6163

64+
#[\Override]
6265
public function hasContexts(): bool
6366
{
6467
return count($this->contexts) > 0;
6568
}
6669

70+
#[\Override]
71+
/**
72+
* @return key-of<TArray>[]
73+
*
74+
* @psalm-return list<key-of<class-string-map<T as Behat\Behat\Context\Context, T:class-string-map as Behat\Behat\Context\Context>>>
75+
*/
6776
public function getContextClasses(): array
6877
{
6978
return array_keys($this->contexts);
7079
}
7180

81+
#[\Override]
7282
public function hasContextClass($class): bool
7383
{
7484
return isset($this->contexts[$class]);

src/Context/Environment/UninitializedSymfonyExtensionEnvironment.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,19 @@ public function getServices(): array
4242
return array_keys($this->contexts);
4343
}
4444

45+
#[\Override]
4546
public function hasContexts(): bool
4647
{
4748
return count($this->contexts) > 0 || $this->delegatedEnvironment->hasContexts();
4849
}
4950

51+
#[\Override]
5052
public function getContextClasses(): array
5153
{
5254
return array_merge(array_values($this->contexts), $this->delegatedEnvironment->getContextClasses());
5355
}
5456

57+
#[\Override]
5558
public function hasContextClass($class): bool
5659
{
5760
return in_array($class, $this->contexts, true) || $this->delegatedEnvironment->hasContextClass($class);

src/Driver/Factory/SymfonyDriverFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,24 @@ public function __construct(string $name, Reference $kernel)
2525
$this->kernel = $kernel;
2626
}
2727

28+
#[\Override]
2829
public function getDriverName(): string
2930
{
3031
return $this->name;
3132
}
3233

34+
#[\Override]
3335
public function supportsJavascript(): bool
3436
{
3537
return false;
3638
}
3739

40+
#[\Override]
3841
public function configure(ArrayNodeDefinition $builder): void
3942
{
4043
}
4144

45+
#[\Override]
4246
public function buildDriver(array $config): Definition
4347
{
4448
if (!class_exists(BrowserKitDriver::class)) {

src/Driver/SymfonyDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function __construct(KernelInterface $kernel, ?string $baseUrl)
3434
parent::__construct($this->createBrowser(), $this->baseUrl);
3535
}
3636

37+
#[\Override]
3738
public function reset()
3839
{
3940
parent::reset();
@@ -61,7 +62,6 @@ public function reset()
6162

6263
private function createBrowser(): AbstractBrowser
6364
{
64-
/** @var object $testClient */
6565
$testClient = $this->kernel->getContainer()->get('test.client');
6666

6767
if (!$testClient instanceof AbstractBrowser) {

0 commit comments

Comments
 (0)