Skip to content

Commit c8bea5d

Browse files
authored
Improved support for PHP 8.0 (#160)
1 parent e2a0f4d commit c8bea5d

11 files changed

+24
-51
lines changed

src/Codeception/Lib/Connector/Symfony.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Symfony extends HttpKernelBrowser
3838
public function __construct(Kernel $kernel, array $services = [], bool $rebootable = true)
3939
{
4040
parent::__construct($kernel);
41-
$this->followRedirects(true);
41+
$this->followRedirects();
4242
$this->rebootable = $rebootable;
4343
$this->persistentServices = $services;
4444
$this->container = $this->getContainer();

src/Codeception/Module/Symfony.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ public function _initialize(): void
212212

213213
/**
214214
* Initialize new client instance before each test
215-
*
216-
* @param TestInterface $test
217215
*/
218216
public function _before(TestInterface $test): void
219217
{
@@ -223,8 +221,6 @@ public function _before(TestInterface $test): void
223221

224222
/**
225223
* Update permanent services after each test
226-
*
227-
* @param TestInterface $test
228224
*/
229225
public function _after(TestInterface $test): void
230226
{
@@ -370,13 +366,8 @@ protected function getProfile(): ?Profile
370366

371367
/**
372368
* Grabs a Symfony Data Collector
373-
*
374-
* @param string $collector
375-
* @param string $function
376-
* @param string|null $message
377-
* @return DataCollectorInterface
378369
*/
379-
protected function grabCollector(string $collector, string $function, ?string $message = null): DataCollectorInterface
370+
protected function grabCollector(string $collector, string $function, string $message = null): DataCollectorInterface
380371
{
381372
if (($profile = $this->getProfile()) === null) {
382373
$this->fail(

src/Codeception/Module/Symfony/DoctrineAssertionsTrait.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ trait DoctrineAssertionsTrait
2727
*
2828
* @param string $entityClass The entity class
2929
* @param array $criteria Optional query criteria
30-
* @return int
3130
*/
3231
public function grabNumRecords(string $entityClass, array $criteria = []): int
3332
{
@@ -55,11 +54,8 @@ public function grabNumRecords(string $entityClass, array $criteria = []): int
5554
* $I->grabRepository(UserRepository::class);
5655
* $I->grabRepository(UserRepositoryInterface::class);
5756
* ```
58-
*
59-
* @param object|string $mixed
60-
* @return \Doctrine\ORM\EntityRepository|null
6157
*/
62-
public function grabRepository($mixed): ?EntityRepository
58+
public function grabRepository(object|string $mixed): ?EntityRepository
6359
{
6460
$entityRepoClass = EntityRepository::class;
6561
$isNotARepo = function () use ($mixed): void {
@@ -79,7 +75,7 @@ public function grabRepository($mixed): ?EntityRepository
7975
};
8076

8177
if (is_object($mixed)) {
82-
$mixed = get_class($mixed);
78+
$mixed = $mixed::class;
8379
}
8480

8581
if (interface_exists($mixed)) {

src/Codeception/Module/Symfony/EventsAssertionsTrait.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ trait EventsAssertionsTrait
2828
* $I->dontSeeOrphanEvent(['App\MyEvent', 'App\MyOtherEvent']);
2929
* ```
3030
*
31-
* @param string|object|string[] $expected
31+
* @param object|string|string[] $expected
3232
*/
33-
public function dontSeeOrphanEvent($expected = null): void
33+
public function dontSeeOrphanEvent(array|object|string $expected = null): void
3434
{
3535
$eventCollector = $this->grabEventCollector(__FUNCTION__);
3636

@@ -55,9 +55,9 @@ public function dontSeeOrphanEvent($expected = null): void
5555
* $I->dontSeeEventTriggered(['App\MyEvent', 'App\MyOtherEvent']);
5656
* ```
5757
*
58-
* @param string|object|string[] $expected
58+
* @param object|string|string[] $expected
5959
*/
60-
public function dontSeeEventTriggered($expected): void
60+
public function dontSeeEventTriggered(array|object|string $expected): void
6161
{
6262
$eventCollector = $this->grabEventCollector(__FUNCTION__);
6363

@@ -82,9 +82,9 @@ public function dontSeeEventTriggered($expected): void
8282
* $I->seeOrphanEvent(['App\MyEvent', 'App\MyOtherEvent']);
8383
* ```
8484
*
85-
* @param string|object|string[] $expected
85+
* @param object|string|string[] $expected
8686
*/
87-
public function seeOrphanEvent($expected): void
87+
public function seeOrphanEvent(array|object|string $expected): void
8888
{
8989
$eventCollector = $this->grabEventCollector(__FUNCTION__);
9090

@@ -105,9 +105,9 @@ public function seeOrphanEvent($expected): void
105105
* $I->seeEventTriggered(['App\MyEvent', 'App\MyOtherEvent']);
106106
* ```
107107
*
108-
* @param string|object|string[] $expected
108+
* @param object|string|string[] $expected
109109
*/
110-
public function seeEventTriggered($expected): void
110+
public function seeEventTriggered(array|object|string $expected): void
111111
{
112112
$eventCollector = $this->grabEventCollector(__FUNCTION__);
113113

@@ -123,7 +123,7 @@ protected function assertEventNotTriggered(Data $data, array $expected): void
123123
$actual = $data->getValue(true);
124124

125125
foreach ($expected as $expectedEvent) {
126-
$expectedEvent = is_object($expectedEvent) ? get_class($expectedEvent) : $expectedEvent;
126+
$expectedEvent = is_object($expectedEvent) ? $expectedEvent::class : $expectedEvent;
127127
$this->assertFalse(
128128
$this->eventWasTriggered($actual, (string)$expectedEvent),
129129
"The '{$expectedEvent}' event triggered"
@@ -140,7 +140,7 @@ protected function assertEventTriggered(Data $data, array $expected): void
140140
$actual = $data->getValue(true);
141141

142142
foreach ($expected as $expectedEvent) {
143-
$expectedEvent = is_object($expectedEvent) ? get_class($expectedEvent) : $expectedEvent;
143+
$expectedEvent = is_object($expectedEvent) ? $expectedEvent::class : $expectedEvent;
144144
$this->assertTrue(
145145
$this->eventWasTriggered($actual, (string)$expectedEvent),
146146
"The '{$expectedEvent}' event did not trigger"
@@ -154,7 +154,7 @@ protected function eventWasTriggered(array $actual, string $expectedEvent): bool
154154

155155
foreach ($actual as $actualEvent) {
156156
if (is_array($actualEvent)) { // Called Listeners
157-
if (strpos($actualEvent['pretty'], $expectedEvent) === 0) {
157+
if (str_starts_with($actualEvent['pretty'], $expectedEvent)) {
158158
$triggered = true;
159159
}
160160
} else { // Orphan Events

src/Codeception/Module/Symfony/FormAssertionsTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function dontSeeFormErrors(): void
4646
* @param string $field
4747
* @param string|null $message
4848
*/
49-
public function seeFormErrorMessage(string $field, ?string $message = null): void
49+
public function seeFormErrorMessage(string $field, string $message = null): void
5050
{
5151
$formCollector = $this->grabFormCollector(__FUNCTION__);
5252

src/Codeception/Module/Symfony/MailerAssertionsTrait.php

-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ public function seeEmailIsSent(int $expectedCount = 1): void
5353
* $address = $email->getTo()[0];
5454
* $I->assertSame('[email protected]', $address->getAddress());
5555
* ```
56-
*
57-
* @return \Symfony\Component\Mime\Email|null
5856
*/
5957
public function grabLastSentEmail(): ?Email
6058
{

src/Codeception/Module/Symfony/RouterAssertionsTrait.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function amOnAction(string $action, array $params = []): void
3737

3838
foreach ($routes as $route) {
3939
$controller = $route->getDefault('_controller');
40-
if (substr_compare($controller, $action, -strlen($action)) === 0) {
40+
if (str_ends_with($controller, $action)) {
4141
$resource = $router->match($route->getPath());
4242
$url = $router->generate(
4343
$resource['_route'],
@@ -100,7 +100,7 @@ public function seeCurrentActionIs(string $action): void
100100

101101
foreach ($routes as $route) {
102102
$controller = $route->getDefault('_controller');
103-
if (substr_compare($controller, $action, -strlen($action)) === 0) {
103+
if (str_ends_with($controller, $action)) {
104104
$request = $this->getClient()->getRequest();
105105
$currentActionFqcn = $request->attributes->get('_controller');
106106

@@ -135,7 +135,7 @@ public function seeCurrentRouteIs(string $routeName, array $params = []): void
135135
$match = [];
136136
try {
137137
$match = $router->match($uri);
138-
} catch (ResourceNotFoundException $e) {
138+
} catch (ResourceNotFoundException) {
139139
$this->fail(sprintf('The "%s" url does not match with any route', $uri));
140140
}
141141

@@ -167,7 +167,7 @@ public function seeInCurrentRoute(string $routeName): void
167167
$matchedRouteName = '';
168168
try {
169169
$matchedRouteName = (string)$router->match($uri)['_route'];
170-
} catch (ResourceNotFoundException $e) {
170+
} catch (ResourceNotFoundException) {
171171
$this->fail(sprintf('The "%s" url does not match with any route', $uri));
172172
}
173173

src/Codeception/Module/Symfony/SecurityAssertionsTrait.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,7 @@ protected function grabSecurityService(): Security
183183
return $this->grabService('security.helper');
184184
}
185185

186-
/**
187-
* @return UserPasswordHasherInterface|UserPasswordEncoderInterface
188-
*/
189-
protected function grabPasswordHasherService()
186+
protected function grabPasswordHasherService(): UserPasswordHasherInterface|UserPasswordEncoderInterface
190187
{
191188
$hasher = $this->getService('security.password_hasher') ?: $this->getService('security.password_encoder');
192189

src/Codeception/Module/Symfony/ServicesAssertionsTrait.php

-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ trait ServicesAssertionsTrait
2121
*
2222
* @part services
2323
* @param string $serviceId
24-
* @return object
2524
*/
2625
public function grabService(string $serviceId): object
2726
{
@@ -37,7 +36,6 @@ public function grabService(string $serviceId): object
3736
* Get service $serviceName and add it to the lists of persistent services.
3837
*
3938
* @part services
40-
* @param string $serviceName
4139
*/
4240
public function persistService(string $serviceName): void
4341
{
@@ -53,7 +51,6 @@ public function persistService(string $serviceName): void
5351
* making that service persistent between tests.
5452
*
5553
* @part services
56-
* @param string $serviceName
5754
*/
5855
public function persistPermanentService(string $serviceName): void
5956
{
@@ -69,7 +66,6 @@ public function persistPermanentService(string $serviceName): void
6966
* Remove service $serviceName from the lists of persistent services.
7067
*
7168
* @part services
72-
* @param string $serviceName
7369
*/
7470
public function unpersistService(string $serviceName): void
7571
{

src/Codeception/Module/Symfony/SessionAssertionsTrait.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ public function amLoggedInAs(UserInterface $user, string $firewallName = 'main',
7575
* $I->dontSeeInSession('attribute', 'value');
7676
* ```
7777
*
78-
* @param string $attribute
79-
* @param mixed|null $value
8078
*/
81-
public function dontSeeInSession(string $attribute, $value = null): void
79+
public function dontSeeInSession(string $attribute, mixed $value = null): void
8280
{
8381
$session = $this->getCurrentSession();
8482

@@ -160,11 +158,8 @@ public function logoutProgrammatically(): void
160158
* $I->seeInSession('attribute');
161159
* $I->seeInSession('attribute', 'value');
162160
* ```
163-
*
164-
* @param string $attribute
165-
* @param mixed|null $value
166161
*/
167-
public function seeInSession(string $attribute, $value = null): void
162+
public function seeInSession(string $attribute, mixed $value = null): void
168163
{
169164
$session = $this->getCurrentSession();
170165

src/Codeception/Module/Symfony/TimeAssertionsTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ trait TimeAssertionsTrait
2424
*
2525
* @param int|float $expectedMilliseconds The expected time in milliseconds
2626
*/
27-
public function seeRequestTimeIsLessThan($expectedMilliseconds): void
27+
public function seeRequestTimeIsLessThan(int|float $expectedMilliseconds): void
2828
{
2929
$expectedMilliseconds = round($expectedMilliseconds, 2);
3030

0 commit comments

Comments
 (0)