Skip to content

Commit 5812106

Browse files
authored
Update codebase to PHP 7.4 (#146)
1 parent 6bbc162 commit 5812106

12 files changed

+62
-31
lines changed

.github/workflows/main.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
php: [7.3, 7.4, 8.0]
11+
php: [7.4, 8.0, 8.1]
1212
symfony: [4.4, 5.3]
1313

1414
steps:
@@ -59,7 +59,10 @@ jobs:
5959
composer require symfony/css-selector=${{ matrix.symfony }} --ignore-platform-req=php --no-update
6060
composer require symfony/dom-crawler=${{ matrix.symfony }} --ignore-platform-req=php --no-update
6161
composer require symfony/browser-kit=${{ matrix.symfony }} --ignore-platform-req=php --no-update
62-
composer install --prefer-dist --no-progress --ignore-platform-req=php
62+
composer require vlucas/phpdotenv --ignore-platform-req=php --no-update
63+
composer require codeception/module-asserts --ignore-platform-req=php --no-update
64+
composer require codeception/module-doctrine2 --ignore-platform-req=php --no-update
65+
composer install --prefer-dist --no-progress --ignore-platform-req=php --no-dev
6366
6467
- name: Validate composer.json and composer.lock
6568
run: composer validate

composer.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,22 @@
1616
],
1717
"minimum-stability": "RC",
1818
"require": {
19-
"php": "^7.3 | ^8.0",
19+
"php": "^7.4 | ^8.0",
2020
"ext-json": "*",
2121
"codeception/lib-innerbrowser": "^1.4",
2222
"codeception/codeception": "^4.0"
2323
},
2424
"require-dev": {
2525
"codeception/module-asserts": "^1.3",
2626
"codeception/module-doctrine2": "^1.1",
27+
"doctrine/orm": "^2.10",
28+
"symfony/form": "^4.4 | ^5.0",
29+
"symfony/framework-bundle": "^4.4 | ^5.0",
30+
"symfony/http-kernel": "^4.4 | ^5.0",
31+
"symfony/mailer": "^4.4 | ^5.0",
32+
"symfony/routing": "^4.4 | ^5.0",
33+
"symfony/security-bundle": "^4.4 | ^5.0",
34+
"symfony/twig-bundle": "^4.4 | ^5.0",
2735
"vlucas/phpdotenv": "^4.2 | ^5.3"
2836
},
2937
"suggest": {

src/Codeception/Lib/Connector/Symfony.php

+9-17
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,13 @@
1717

1818
class Symfony extends HttpKernelBrowser
1919
{
20-
/**
21-
* @var bool
22-
*/
23-
private $rebootable;
20+
private bool $rebootable;
2421

25-
/**
26-
* @var bool
27-
*/
28-
private $hasPerformedRequest = false;
22+
private bool $hasPerformedRequest = false;
2923

30-
/**
31-
* @var ContainerInterface
32-
*/
33-
private $container;
24+
private ?ContainerInterface $container;
3425

35-
/**
36-
* @var array
37-
*/
38-
public $persistentServices = [];
26+
public array $persistentServices = [];
3927

4028
/**
4129
* Constructor.
@@ -67,6 +55,7 @@ protected function doRequest($request): Response
6755
$this->hasPerformedRequest = true;
6856
}
6957
}
58+
7059
return parent::doRequest($request);
7160
}
7261

@@ -113,6 +102,7 @@ private function getContainer(): ?ContainerInterface
113102
if ($container->has('test.service_container')) {
114103
$container = $container->get('test.service_container');
115104
}
105+
116106
return $container;
117107
}
118108

@@ -123,6 +113,7 @@ private function getProfiler(): ?Profiler
123113
$profiler = $this->container->get('profiler');
124114
return $profiler;
125115
}
116+
126117
return null;
127118
}
128119

@@ -131,10 +122,11 @@ private function getService(string $serviceName): ?object
131122
if ($this->container->has($serviceName)) {
132123
return $this->container->get($serviceName);
133124
}
125+
134126
return null;
135127
}
136128

137-
private function persistDoctrineConnections()
129+
private function persistDoctrineConnections(): void
138130
{
139131
if (!$this->container->hasParameter('doctrine.connections')) {
140132
return;

src/Codeception/Module/Symfony.php

+17-8
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,16 @@ class Symfony extends Framework implements DoctrineProvider, PartedModule
143143
use TimeAssertionsTrait;
144144
use TwigAssertionsTrait;
145145

146-
/**
147-
* @var Kernel
148-
*/
149-
public $kernel;
146+
public Kernel $kernel;
150147

151148
/**
152149
* @var SymfonyConnector
153150
*/
154151
public $client;
155152

153+
/**
154+
* @var array
155+
*/
156156
public $config = [
157157
'app_path' => 'app',
158158
'kernel_class' => 'App\Kernel',
@@ -172,10 +172,7 @@ public function _parts(): array
172172
return ['services'];
173173
}
174174

175-
/**
176-
* @var string|null
177-
*/
178-
protected $kernelClass;
175+
protected ?string $kernelClass = null;
179176

180177
/**
181178
* Services that should be persistent permanently for all tests
@@ -229,6 +226,7 @@ public function _after(TestInterface $test): void
229226
foreach (array_keys($this->permanentServices) as $serviceName) {
230227
$this->permanentServices[$serviceName] = $this->grabService($serviceName);
231228
}
229+
232230
parent::_after($test);
233231
}
234232

@@ -250,6 +248,7 @@ public function _getEntityManager()
250248
if ($this->kernel === null) {
251249
$this->fail('Symfony module is not loaded');
252250
}
251+
253252
$emService = $this->config['em_service'];
254253
if (!isset($this->permanentServices[$emService])) {
255254
// Try to persist configured entity manager
@@ -258,13 +257,16 @@ public function _getEntityManager()
258257
if ($container->has('doctrine')) {
259258
$this->persistPermanentService('doctrine');
260259
}
260+
261261
if ($container->has('doctrine.orm.default_entity_manager')) {
262262
$this->persistPermanentService('doctrine.orm.default_entity_manager');
263263
}
264+
264265
if ($container->has('doctrine.dbal.default_connection')) {
265266
$this->persistPermanentService('doctrine.dbal.default_connection');
266267
}
267268
}
269+
268270
return $this->permanentServices[$emService];
269271
}
270272

@@ -277,9 +279,11 @@ public function _getContainer(): ContainerInterface
277279
if (!$container instanceof ContainerInterface) {
278280
$this->fail('Could not get Symfony container');
279281
}
282+
280283
if ($container->has('test.service_container')) {
281284
$container = $container->get('test.service_container');
282285
}
286+
283287
return $container;
284288
}
285289

@@ -348,6 +352,7 @@ protected function getProfile(): ?Profile
348352
if (!$profiler = $this->getService('profiler')) {
349353
return null;
350354
}
355+
351356
try {
352357
$response = $this->getClient()->getResponse();
353358
return $profiler->loadProfileFromResponse($response);
@@ -356,6 +361,7 @@ protected function getProfile(): ?Profile
356361
} catch (Exception $e) {
357362
$this->fail($e->getMessage());
358363
}
364+
359365
return null;
360366
}
361367

@@ -379,6 +385,7 @@ protected function grabCollector(string $collector, string $function, ?string $m
379385
if ($message) {
380386
$this->fail($message);
381387
}
388+
382389
$this->fail(
383390
sprintf("The '%s' collector is needed to use the '%s' function.", $collector, $function)
384391
);
@@ -419,12 +426,14 @@ protected function debugResponse($url): void
419426
$this->debugSection('User', 'Anonymous');
420427
}
421428
}
429+
422430
if ($profile->hasCollector('mailer')) {
423431
/** @var MessageDataCollector $mailerCollector */
424432
$mailerCollector = $profile->getCollector('mailer');
425433
$emails = count($mailerCollector->getEvents()->getMessages());
426434
$this->debugSection('Emails', $emails . ' sent');
427435
}
436+
428437
if ($profile->hasCollector('time')) {
429438
/** @var TimeDataCollector $timeCollector */
430439
$timeCollector = $profile->getCollector('time');

src/Codeception/Module/Symfony/BrowserAssertionsTrait.php

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function seePageIsAvailable(string $url = null): void
5050
$this->amOnPage($url);
5151
$this->seeInCurrentUrl($url);
5252
}
53+
5354
$this->assertThat($this->getClient()->getResponse(), new ResponseIsSuccessful());
5455
}
5556

@@ -102,6 +103,7 @@ public function submitSymfonyForm(string $name, array $fields): void
102103
$fixedKey = sprintf('%s%s', $name, $key);
103104
$params[$fixedKey] = $value;
104105
}
106+
105107
$button = sprintf('%s_submit', $name);
106108

107109
$this->submitForm($selector, $params, $button);

src/Codeception/Module/Symfony/DoctrineAssertionsTrait.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Codeception\Module\Symfony;
66

7+
use Doctrine\ORM\EntityRepository;
78
use function class_exists;
89
use function get_class;
910
use function interface_exists;
@@ -39,6 +40,7 @@ public function grabNumRecords(string $entityClass, array $criteria = []): int
3940
->getQuery()
4041
->getSingleScalarResult();
4142
}
43+
4244
return $repository->count($criteria);
4345
}
4446

@@ -59,18 +61,20 @@ public function grabNumRecords(string $entityClass, array $criteria = []): int
5961
*/
6062
public function grabRepository($mixed)
6163
{
62-
$entityRepoClass = '\Doctrine\ORM\EntityRepository';
64+
$entityRepoClass = EntityRepository::class;
6365
$isNotARepo = function () use ($mixed): void {
6466
$this->fail(
6567
sprintf("'%s' is not an entity repository", $mixed)
6668
);
6769
};
68-
$getRepo = function () use ($mixed, $entityRepoClass, $isNotARepo) {
70+
$getRepo = function () use ($mixed, $entityRepoClass, $isNotARepo): ?EntityRepository {
6971
if (!$repo = $this->grabService($mixed)) return null;
72+
7073
if (!$repo instanceof $entityRepoClass) {
7174
$isNotARepo();
7275
return null;
7376
}
77+
7478
return $repo;
7579
};
7680

@@ -123,7 +127,7 @@ public function seeNumRecords(int $expectedNum, string $className, array $criter
123127
$currentNum,
124128
sprintf(
125129
'The number of found %s (%d) does not match expected number %d with %s',
126-
$className, $currentNum, $expectedNum, json_encode($criteria)
130+
$className, $currentNum, $expectedNum, json_encode($criteria, JSON_THROW_ON_ERROR)
127131
)
128132
);
129133
}

src/Codeception/Module/Symfony/FormAssertionsTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function seeFormErrorMessage(string $field, ?string $message = null): voi
6565
if (!array_key_exists('errors', $child)) {
6666
continue;
6767
}
68+
6869
foreach ($child['errors'] as $error) {
6970
$errors[$fieldName] = $error['message'];
7071
}

src/Codeception/Module/Symfony/MailerAssertionsTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function grabLastSentEmail(): ?Email
6363
if ($lastEmail = end($emails)) {
6464
return $lastEmail;
6565
}
66+
6667
return null;
6768
}
6869

src/Codeception/Module/Symfony/RouterAssertionsTrait.php

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function amOnRoute(string $routeName, array $params = []): void
6868
if ($router->getRouteCollection()->get($routeName) === null) {
6969
$this->fail(sprintf('Route with name "%s" does not exists.', $routeName));
7070
}
71+
7172
$url = $router->generate($routeName, $params);
7273
$this->amOnPage($url);
7374
}
@@ -107,6 +108,7 @@ public function seeCurrentActionIs(string $action): void
107108
return;
108109
}
109110
}
111+
110112
$this->fail("Action '{$action}' does not exist");
111113
}
112114

@@ -130,11 +132,13 @@ public function seeCurrentRouteIs(string $routeName, array $params = []): void
130132
}
131133

132134
$uri = explode('?', $this->grabFromCurrentUrl())[0];
135+
$match = [];
133136
try {
134137
$match = $router->match($uri);
135138
} catch (ResourceNotFoundException $e) {
136139
$this->fail(sprintf('The "%s" url does not match with any route', $uri));
137140
}
141+
138142
$expected = array_merge(['_route' => $routeName], $params);
139143
$intersection = array_intersect_assoc($expected, $match);
140144

@@ -160,6 +164,7 @@ public function seeInCurrentRoute(string $routeName): void
160164
}
161165

162166
$uri = explode('?', $this->grabFromCurrentUrl())[0];
167+
$matchedRouteName = '';
163168
try {
164169
$matchedRouteName = (string) $router->match($uri)['_route'];
165170
} catch (ResourceNotFoundException $e) {

src/Codeception/Module/Symfony/SecurityAssertionsTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public function seeUserPasswordDoesNotNeedRehash(UserInterface $user = null): vo
172172
$this->fail('No user found to validate');
173173
}
174174
}
175+
175176
$hasher = $this->grabPasswordHasherService();
176177

177178
$this->assertFalse($hasher->needsRehash($user), 'User password needs rehash');

src/Codeception/Module/Symfony/ServicesAssertionsTrait.php

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function grabService(string $serviceId): object
2929
$this->fail("Service `{$serviceId}` is required by Codeception, but not loaded by Symfony since you're not using it anywhere in your app.\n
3030
Recommended solution: Set it to `public` in your `config/services_test.php`/`.yaml`, see https://symfony.com/doc/current/service_container/alias_private.html#marking-services-as-public-private");
3131
}
32+
3233
return $service;
3334
}
3435

@@ -75,9 +76,11 @@ public function unpersistService(string $serviceName): void
7576
if (isset($this->persistentServices[$serviceName])) {
7677
unset($this->persistentServices[$serviceName]);
7778
}
79+
7880
if (isset($this->permanentServices[$serviceName])) {
7981
unset($this->permanentServices[$serviceName]);
8082
}
83+
8184
if ($this->client instanceof SymfonyConnector && isset($this->client->persistentServices[$serviceName])) {
8285
unset($this->client->persistentServices[$serviceName]);
8386
}
@@ -89,6 +92,7 @@ protected function getService(string $serviceId): ?object
8992
if ($container->has($serviceId)) {
9093
return $container->get($serviceId);
9194
}
95+
9296
return null;
9397
}
9498
}

src/Codeception/Module/Symfony/SessionAssertionsTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public function logoutProgrammatically(): void
137137
$cookieJar->expire($cookieName);
138138
}
139139
}
140+
140141
$cookieJar->flushExpiredCookies();
141142
}
142143

0 commit comments

Comments
 (0)