Skip to content

Commit 71f92ce

Browse files
authored
Update codebase to PHP 7.4 (#36)
1 parent 91e812b commit 71f92ce

File tree

9 files changed

+48
-90
lines changed

9 files changed

+48
-90
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 4 deletions
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]
1212
laravel: [6, 8]
1313

1414
steps:
@@ -74,6 +74,4 @@ jobs:
7474
working-directory: framework-tests
7575

7676
- name: Run test suite
77-
run: |
78-
php vendor/bin/codecept build -c framework-tests
79-
php vendor/bin/codecept run Functional -c framework-tests
77+
run: php vendor/bin/codecept run Functional -c framework-tests

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
],
2020
"minimum-stability": "RC",
2121
"require": {
22-
"php": "^7.3 | ^8.0",
22+
"php": "^7.4 | ^8.0",
2323
"ext-json": "*",
2424
"codeception/lib-innerbrowser": "^1.3",
2525
"codeception/codeception": "^4.0"
2626
},
2727
"require-dev": {
2828
"codeception/module-asserts": "^1.3",
2929
"codeception/module-rest": "^1.2",
30+
"laravel/framework": "^6.0 | ^7.0 | ^8.0",
3031
"vlucas/phpdotenv": "^3.6 | ^4.1 | ^5.2"
3132
},
3233
"autoload": {

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A Codeception module for Laravel framework.
1010
## Requirements
1111

1212
* `Laravel 6` or higher.
13-
* `PHP 7.3` or higher.
13+
* `PHP 7.4` or higher.
1414

1515
## Installation
1616

src/Codeception/Lib/Connector/Laravel.php

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Closure;
88
use Codeception\Lib\Connector\Laravel\ExceptionHandlerDecorator as LaravelExceptionHandlerDecorator;
99
use Codeception\Lib\Connector\Laravel6\ExceptionHandlerDecorator as Laravel6ExceptionHandlerDecorator;
10+
use Codeception\Module\Laravel as LaravelModule;
1011
use Codeception\Stub;
1112
use Exception;
1213
use Illuminate\Contracts\Config\Repository as Config;
@@ -27,75 +28,42 @@
2728

2829
class Laravel extends Client
2930
{
30-
/**
31-
* @var array
32-
*/
33-
private $bindings = [];
31+
private array $bindings = [];
3432

35-
/**
36-
* @var array
37-
*/
38-
private $contextualBindings = [];
33+
private array $contextualBindings = [];
3934

4035
/**
4136
* @var object[]
4237
*/
43-
private $instances = [];
38+
private array $instances = [];
4439

4540
/**
4641
* @var callable[]
4742
*/
48-
private $applicationHandlers = [];
43+
private array $applicationHandlers = [];
4944

50-
/**
51-
* @var Application
52-
*/
53-
private $app;
45+
private ?AppContract $app = null;
5446

55-
/**
56-
* @var \Codeception\Module\Laravel
57-
*/
58-
private $module;
47+
private LaravelModule $module;
5948

60-
/**
61-
* @var bool
62-
*/
63-
private $firstRequest = true;
49+
private bool $firstRequest = true;
6450

65-
/**
66-
* @var array
67-
*/
68-
private $triggeredEvents = [];
51+
private array $triggeredEvents = [];
6952

70-
/**
71-
* @var bool
72-
*/
73-
private $exceptionHandlingDisabled;
53+
private bool $exceptionHandlingDisabled;
7454

75-
/**
76-
* @var bool
77-
*/
78-
private $middlewareDisabled;
55+
private bool $middlewareDisabled;
7956

80-
/**
81-
* @var bool
82-
*/
83-
private $eventsDisabled;
57+
private bool $eventsDisabled;
8458

85-
/**
86-
* @var bool
87-
*/
88-
private $modelEventsDisabled;
59+
private bool $modelEventsDisabled;
8960

90-
/**
91-
* @var object
92-
*/
93-
private $oldDb;
61+
private ?object $oldDb = null;
9462

9563
/**
9664
* Constructor.
9765
*
98-
* @param \Codeception\Module\Laravel $module
66+
* @param LaravelModule $module
9967
* @throws Exception
10068
*/
10169
public function __construct($module)
@@ -113,6 +81,7 @@ public function __construct($module)
11381
if (array_key_exists('url', $this->module->config)) {
11482
$components = parse_url($this->module->config['url']);
11583
}
84+
11685
$host = $components['host'] ?? 'localhost';
11786

11887
parent::__construct($this->app, ['HTTP_HOST' => $host]);
@@ -132,6 +101,7 @@ protected function doRequest($request): Response
132101
if (!$this->firstRequest) {
133102
$this->initialize($request);
134103
}
104+
135105
$this->firstRequest = false;
136106

137107
$this->applyBindings();
@@ -157,27 +127,27 @@ private function initialize(SymfonyRequest $request = null): void
157127
$this->oldDb = $db;
158128
}
159129

160-
$this->app = $this->kernel = $this->loadApplication();
130+
$this->app = $this->loadApplication();
131+
$this->kernel = $this->app;
161132

162133
// Set the request instance for the application,
163134
if (is_null($request)) {
164135
$appConfig = require $this->module->config['project_dir'] . 'config/app.php';
165136
$request = SymfonyRequest::create($appConfig['url']);
166137
}
138+
167139
$this->app->instance('request', Request::createFromBase($request));
168140

169141
// Reset the old database after all the service providers are registered.
170142
if ($this->oldDb) {
171-
$this->getEvents()->listen('bootstrapped: ' . RegisterProviders::class, function () {
172-
$this->app->singleton('db', function () {
173-
return $this->oldDb;
174-
});
143+
$this->getEvents()->listen('bootstrapped: ' . RegisterProviders::class, function (): void {
144+
$this->app->singleton('db', fn(): object => $this->oldDb);
175145
});
176146
}
177147

178148
$this->getHttpKernel()->bootstrap();
179149

180-
$listener = function ($event) {
150+
$listener = function ($event): void {
181151
$this->triggeredEvents[] = $this->normalizeEvent($event);
182152
};
183153

@@ -230,7 +200,7 @@ private function mockEventDispatcher(): void
230200
// Even if events are disabled we still want to record the triggered events.
231201
// But by mocking the event dispatcher the wildcard listener registered in the initialize method is removed.
232202
// So to record the triggered events we have to catch the calls to the fire method of the event dispatcher mock.
233-
$callback = function ($event) {
203+
$callback = function ($event): array {
234204
$this->triggeredEvents[] = $this->normalizeEvent($event);
235205

236206
return [];
@@ -253,7 +223,7 @@ private function normalizeEvent($event): string
253223
$event = get_class($event);
254224
}
255225

256-
if (preg_match('/^bootstrapp(ing|ed): /', $event)) {
226+
if (preg_match('#^bootstrapp(ing|ed): #', $event)) {
257227
return $event;
258228
}
259229

src/Codeception/Lib/Connector/Laravel/ExceptionHandlerDecorator.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,13 @@
1313

1414
class ExceptionHandlerDecorator implements ExceptionHandlerContract
1515
{
16-
/**
17-
* @var ExceptionHandlerContract
18-
*/
19-
private $laravelExceptionHandler;
16+
private ExceptionHandlerContract $laravelExceptionHandler;
2017

21-
/**
22-
* @var bool
23-
*/
24-
private $exceptionHandlingDisabled = true;
18+
private bool $exceptionHandlingDisabled = true;
2519

26-
public function __construct(object $laravelExceptionHandler)
20+
public function __construct(ExceptionHandlerContract $exceptionHandler)
2721
{
28-
$this->laravelExceptionHandler = $laravelExceptionHandler;
22+
$this->laravelExceptionHandler = $exceptionHandler;
2923
}
3024

3125
public function exceptionHandlingDisabled(bool $exceptionHandlingDisabled): void

src/Codeception/Lib/Connector/Laravel6/ExceptionHandlerDecorator.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,13 @@
1313

1414
class ExceptionHandlerDecorator implements ExceptionHandlerContract
1515
{
16-
/**
17-
* @var ExceptionHandlerContract
18-
*/
19-
private $laravelExceptionHandler;
16+
private ExceptionHandlerContract $laravelExceptionHandler;
2017

21-
/**
22-
* @var bool
23-
*/
24-
private $exceptionHandlingDisabled = true;
18+
private bool $exceptionHandlingDisabled = true;
2519

26-
public function __construct(object $laravelExceptionHandler)
20+
public function __construct(ExceptionHandlerContract $exceptionHandler)
2721
{
28-
$this->laravelExceptionHandler = $laravelExceptionHandler;
22+
$this->laravelExceptionHandler = $exceptionHandler;
2923
}
3024

3125
public function exceptionHandlingDisabled(bool $exceptionHandlingDisabled): void

src/Codeception/Module/Laravel/InteractsWithAuthentication.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait InteractsWithAuthentication
2020
*/
2121
public function amActingAs(Authenticatable $user, string $guardName = null): void
2222
{
23-
if (isset($user->wasRecentlyCreated) && $user->wasRecentlyCreated) {
23+
if (property_exists($user, 'wasRecentlyCreated') && $user->wasRecentlyCreated) {
2424
$user->wasRecentlyCreated = false;
2525
}
2626

@@ -57,7 +57,7 @@ public function amLoggedAs($user, string $guardName = null): void
5757
$guard = $this->getAuth()->guard($guardName);
5858
$this->assertTrue(
5959
$guard->attempt($user)
60-
, 'Failed to login with credentials ' . json_encode($user)
60+
, 'Failed to login with credentials ' . json_encode($user, JSON_THROW_ON_ERROR)
6161
);
6262
}
6363

src/Codeception/Module/Laravel/InteractsWithEloquent.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function dontSeeRecord($table, $attributes = []): void
4343

4444
if (class_exists($table)) {
4545
if ($foundMatchingRecord = (bool)$this->findModel($table, $attributes)) {
46-
$this->fail("Unexpectedly found matching {$table} with " . json_encode($attributes));
46+
$this->fail("Unexpectedly found matching {$table} with " . json_encode($attributes, JSON_THROW_ON_ERROR));
4747
}
4848
} elseif ($foundMatchingRecord = (bool)$this->findRecord($table, $attributes)) {
4949
$this->fail("Unexpectedly found matching record in table '{$table}'");
@@ -89,7 +89,7 @@ public function grabRecord($table, $attributes = [])
8989
{
9090
if (class_exists($table)) {
9191
if (!$model = $this->findModel($table, $attributes)) {
92-
$this->fail("Could not find {$table} with " . json_encode($attributes));
92+
$this->fail("Could not find {$table} with " . json_encode($attributes, JSON_THROW_ON_ERROR));
9393
}
9494

9595
return $model;
@@ -192,7 +192,7 @@ public function haveRecord($table, $attributes = [])
192192
$table = $this->getDb()->table($table);
193193
return $table->insertGetId($attributes);
194194
} catch (Throwable $t) {
195-
$this->fail("Could not insert record into table '$table':\n\n" . $t->getMessage());
195+
$this->fail("Could not insert record into table '{$table}':\n\n" . $t->getMessage());
196196
}
197197
}
198198

@@ -275,14 +275,14 @@ public function seeNumRecords(int $expectedNum, string $table, array $attributes
275275
$this->assertSame(
276276
$expectedNum,
277277
$currentNum,
278-
"The number of found {$table} ({$currentNum}) does not match expected number {$expectedNum} with " . json_encode($attributes)
278+
"The number of found {$table} ({$currentNum}) does not match expected number {$expectedNum} with " . json_encode($attributes, JSON_THROW_ON_ERROR)
279279
);
280280
} else {
281281
$currentNum = $this->countRecords($table, $attributes);
282282
$this->assertSame(
283283
$expectedNum,
284284
$currentNum,
285-
"The number of found records in table {$table} ({$currentNum}) does not match expected number $expectedNum with " . json_encode($attributes)
285+
"The number of found records in table {$table} ({$currentNum}) does not match expected number $expectedNum with " . json_encode($attributes, JSON_THROW_ON_ERROR)
286286
);
287287
}
288288
}
@@ -310,7 +310,7 @@ public function seeRecord($table, $attributes = []): void
310310

311311
if (class_exists($table)) {
312312
if (!$foundMatchingRecord = (bool)$this->findModel($table, $attributes)) {
313-
$this->fail("Could not find {$table} with " . json_encode($attributes));
313+
$this->fail("Could not find {$table} with " . json_encode($attributes, JSON_THROW_ON_ERROR));
314314
}
315315
} elseif (!$foundMatchingRecord = (bool)$this->findRecord($table, $attributes)) {
316316
$this->fail("Could not find matching record in table '{$table}'");
@@ -373,6 +373,7 @@ private function buildQuery(string $table, array $attributes = [])
373373
$query->where($key, $value);
374374
}
375375
}
376+
376377
return $query;
377378
}
378379

src/Codeception/Module/Laravel/InteractsWithRouting.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function seeCurrentActionIs(string $action): void
8383
'\\'
8484
);
8585

86-
if ($currentAction != $action) {
86+
if ($currentAction !== $action) {
8787
$this->fail("Current action is '{$currentAction}'");
8888
}
8989
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy