Skip to content

Commit 2a0751b

Browse files
committed
Refactor Doctrine connections persistence
1 parent 5b8dcff commit 2a0751b

File tree

4 files changed

+21
-31
lines changed

4 files changed

+21
-31
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ jobs:
88
matrix:
99
php: [8.2, 8.3, 8.4]
1010
symfony: ["5.4.*", "6.4.*", "6.4wApi", "7.3.*"]
11+
env:
12+
only_sf_latest: &only_sf_latest ${{ matrix.symfony == '7.3.*' }}
1113

1214
steps:
1315
- name: Checkout code
@@ -79,13 +81,17 @@ jobs:
7981
composer update --prefer-dist --no-progress
8082
8183
- name: Run PHPStan (max)
82-
if: ${{ matrix.symfony == '7.3.*' }}
84+
if: *only_sf_latest
8385
run: composer phpstan
8486

8587
- name: Run PHP-CS-Fixer
86-
if: ${{ matrix.symfony == '7.3.*' }}
88+
if: *only_sf_latest
8789
run: composer cs-check
8890

91+
- name: Run Composer Audit
92+
if: *only_sf_latest
93+
run: composer audit
94+
8995
- name: Validate Composer files
9096
run: composer validate --strict
9197
working-directory: framework-tests

src/Codeception/Lib/Connector/Symfony.php

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
use InvalidArgumentException;
88
use LogicException;
9-
use ReflectionMethod;
10-
use ReflectionProperty;
11-
use Symfony\Bundle\FrameworkBundle\Test\TestContainer;
129
use Symfony\Component\DependencyInjection\ContainerInterface;
10+
use Symfony\Component\DependencyInjection\Container;
1311
use Symfony\Component\HttpFoundation\Response;
1412
use Symfony\Component\HttpKernel\HttpKernelBrowser;
1513
use Symfony\Component\HttpKernel\HttpKernelInterface;
@@ -118,28 +116,12 @@ private function persistDoctrineConnections(): void
118116
return;
119117
}
120118

121-
if ($this->container instanceof TestContainer) {
122-
$method = new ReflectionMethod($this->container, 'getPublicContainer');
123-
$publicContainer = $method->invoke($this->container);
124-
} else {
125-
$publicContainer = $this->container;
126-
}
127-
128-
if (!is_object($publicContainer) || !method_exists($publicContainer, 'getParameterBag')) {
129-
return;
130-
}
131-
132-
$target = property_exists($publicContainer, 'parameters')
133-
? $publicContainer
134-
: $publicContainer->getParameterBag();
135-
136-
if (!is_object($target) || !property_exists($target, 'parameters')) {
137-
return;
119+
if ($this->container instanceof Container) {
120+
try {
121+
$this->container->getParameterBag()->remove('doctrine.connections');
122+
} catch (LogicException) {
123+
// Parameter bag is frozen and cannot be modified.
124+
}
138125
}
139-
$prop = new ReflectionProperty($target, 'parameters');
140-
141-
$params = (array) $prop->getValue($target);
142-
unset($params['doctrine.connections']);
143-
$prop->setValue($target, $params);
144126
}
145127
}

src/Codeception/Module/Symfony.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
use function file_exists;
6666
use function implode;
6767
use function in_array;
68+
use function extension_loaded;
6869
use function ini_get;
6970
use function ini_set;
7071
use function is_object;
@@ -495,6 +496,10 @@ protected function getInternalDomains(): array
495496
*/
496497
private function setXdebugMaxNestingLevel(int $max): void
497498
{
499+
if (!extension_loaded('xdebug')) {
500+
return;
501+
}
502+
498503
if ((int) ini_get('xdebug.max_nesting_level') < $max) {
499504
ini_set('xdebug.max_nesting_level', (string) $max);
500505
}

src/Codeception/Module/Symfony/BrowserAssertionsTrait.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,7 @@ public function seePageRedirectsTo(string $page, string $redirectsTo): void
330330
$client->followRedirects(false);
331331
$this->amOnPage($page);
332332

333-
$this->assertTrue(
334-
$client->getResponse()->isRedirection(),
335-
'The response is not a redirection.'
336-
);
333+
$this->assertThatForResponse(new ResponseIsRedirected(), 'The response is not a redirection.');
337334

338335
$client->followRedirect();
339336
$this->seeInCurrentUrl($redirectsTo);

0 commit comments

Comments
 (0)