Skip to content

Improved support for PHP 8.0 #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Codeception/Lib/Connector/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Symfony extends HttpKernelBrowser
public function __construct(Kernel $kernel, array $services = [], bool $rebootable = true)
{
parent::__construct($kernel);
$this->followRedirects(true);
$this->followRedirects();
$this->rebootable = $rebootable;
$this->persistentServices = $services;
$this->container = $this->getContainer();
Expand Down
11 changes: 1 addition & 10 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ public function _initialize(): void

/**
* Initialize new client instance before each test
*
* @param TestInterface $test
*/
public function _before(TestInterface $test): void
{
Expand All @@ -223,8 +221,6 @@ public function _before(TestInterface $test): void

/**
* Update permanent services after each test
*
* @param TestInterface $test
*/
public function _after(TestInterface $test): void
{
Expand Down Expand Up @@ -370,13 +366,8 @@ protected function getProfile(): ?Profile

/**
* Grabs a Symfony Data Collector
*
* @param string $collector
* @param string $function
* @param string|null $message
* @return DataCollectorInterface
*/
protected function grabCollector(string $collector, string $function, ?string $message = null): DataCollectorInterface
protected function grabCollector(string $collector, string $function, string $message = null): DataCollectorInterface
{
if (($profile = $this->getProfile()) === null) {
$this->fail(
Expand Down
8 changes: 2 additions & 6 deletions src/Codeception/Module/Symfony/DoctrineAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ trait DoctrineAssertionsTrait
*
* @param string $entityClass The entity class
* @param array $criteria Optional query criteria
* @return int
*/
public function grabNumRecords(string $entityClass, array $criteria = []): int
{
Expand Down Expand Up @@ -55,11 +54,8 @@ public function grabNumRecords(string $entityClass, array $criteria = []): int
* $I->grabRepository(UserRepository::class);
* $I->grabRepository(UserRepositoryInterface::class);
* ```
*
* @param object|string $mixed
* @return \Doctrine\ORM\EntityRepository|null
*/
public function grabRepository($mixed): ?EntityRepository
public function grabRepository(object|string $mixed): ?EntityRepository
{
$entityRepoClass = EntityRepository::class;
$isNotARepo = function () use ($mixed): void {
Expand All @@ -79,7 +75,7 @@ public function grabRepository($mixed): ?EntityRepository
};

if (is_object($mixed)) {
$mixed = get_class($mixed);
$mixed = $mixed::class;
}

if (interface_exists($mixed)) {
Expand Down
22 changes: 11 additions & 11 deletions src/Codeception/Module/Symfony/EventsAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ trait EventsAssertionsTrait
* $I->dontSeeOrphanEvent(['App\MyEvent', 'App\MyOtherEvent']);
* ```
*
* @param string|object|string[] $expected
* @param object|string|string[] $expected
*/
public function dontSeeOrphanEvent($expected = null): void
public function dontSeeOrphanEvent(array|object|string $expected = null): void
{
$eventCollector = $this->grabEventCollector(__FUNCTION__);

Expand All @@ -55,9 +55,9 @@ public function dontSeeOrphanEvent($expected = null): void
* $I->dontSeeEventTriggered(['App\MyEvent', 'App\MyOtherEvent']);
* ```
*
* @param string|object|string[] $expected
* @param object|string|string[] $expected
*/
public function dontSeeEventTriggered($expected): void
public function dontSeeEventTriggered(array|object|string $expected): void
{
$eventCollector = $this->grabEventCollector(__FUNCTION__);

Expand All @@ -82,9 +82,9 @@ public function dontSeeEventTriggered($expected): void
* $I->seeOrphanEvent(['App\MyEvent', 'App\MyOtherEvent']);
* ```
*
* @param string|object|string[] $expected
* @param object|string|string[] $expected
*/
public function seeOrphanEvent($expected): void
public function seeOrphanEvent(array|object|string $expected): void
{
$eventCollector = $this->grabEventCollector(__FUNCTION__);

Expand All @@ -105,9 +105,9 @@ public function seeOrphanEvent($expected): void
* $I->seeEventTriggered(['App\MyEvent', 'App\MyOtherEvent']);
* ```
*
* @param string|object|string[] $expected
* @param object|string|string[] $expected
*/
public function seeEventTriggered($expected): void
public function seeEventTriggered(array|object|string $expected): void
{
$eventCollector = $this->grabEventCollector(__FUNCTION__);

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

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

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

foreach ($actual as $actualEvent) {
if (is_array($actualEvent)) { // Called Listeners
if (strpos($actualEvent['pretty'], $expectedEvent) === 0) {
if (str_starts_with($actualEvent['pretty'], $expectedEvent)) {
$triggered = true;
}
} else { // Orphan Events
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Module/Symfony/FormAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function dontSeeFormErrors(): void
* @param string $field
* @param string|null $message
*/
public function seeFormErrorMessage(string $field, ?string $message = null): void
public function seeFormErrorMessage(string $field, string $message = null): void
{
$formCollector = $this->grabFormCollector(__FUNCTION__);

Expand Down
2 changes: 0 additions & 2 deletions src/Codeception/Module/Symfony/MailerAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public function seeEmailIsSent(int $expectedCount = 1): void
* $address = $email->getTo()[0];
* $I->assertSame('john_doe@example.com', $address->getAddress());
* ```
*
* @return \Symfony\Component\Mime\Email|null
*/
public function grabLastSentEmail(): ?Email
{
Expand Down
8 changes: 4 additions & 4 deletions src/Codeception/Module/Symfony/RouterAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function amOnAction(string $action, array $params = []): void

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

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

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

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

Expand Down
5 changes: 1 addition & 4 deletions src/Codeception/Module/Symfony/SecurityAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ protected function grabSecurityService(): Security
return $this->grabService('security.helper');
}

/**
* @return UserPasswordHasherInterface|UserPasswordEncoderInterface
*/
protected function grabPasswordHasherService()
protected function grabPasswordHasherService(): UserPasswordHasherInterface|UserPasswordEncoderInterface
{
$hasher = $this->getService('security.password_hasher') ?: $this->getService('security.password_encoder');

Expand Down
4 changes: 0 additions & 4 deletions src/Codeception/Module/Symfony/ServicesAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ trait ServicesAssertionsTrait
*
* @part services
* @param string $serviceId
* @return object
*/
public function grabService(string $serviceId): object
{
Expand All @@ -37,7 +36,6 @@ public function grabService(string $serviceId): object
* Get service $serviceName and add it to the lists of persistent services.
*
* @part services
* @param string $serviceName
*/
public function persistService(string $serviceName): void
{
Expand All @@ -53,7 +51,6 @@ public function persistService(string $serviceName): void
* making that service persistent between tests.
*
* @part services
* @param string $serviceName
*/
public function persistPermanentService(string $serviceName): void
{
Expand All @@ -69,7 +66,6 @@ public function persistPermanentService(string $serviceName): void
* Remove service $serviceName from the lists of persistent services.
*
* @part services
* @param string $serviceName
*/
public function unpersistService(string $serviceName): void
{
Expand Down
9 changes: 2 additions & 7 deletions src/Codeception/Module/Symfony/SessionAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ public function amLoggedInAs(UserInterface $user, string $firewallName = 'main',
* $I->dontSeeInSession('attribute', 'value');
* ```
*
* @param string $attribute
* @param mixed|null $value
*/
public function dontSeeInSession(string $attribute, $value = null): void
public function dontSeeInSession(string $attribute, mixed $value = null): void
{
$session = $this->getCurrentSession();

Expand Down Expand Up @@ -160,11 +158,8 @@ public function logoutProgrammatically(): void
* $I->seeInSession('attribute');
* $I->seeInSession('attribute', 'value');
* ```
*
* @param string $attribute
* @param mixed|null $value
*/
public function seeInSession(string $attribute, $value = null): void
public function seeInSession(string $attribute, mixed $value = null): void
{
$session = $this->getCurrentSession();

Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Module/Symfony/TimeAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trait TimeAssertionsTrait
*
* @param int|float $expectedMilliseconds The expected time in milliseconds
*/
public function seeRequestTimeIsLessThan($expectedMilliseconds): void
public function seeRequestTimeIsLessThan(int|float $expectedMilliseconds): void
{
$expectedMilliseconds = round($expectedMilliseconds, 2);

Expand Down