From 0147dcb2f9d3b9e75c5c0ffa1d0036b3f04effc3 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 7 Aug 2023 17:59:01 +0100 Subject: [PATCH 1/2] Update to support Codeception versions 4 and 5 --- composer.json | 4 +-- src/Module/MailCatcher.php | 54 ++++++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 3f3d74a..1fb3d08 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "php": "^7.4 || ^8.0", "ext-json": "*", "guzzlehttp/guzzle": "^6.0 || ^7.0", - "codeception/codeception": "^3.0 || ^4.0", + "codeception/codeception": "^4.0 || ^5.0", "zbateson/mail-mime-parser": "^1.2" }, "autoload": { @@ -25,7 +25,7 @@ } }, "require-dev": { - "codeception/module-asserts": "^1.1", + "codeception/module-asserts": "^1.1 || ^2", "phpmailer/phpmailer": "^6.1.6" }, "suggest": { diff --git a/src/Module/MailCatcher.php b/src/Module/MailCatcher.php index 8f61092..f8fa4d5 100644 --- a/src/Module/MailCatcher.php +++ b/src/Module/MailCatcher.php @@ -2,28 +2,54 @@ namespace Codeception\Module; +use Codeception\Codecept; use Codeception\Module; use Codeception\Util\Email; use GuzzleHttp\Client; use ZBateson\MailMimeParser\Message; -class MailCatcher extends Module -{ - /** - * @var Client - */ - protected $mailcatcher; +if (substr(Codecept::VERSION, 0, 1) === '4') { + class MailCatcher extends Module + { + /** + * @var array + */ + protected $config = ['url', 'port', 'guzzleRequestOptions']; + + /** + * @var Client + */ + protected $mailcatcher; + + /** + * @var array + */ + protected $requiredFields = ['url', 'port']; + + use MailCatcherImplementation; + } +} else { + class MailCatcher extends Module + { + /** + * @var array + */ + protected array $config = ['url', 'port', 'guzzleRequestOptions']; - /** - * @var array - */ - protected $config = ['url', 'port', 'guzzleRequestOptions']; + protected Client $mailcatcher; - /** - * @var array - */ - protected $requiredFields = ['url', 'port']; + protected array $requiredFields = ['url', 'port']; + use MailCatcherImplementation; + } +} + +/** + * @internal The methods as exposed by the MailCatcher class are public but do + * not depend on the existence of this trait. + */ +trait MailCatcherImplementation +{ public function _initialize(): void { $base_uri = trim($this->config['url'], '/') . ':' . $this->config['port']; From 34793c64da22c4a1f251b9f4eedf584667d3edd3 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 8 Aug 2023 13:47:40 +0100 Subject: [PATCH 2/2] Update CI to ensure both supported Codeception branches are tested --- .github/workflows/tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bd4d0b1..bee4b95 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,6 +18,11 @@ jobs: strategy: matrix: php: ['7.4', '8.0', '8.1'] + codeception: ['^4.0', '^5.0'] + exclude: + # Codeception 5 requires PHP ≥ 8 + - php: '7.4' + codeception: '^5.0' steps: - uses: actions/checkout@v3 @@ -39,6 +44,7 @@ jobs: - uses: ramsey/composer-install@v2 with: dependency-versions: highest + composer-options: "--with=codeception/codeception:${{ matrix.codeception }}" - run: php vendor/bin/codecept build - name: Acceptance tests run: php vendor/bin/codecept run acceptance -d