Skip to content

Symfony 6.4 Support #177

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 4 commits into from
Jan 7, 2024
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
65 changes: 13 additions & 52 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,12 @@ jobs:

strategy:
matrix:
php: [8.0, 8.1, 8.2]
symfony: ["4.4.*", "5.4.*", "6.0.*", "6.1.*", "6.2.*", "6.3.*"]
exclude:
- php: 8.0
symfony: "6.1.*"
- php: 8.0
symfony: "6.2.*"
- php: 8.0
symfony: "6.3.*"
php: [8.1, 8.2, 8.3]
symfony: ["5.4.*", "6.4.*"]

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -30,67 +23,35 @@ jobs:
extensions: ctype, iconv, intl, json, mbstring, pdo, pdo_sqlite
coverage: none

- name: Checkout Symfony 4.4 Sample
if: "matrix.symfony == '4.4.*'"
uses: actions/checkout@v2
with:
repository: Codeception/symfony-module-tests
path: framework-tests
ref: "4.4_codecept5"

- name: Checkout Symfony 5.4 Sample
if: "matrix.symfony == '5.4.*'"
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
repository: Codeception/symfony-module-tests
path: framework-tests
ref: "5.4_codecept5"

- name: Checkout Symfony 6.0 Sample
if: "matrix.symfony == '6.0.*'"
uses: actions/checkout@v2
- name: Checkout Symfony 6.4 Sample
if: "matrix.symfony == '6.4.*'"
uses: actions/checkout@v4
with:
repository: Codeception/symfony-module-tests
path: framework-tests
ref: "6.0"

- name: Checkout Symfony 6.1 Sample
if: "matrix.symfony == '6.1.*'"
uses: actions/checkout@v2
with:
repository: Codeception/symfony-module-tests
path: framework-tests
ref: "6.1"

- name: Checkout Symfony 6.2 Sample
if: "matrix.symfony == '6.2.*'"
uses: actions/checkout@v2
with:
repository: Codeception/symfony-module-tests
path: framework-tests
ref: "6.2"

- name: Checkout Symfony 6.3 Sample
if: "matrix.symfony == '6.3.*'"
uses: actions/checkout@v2
with:
repository: Codeception/symfony-module-tests
path: framework-tests
ref: "6.3"
ref: "6.4"

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v2.1.3
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer-

- name: Install PHPUnit 9 for Symfony 4.4, 5.4 and 6.0
if: "matrix.symfony == '4.4.*' || matrix.symfony == '5.4.*' || matrix.symfony == '6.0.*'"
- name: Install PHPUnit 9 for Symfony 5.4
if: "matrix.symfony == '5.4.*'"
run: composer require --dev --no-update "phpunit/phpunit=^9.0"

- name: Install dependencies
Expand All @@ -111,8 +72,8 @@ jobs:
run: composer validate
working-directory: framework-tests

- name: Install PHPUnit 10 in framework-tests for Symfony 6.1 and 6.2
if: "matrix.symfony == '6.1.*' || matrix.symfony == '6.2.*' || matrix.symfony == '6.3.*'"
- name: Install PHPUnit 10 in framework-tests for Symfony 6.4
if: "matrix.symfony == '6.4.*'"
run: composer require --dev --no-update "phpunit/phpunit=^10.0"
working-directory: framework-tests

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2011-2020 Michael Bodnarchuk and contributors
Copyright (c) 2011-2024 Michael Bodnarchuk and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"homepage": "https://codeception.com/",
"require": {
"php": "^8.0",
"php": "^8.1",
"ext-json": "*",
"codeception/codeception": "^5.0.8",
"codeception/lib-innerbrowser": "^3.1.1 | ^4.0"
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ A Codeception module for Symfony framework.

## Requirements

* `Symfony` `4.4.x`, `5.4.x`, `6.x` or higher, as per the [Symfony supported versions](https://symfony.com/releases).
* `PHP 8.0` or higher.
* `Symfony` `5.4.x`, `6.4.x` or higher, as per the [Symfony supported versions](https://symfony.com/releases).
* `PHP 8.1` or higher.

## Installation

Expand Down
23 changes: 8 additions & 15 deletions src/Codeception/Lib/Connector/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,29 @@

class Symfony extends HttpKernelBrowser
{
private bool $rebootable;

private bool $hasPerformedRequest = false;

private ?ContainerInterface $container;

public array $persistentServices = [];

/**
* Constructor.
*
* @param Kernel $kernel A booted HttpKernel instance
* @param array $services An injected services
* @param bool $rebootable
* @param array $persistentServices An injected services
*/
public function __construct(Kernel $kernel, array $services = [], bool $rebootable = true)
{
public function __construct(
Kernel $kernel,
public array $persistentServices = [],
private readonly bool $rebootable = true
) {
parent::__construct($kernel);
$this->followRedirects();
$this->rebootable = $rebootable;
$this->persistentServices = $services;
$this->container = $this->getContainer();
$this->rebootKernel();
}

/**
* @param Request $request
* @return Response
*/
protected function doRequest($request): Response
/** @param Request $request */
protected function doRequest(object $request): Response
{
if ($this->rebootable) {
if ($this->hasPerformedRequest) {
Expand Down
17 changes: 8 additions & 9 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
use Symfony\Component\VarDumper\Cloner\Data;
use function array_keys;
use function array_map;
use function array_merge;
use function array_search;
use function array_unique;
use function class_exists;
Expand Down Expand Up @@ -74,7 +73,7 @@
*
* ## Config
*
* ### Symfony 5.x or 4.4
* ### Symfony 5.4 or higher
*
* * app_path: 'src' - Specify custom path to your app dir, where the kernel interface is located.
* * environment: 'local' - Environment used for load kernel
Expand All @@ -83,8 +82,8 @@
* * debug: true - Turn on/off debug mode
* * cache_router: 'false' - Enable router caching between tests in order to [increase performance](http://lakion.com/blog/how-did-we-speed-up-sylius-behat-suite-with-blackfire)
* * rebootable_client: 'true' - Reboot client's kernel before each request
* * guard: 'false' - Enable custom authentication system with guard (only for 4.x and 5.x versions of the symfony)
* * authenticator: 'false' - Reboot client's kernel before each request (only for 6.x versions of the symfony)
* * guard: 'false' - Enable custom authentication system with guard (only for Symfony 5.4)
* * authenticator: 'false' - Reboot client's kernel before each request (only for Symfony 6.0 or higher)
*
* #### Example (`functional.suite.yml`) - Symfony 4 Directory Structure
*
Expand Down Expand Up @@ -126,7 +125,7 @@
* browser: firefox
* ```
*
* If you're using Symfony with Eloquent ORM (instead of Doctrine), you can load the [`ORM` part of Laravel module](https://codeception.com/docs/modules/Laravel5#Parts)
* If you're using Symfony with Eloquent ORM (instead of Doctrine), you can load the [`ORM` part of Laravel module](https://codeception.com/docs/modules/Laravel#Parts)
* in addition to Symfony module.
*
*/
Expand Down Expand Up @@ -215,7 +214,7 @@ public function _initialize(): void
*/
public function _before(TestInterface $test): void
{
$this->persistentServices = array_merge($this->persistentServices, $this->permanentServices);
$this->persistentServices = [...$this->persistentServices, ...$this->permanentServices];
$this->client = new SymfonyConnector($this->kernel, $this->persistentServices, $this->config['rebootable_client']);
}

Expand Down Expand Up @@ -322,7 +321,7 @@ protected function getKernelClass(): string

$this->requireAdditionalAutoloader();

$filesRealPath = array_map(function ($file) {
$filesRealPath = array_map(static function ($file) {
require_once $file;
return $file->getRealPath();
}, $results);
Expand All @@ -331,7 +330,7 @@ protected function getKernelClass(): string

if (class_exists($kernelClass)) {
$reflectionClass = new ReflectionClass($kernelClass);
if ($file = array_search($reflectionClass->getFileName(), $filesRealPath)) {
if ($file = array_search($reflectionClass->getFileName(), $filesRealPath, true)) {
return $kernelClass;
}

Expand All @@ -355,7 +354,7 @@ protected function getProfile(): ?Profile
try {
$response = $this->getClient()->getResponse();
return $profiler->loadProfileFromResponse($response);
} catch (BadMethodCallException $e) {
} catch (BadMethodCallException) {
$this->fail('You must perform a request before using this method.');
} catch (Exception $e) {
$this->fail($e->getMessage());
Expand Down
5 changes: 1 addition & 4 deletions src/Codeception/Module/Symfony/BrowserAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function rebootClientKernel(): void

/**
* Verifies that a page is available.
* By default it checks the current page, specify the `$url` parameter to change it.
* By default, it checks the current page, specify the `$url` parameter to change it.
*
* ```php
* <?php
Expand Down Expand Up @@ -60,9 +60,6 @@ public function seePageIsAvailable(string $url = null): void
* <?php
* $I->seePageRedirectsTo('/admin', '/login');
* ```
*
* @param string $page
* @param string $redirectsTo
*/
public function seePageRedirectsTo(string $page, string $redirectsTo): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Codeception/Module/Symfony/EventsAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trait EventsAssertionsTrait
*/
public function dontSeeEvent(array|string $expected = null): void
{
$actualEvents = array_merge(array_column($this->getCalledListeners(), 'event'));
$actualEvents = [...array_column($this->getCalledListeners(), 'event')];
$actual = [$this->getOrphanedEvents(), $actualEvents];
$this->assertEventTriggered(false, $expected, $actual);
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public function dontSeeOrphanEvent(array|string $expected = null): void
*/
public function seeEvent(array|string $expected): void
{
$actualEvents = array_merge(array_column($this->getCalledListeners(), 'event'));
$actualEvents = [...array_column($this->getCalledListeners(), 'event')];
$actual = [$this->getOrphanedEvents(), $actualEvents];
$this->assertEventTriggered(true, $expected, $actual);
}
Expand Down
1 change: 0 additions & 1 deletion src/Codeception/Module/Symfony/FormAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function dontSeeFormErrors(): void
* $I->seeFormErrorMessage('username', 'Username is empty');
* ```
*
* @param string $field
* @param string|null $message
*/
public function seeFormErrorMessage(string $field, string $message = null): void
Expand Down
17 changes: 5 additions & 12 deletions src/Codeception/Module/Symfony/MailerAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ trait MailerAssertionsTrait
/**
* Checks that no email was sent.
* The check is based on `\Symfony\Component\Mailer\EventListener\MessageLoggerListener`, which means:
* If your app performs a HTTP redirect, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first; otherwise this check will *always* pass.
* Starting with version 2.0.0, `codeception/module-symfony` requires your app to use [Symfony Mailer](https://symfony.com/doc/current/mailer.html). If your app still uses [Swift Mailer](https://symfony.com/doc/current/email.html), set your version constraint to `^1.6`.
* If your app performs an HTTP redirect, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first; otherwise this check will *always* pass.
*/
public function dontSeeEmailIsSent(): void
{
Expand All @@ -25,8 +24,7 @@ public function dontSeeEmailIsSent(): void
/**
* Checks if the given number of emails was sent (default `$expectedCount`: 1).
* The check is based on `\Symfony\Component\Mailer\EventListener\MessageLoggerListener`, which means:
* If your app performs a HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first.
* Starting with version 2.0.0, `codeception/module-symfony` requires your app to use [Symfony Mailer](https://symfony.com/doc/current/mailer.html). If your app still uses [Swift Mailer](https://symfony.com/doc/current/email.html), set your version constraint to `^1.6`.
* If your app performs an HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first.
*
* ```php
* <?php
Expand All @@ -43,8 +41,7 @@ public function seeEmailIsSent(int $expectedCount = 1): void
/**
* Returns the last sent email.
* The function is based on `\Symfony\Component\Mailer\EventListener\MessageLoggerListener`, which means:
* If your app performs a HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first.
* Starting with version 2.0.0, `codeception/module-symfony` requires your app to use [Symfony Mailer](https://symfony.com/doc/current/mailer.html). If your app still uses [Swift Mailer](https://symfony.com/doc/current/email.html), set your version constraint to `^1.6`.
* If your app performs an HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first.
* See also: [grabSentEmails()](https://codeception.com/docs/modules/Symfony#grabSentEmails)
*
* ```php
Expand All @@ -66,8 +63,7 @@ public function grabLastSentEmail(): ?Email
/**
* Returns an array of all sent emails.
* The function is based on `\Symfony\Component\Mailer\EventListener\MessageLoggerListener`, which means:
* If your app performs a HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first.
* Starting with version 2.0.0, `codeception/module-symfony` requires your app to use [Symfony Mailer](https://symfony.com/doc/current/mailer.html). If your app still uses [Swift Mailer](https://symfony.com/doc/current/email.html), set your version constraint to `^1.6`.
* If your app performs an HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first.
* See also: [grabLastSentEmail()](https://codeception.com/docs/modules/Symfony#grabLastSentEmail)
*
* ```php
Expand All @@ -94,9 +90,6 @@ protected function getMessageMailerEvents(): MessageEvents
return $messageLogger->getEvents();
}

$this->fail("codeception/module-symfony requires Symfony Mailer https://symfony.com/doc/current/mailer.html to test emails. If your app still uses Swift Mailer, downgrade codeception/module-symfony to ^1.6


Emails can't be tested without Symfony Mailer service.");
$this->fail("Emails can't be tested without Symfony Mailer service.");
}
}
4 changes: 2 additions & 2 deletions src/Codeception/Module/Symfony/MimeAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ public function assertEmailTextBodyNotContains(string $text, Email $email = null
private function verifyEmailObject(?Email $email, string $function): Email
{
$email = $email ?: $this->grabLastSentEmail();
$errorMsgFormat = "There is no email to verify. An Email object was not specified when invoking '%s' and the application has not sent one.";
$errorMsgTemplate = "There is no email to verify. An Email object was not specified when invoking '%s' and the application has not sent one.";
return $email ?: $this->fail(
sprintf($errorMsgFormat, $function)
sprintf($errorMsgTemplate, $function)
);
}
}
6 changes: 2 additions & 4 deletions src/Codeception/Module/Symfony/ParameterAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Codeception\Module\Symfony;

use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use UnitEnum;

trait ParameterAssertionsTrait
{
Expand All @@ -15,11 +16,8 @@ trait ParameterAssertionsTrait
* <?php
* $I->grabParameter('app.business_name');
* ```
*
* @param string $parameterName
* @return array|bool|float|int|string|null
*/
public function grabParameter(string $parameterName)
public function grabParameter(string $parameterName): array|bool|string|int|float|UnitEnum|null
{
$parameterBag = $this->grabParameterBagService();
return $parameterBag->get($parameterName);
Expand Down
Loading