diff --git a/.editorconfig b/.editorconfig index 5e9a93e..8802775 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,6 +10,10 @@ indent_style = space indent_size = 4 trim_trailing_whitespace = true +[*.php] +ij_php_space_before_short_closure_left_parenthesis = false +ij_php_space_after_type_cast = true + [*.md] trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes index a8d4072..65a6a4e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,10 +1,39 @@ -# Ignore all test and documentation for archive -/.editorconfig export-ignore -/.github export-ignore -/.gitattributes export-ignore -/.gitignore export-ignore -/.scrutinizer.yml export-ignore -/.travis.yml export-ignore -/phpunit.xml.dist export-ignore -/tests export-ignore -/docs export-ignore +# Autodetect text files +* text=auto eol=lf + +# ...Unless the name matches the following overriding patterns + +# Definitively text files +*.php text +*.css text +*.js text +*.txt text +*.md text +*.xml text +*.json text +*.bat text +*.sql text +*.yml text + +# Ensure those won't be messed up with +*.png binary +*.jpg binary +*.gif binary +*.ttf binary + +# Avoid merge conflicts in CHANGELOG +# https://about.gitlab.com/2015/02/10/gitlab-reduced-merge-conflicts-by-90-percent-with-changelog-placeholders/ +/CHANGELOG.md merge=union + +# Exclude files from the archive +/.gitattributes export-ignore +/.github export-ignore +/.gitignore export-ignore +/.styleci.yml export-ignore +/codeception.yml export-ignore +/composer-require-checker.json export-ignore +/docs export-ignore +/phpunit.xml.dist export-ignore +/psalm.xml export-ignore +/rector.php export-ignore +/tests export-ignore diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 89eb03b..a31b3c0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,49 +1,32 @@ -name: build +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' -on: [push, pull_request] + push: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' -env: - DEFAULT_COMPOSER_FLAGS: "--prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi" +name: build jobs: - phpunit: - name: PHP ${{ matrix.php }} on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - php: ['8.1', '8.2'] - - steps: - - name: Install sendmail - run: sudo apt-get install -y sendmail - - name: Checkout - uses: actions/checkout@v2 - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - coverage: pcov - - 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@v1 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer-${{ matrix.php }}- - - name: Install dependencies - run: composer update $DEFAULT_COMPOSER_FLAGS - - name: Install logging proxy - if: ${{ matrix.php != '7.4' }} - run: composer require "yiisoft/yii2-psr-log-source" - - name: Run unit tests with coverage - run: vendor/bin/phpunit --coverage-text - - name: Static analysis (Psalm) - run: vendor/bin/psalm - - name: Static analysis (phpstan) - run: vendor/bin/phpstan - - name: Test code style - run: vendor/bin/ecs + phpunit: + uses: yiisoft/actions/.github/workflows/phpunit.yml@master + with: + composer-command: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi --ignore-platform-req=php+ + os: >- + ['ubuntu-latest'] + php: >- + ['8.1', '8.2', '8.3'] diff --git a/.github/workflows/dependency-check.yml b/.github/workflows/dependency-check.yml new file mode 100644 index 0000000..59be2fc --- /dev/null +++ b/.github/workflows/dependency-check.yml @@ -0,0 +1,33 @@ +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'phpunit.xml.dist' + - 'psalm.xml' + + push: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'phpunit.xml.dist' + - 'psalm.xml' + +name: dependency-check + +jobs: + composer-require-checker: + uses: yiisoft/actions/.github/workflows/composer-require-checker.yml@master + with: + os: >- + ['ubuntu-latest'] + php: >- + ['8.1'] diff --git a/.github/workflows/ecs.yml b/.github/workflows/ecs.yml new file mode 100644 index 0000000..7f2b641 --- /dev/null +++ b/.github/workflows/ecs.yml @@ -0,0 +1,31 @@ +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'phpunit.xml.dist' + + push: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'phpunit.xml.dist' + +name: ecs + +jobs: + easy-coding-standard: + uses: yiisoft/actions/.github/workflows/ecs.yml@master + with: + os: >- + ['ubuntu-latest'] + php: >- + ['8.1'] diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml new file mode 100644 index 0000000..598077b --- /dev/null +++ b/.github/workflows/mutation.yml @@ -0,0 +1,32 @@ +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'psalm.xml' + + push: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'psalm.xml' + +name: mutation test + +jobs: + mutation: + uses: yiisoft/actions/.github/workflows/roave-infection.yml@master + secrets: + STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} + with: + extensions: runkit7 + os: >- + ['ubuntu-latest'] + php: >- + ['8.1'] diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 0000000..58b5407 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,31 @@ +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'phpunit.xml.dist' + + push: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'phpunit.xml.dist' + +name: static analysis + +jobs: + psalm: + uses: yiisoft/actions/.github/workflows/psalm.yml@master + with: + os: >- + ['ubuntu-latest'] + php: >- + ['8.1'] diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..6f428b6 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,87 @@ +preset: psr12 +risky: true + +version: 8.1 + +finder: + exclude: + - docs + - vendor + +enabled: + - alpha_ordered_traits + - array_indentation + - array_push + - combine_consecutive_issets + - combine_consecutive_unsets + - combine_nested_dirname + - declare_strict_types + - dir_constant + - empty_loop_body_braces + - fully_qualified_strict_types + - function_to_constant + - hash_to_slash_comment + - integer_literal_case + - is_null + - logical_operators + - magic_constant_casing + - magic_method_casing + - method_separation + - modernize_types_casting + - native_function_casing + - native_function_type_declaration_casing + - no_alias_functions + - no_empty_comment + - no_empty_phpdoc + - no_empty_statement + - no_extra_block_blank_lines + - no_short_bool_cast + - no_superfluous_elseif + - no_unneeded_control_parentheses + - no_unneeded_curly_braces + - no_unneeded_final_method + - no_unset_cast + - no_unused_imports + - no_unused_lambda_imports + - no_useless_else + - no_useless_return + - normalize_index_brace + - php_unit_dedicate_assert + - php_unit_dedicate_assert_internal_type + - php_unit_expectation + - php_unit_mock + - php_unit_mock_short_will_return + - php_unit_namespaced + - php_unit_no_expectation_annotation + - phpdoc_no_empty_return + - phpdoc_no_useless_inheritdoc + - phpdoc_order + - phpdoc_property + - phpdoc_scalar + - phpdoc_singular_inheritdoc + - phpdoc_trim + - phpdoc_trim_consecutive_blank_line_separation + - phpdoc_type_to_var + - phpdoc_types + - phpdoc_types_order + - print_to_echo + - regular_callable_call + - return_assignment + - self_accessor + - self_static_accessor + - set_type_to_cast + - short_array_syntax + - short_list_syntax + - simplified_if_return + - single_quote + - standardize_not_equals + - ternary_to_null_coalescing + - trailing_comma_in_multiline_array + - unalign_double_arrow + - unalign_equals + - union_type_without_spaces + +disabled: + - function_declaration + - psr12_braces + - psr12_class_definition diff --git a/README.md b/README.md index fe203cb..7f62ac6 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,14 @@ For license information check the [LICENSE](LICENSE.md)-file. [![Latest Stable Version](https://poser.pugx.org/yiisoft/yii2-symfonymailer/v/stable.png)](https://packagist.org/packages/yiisoft/yii2-symfonymailer) [![Total Downloads](https://poser.pugx.org/yiisoft/yii2-symfonymailer/downloads.png)](https://packagist.org/packages/yiisoft/yii2-symfonymailer) [![Build Status](https://github.com/yiisoft/yii2-symfonymailer/workflows/build/badge.svg)](https://github.com/yiisoft/yii2-symfonymailer/actions) +[![codecov](https://codecov.io/gh/yiisoft/yii2-symfonymailer/graph/badge.svg?token=XCj60xP699)](https://codecov.io/gh/yiisoft/yii2-symfonymailer) +[![static analysis](https://github.com/yiisoft/yii2-symfonymailer/actions/workflows/static.yml/badge.svg)](https://github.com/yiisoft/yii2-symfonymailer/actions/workflows/static.yml) +[![type-coverage](https://shepherd.dev/github/yiisoft/yii2-symfonymailer/coverage.svg)](https://shepherd.dev/github/yiisoft/yii2-symfonymailer) + +Requirements +------------ + +- PHP 8.1 or higher. Installation ------------ @@ -150,3 +158,7 @@ Security implications of the DSN While the DSN might seem like a simple way to allow user configurable mailer settings it should be noted that the sendmail transport allows for execution of local executables. If you need to have a user configurable DSN (which is easier to build and more powerful to use than creating a GUI) you should probably disable the sendmail transport. Any user who has the power to configure a DSN essentially has shell access to wherever the code is running. + +## Testing + +[Check the documentation testing](/docs/testing.md) to learn about testing. diff --git a/composer-require-checker.json b/composer-require-checker.json new file mode 100644 index 0000000..9e0e296 --- /dev/null +++ b/composer-require-checker.json @@ -0,0 +1,5 @@ +{ + "symbol-whitelist": [ + "yii\\psr\\DynamicLogger" + ] +} diff --git a/composer.json b/composer.json index 9d6373c..d260da3 100644 --- a/composer.json +++ b/composer.json @@ -26,16 +26,17 @@ ], "require": { "php": ">=8.1", - "yiisoft/yii2": ">=2.0.4", - "symfony/mailer": ">=6" + "psr/event-dispatcher": "1.0.0", + "symfony/mailer": "^6.4 || ^7.0", + "symfony/mime": "^6.4 || ^7.0", + "yiisoft/yii2": ">=2.0.4" }, "require-dev": { - "phpunit/phpunit": "^10", - "symplify/easy-coding-standard": "^10", - "vimeo/psalm": "^5", - "captainhook/captainhook": "^5.10", - "captainhook/plugin-composer": "^5.3", - "phpstan/phpstan": "^1.9" + "maglnet/composer-require-checker": "^4.7", + "phpunit/phpunit": "^10.5", + "roave/infection-static-analysis-plugin": "^1.34", + "symplify/easy-coding-standard": "^12.1", + "vimeo/psalm": "^5.20" }, "suggest": { "yiisoft/yii2-psr-log-source": "Allows routing transport logs to your Yii2 logger" @@ -59,12 +60,23 @@ "extra": { "branch-alias": { "dev-master": "3.0.x-dev" - } + }, + "sort-packages": true }, "config": { "allow-plugins": { "yiisoft/yii2-composer": true, - "captainhook/plugin-composer": true + "infection/extension-installer": true } + }, + "scripts": { + "check-dependencies": "composer-require-checker", + "easy-coding-standard": "ecs check", + "mutation": [ + "Composer\\Config::disableProcessTimeout", + "roave-infection-static-analysis-plugin" + ], + "psalm": "psalm", + "test": "phpunit" } } diff --git a/docs/testing.md b/docs/testing.md new file mode 100644 index 0000000..62eb2df --- /dev/null +++ b/docs/testing.md @@ -0,0 +1,45 @@ +# Testing + +## Checking dependencies + +This package uses [composer-require-checker](https://github.com/maglnet/ComposerRequireChecker) to check if all +dependencies are correctly defined in `composer.json`. + +To run the checker, execute the following command: + +```shell +composer run check-dependencies +``` + +## Easy coding standard + +The code is checked with [Easy Coding Standard](https://github.com/easy-coding-standard/easy-coding-standard) and +[PHP CS Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer). To run it: + +```shell +composer run ecs +``` + +## Mutation testing + +Mutation testing is checked with [Infection](https://infection.github.io/). To run it: + +```shell +composer run mutation +``` + +## Static analysis + +The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis: + +```shell +composer run psalm +``` + +## Unit tests + +The code is tested with [PHPUnit](https://phpunit.de/). To run tests: + +``` +composer run test +``` diff --git a/ecs.php b/ecs.php index 6535bf3..cb4354f 100644 --- a/ecs.php +++ b/ecs.php @@ -2,36 +2,38 @@ declare(strict_types=1); -use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer; -use PhpCsFixer\Fixer\ClassNotation\FinalInternalClassFixer; +use PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer; +use PhpCsFixer\Fixer\ClassNotation\OrderedTraitsFixer; use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer; -use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; -use Symplify\EasyCodingStandard\ValueObject\Option; -use Symplify\EasyCodingStandard\ValueObject\Set\SetList; -return static function (ECSConfig $ecsConfig): void { - $ecsConfig->paths([ - __DIR__ . '/src', - __DIR__ . '/tests', - ]); - - // run and fix, one by one - $ecsConfig->import(SetList::ARRAY); - $ecsConfig->import(SetList::DOCBLOCK); - $ecsConfig->import(SetList::PSR_12); - - $ecsConfig->ruleWithConfiguration(ArraySyntaxFixer::class, [ - 'syntax' => 'short' - ]); - $ecsConfig->rule(NoUnusedImportsFixer::class); - $ecsConfig->rule(DeclareStrictTypesFixer::class); - $ecsConfig->ruleWithConfiguration(FinalInternalClassFixer::class, [ - 'annotation_exclude' => ['@extendable'], - 'annotation_include' => [], - 'consider_absent_docblock_as_internal_class' => \true - ]); - - - -}; +return ECSConfig::configure() + ->withConfiguredRule( + ClassDefinitionFixer::class, + [ + 'space_before_parenthesis' => true, + ], + ) + ->withFileExtensions(['php']) + ->withPaths( + [ + __DIR__ . '/src', + __DIR__ . '/tests', + ], + ) + ->withPhpCsFixerSets(perCS20: true) + ->withPreparedSets( + arrays: true, + cleanCode: true, + comments:true, + docblocks: true, + namespaces: true, + psr12: true, + strict: true + ) + ->withRules( + [ + NoUnusedImportsFixer::class, + OrderedTraitsFixer::class, + ] + ); diff --git a/infection.json.dist b/infection.json.dist new file mode 100644 index 0000000..3776e22 --- /dev/null +++ b/infection.json.dist @@ -0,0 +1,16 @@ +{ + "source": { + "directories": [ + "src" + ] + }, + "logs": { + "text": "php:\/\/stderr", + "stryker": { + "report": "master" + } + }, + "mutators": { + "@default": true + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0320848..6e24b41 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,12 @@ - + ./tests diff --git a/psalm.xml b/psalm.xml index 8822f66..943c003 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,17 +1,17 @@ - - - - - - + + + + + + diff --git a/src/DkimMessageSigner.php b/src/DkimMessageSigner.php index c0ba6a5..3fc7df7 100644 --- a/src/DkimMessageSigner.php +++ b/src/DkimMessageSigner.php @@ -17,6 +17,7 @@ final class DkimMessageSigner implements MessageSignerInterface { private DkimSigner $dkimSigner; + public function __construct(DkimSigner $dkimSigner) { $this->dkimSigner = $dkimSigner; diff --git a/src/EventDispatcherProxy.php b/src/EventDispatcherProxy.php index baac57a..0fda9e5 100644 --- a/src/EventDispatcherProxy.php +++ b/src/EventDispatcherProxy.php @@ -10,7 +10,8 @@ final class EventDispatcherProxy implements EventDispatcherInterface { private Component $component; - public function __construct(Component $component) + + public function __construct(Component $component) { $this->component = $component; } diff --git a/src/Mailer.php b/src/Mailer.php index 566052e..04fbe52 100644 --- a/src/Mailer.php +++ b/src/Mailer.php @@ -43,7 +43,7 @@ class Mailer extends BaseMailer */ public array $signerOptions = []; /** - * @var null|TransportInterface Symfony transport instance or its array configuration. + * @var TransportInterface|null Symfony transport instance or its array configuration. */ private ?TransportInterface $_transport = null; public ?Transport $transportFactory = null; diff --git a/src/Message.php b/src/Message.php index a81f73a..20ae328 100644 --- a/src/Message.php +++ b/src/Message.php @@ -24,7 +24,7 @@ * @psalm-type PsalmAddressList array|string * * @property PsalmAddressList $bcc The type defined by the message interface is not strict enough. - * @property-read Email $symfonyEmail Symfony email instance. + * @property Email $symfonyEmail Symfony email instance. * * @extendable */ @@ -315,7 +315,7 @@ public function addHeader(string $name, string $value): self } /** - * @param string|list $value + * @param list|string $value */ public function setHeader(string $name, array|string $value): self { @@ -331,7 +331,7 @@ public function setHeader(string $name, array|string $value): self } /** - * @param array> $headers + * @param array|string> $headers * @return $this */ public function setHeaders(array $headers): self diff --git a/src/SMimeMessageEncrypter.php b/src/SMimeMessageEncrypter.php index 2081087..ac9cfa1 100644 --- a/src/SMimeMessageEncrypter.php +++ b/src/SMimeMessageEncrypter.php @@ -16,9 +16,7 @@ */ final class SMimeMessageEncrypter implements MessageEncrypterInterface { - public function __construct(private readonly SMimeEncrypter $encrypter) - { - } + public function __construct(private readonly SMimeEncrypter $encrypter) {} public function encrypt(Message $message): Message { diff --git a/src/SMimeMessageSigner.php b/src/SMimeMessageSigner.php index d7f8c87..0c3990d 100644 --- a/src/SMimeMessageSigner.php +++ b/src/SMimeMessageSigner.php @@ -16,9 +16,7 @@ */ final class SMimeMessageSigner implements MessageSignerInterface { - public function __construct(private readonly SMimeSigner $signer) - { - } + public function __construct(private readonly SMimeSigner $signer) {} public function sign(Message $message, array $options = []): Message { diff --git a/tests/MailerTest.php b/tests/MailerTest.php index 66440d7..5778f1f 100644 --- a/tests/MailerTest.php +++ b/tests/MailerTest.php @@ -122,7 +122,6 @@ public function testConfigureTransportFromArrayWithYii(): void public function testConfigureTransportInvalidArray(): void { $transportConfig = [ - ]; $mailer = new Mailer(); $this->expectException(InvalidConfigException::class); diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 1d74fd4..8306fb8 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -51,7 +51,7 @@ public function tearDown(): void */ private function getTestFilePath(): string { - return Yii::getAlias('@yiiunit/extensions/symfonymailer/runtime') . DIRECTORY_SEPARATOR . basename(get_class($this)) . '_' . getmypid(); + return Yii::getAlias('@yiiunit/extensions/symfonymailer/runtime') . DIRECTORY_SEPARATOR . basename(self::class) . '_' . getmypid(); } /** @@ -59,11 +59,9 @@ private function getTestFilePath(): string */ private function createTestEmailComponent(): Mailer { - $component = new Mailer([ + return new Mailer([ 'useFileTransport' => true, ]); - - return $component; } /** @@ -155,7 +153,7 @@ public function testClone(): void $messageWithoutSymfonyInitialized = new Message(); $m2 = clone $messageWithoutSymfonyInitialized; // should be no error during cloning - $this->assertTrue($m2 instanceof Message); + $this->assertInstanceOf(Message::class, $m2); } public function testSetupHeaderShortcuts(): void @@ -189,7 +187,7 @@ public function testSetupHeaderShortcuts(): void $this->assertStringContainsString("To: $to", $messageString, 'Incorrect "To" header!'); $this->assertStringContainsString("Cc: $cc", $messageString, 'Incorrect "Cc" header!'); $this->assertStringContainsString("Return-Path: <{$returnPath}>", $messageString, 'Incorrect "Return-Path" header!'); - $this->assertStringContainsString("X-Priority: 2 (High)", $messageString, 'Incorrect "Priority" header!'); + $this->assertStringContainsString('X-Priority: 2 (High)', $messageString, 'Incorrect "Priority" header!'); } public function testSend(): void @@ -219,7 +217,7 @@ public function testAttachFile(): void $this->assertTrue($message->send()); $attachment = $this->getAttachment($message); - $this->assertTrue(is_object($attachment), 'No attachment found!'); + $this->assertIsObject($attachment, 'No attachment found!'); $this->assertStringContainsString("attachment filename: $fileName", $attachment->asDebugString(), 'Invalid file name!'); } @@ -243,7 +241,7 @@ public function testAttachContent(): void $this->assertTrue($message->send()); $attachment = $this->getAttachment($message); - $this->assertTrue(is_object($attachment), 'No attachment found!'); + $this->assertIsObject($attachment, 'No attachment found!'); $this->assertStringContainsString("attachment filename: $fileName", $attachment->asDebugString(), 'Invalid file name!'); $this->assertStringContainsString('image/png', $attachment->asDebugString(), 'Invalid content type!'); } @@ -268,9 +266,9 @@ public function testEmbedFile(): void $this->assertTrue($message->send()); $attachment = $this->getAttachment($message); - $this->assertTrue(is_object($attachment), 'No attachment found!'); + $this->assertIsObject($attachment, 'No attachment found!'); $this->assertStringContainsString(" filename: $fileName", $attachment->asDebugString(), 'Invalid file name!'); - $this->assertStringContainsString(" disposition: inline", $attachment->asDebugString(), 'Invalid disposition!'); + $this->assertStringContainsString(' disposition: inline', $attachment->asDebugString(), 'Invalid disposition!'); } /** @@ -300,10 +298,10 @@ public function testEmbedContent(): void $this->assertTrue($message->send()); $attachment = $this->getAttachment($message); - $this->assertTrue(is_object($attachment), 'No attachment found!'); + $this->assertIsObject($attachment, 'No attachment found!'); $this->assertStringContainsString(" filename: $fileName", $attachment->asDebugString(), 'Invalid file name!'); $this->assertStringContainsString($contentType, $attachment->asDebugString(), 'Invalid content type!'); - $this->assertStringContainsString(" disposition: inline", $attachment->asDebugString(), 'Invalid disposition!'); + $this->assertStringContainsString(' disposition: inline', $attachment->asDebugString(), 'Invalid disposition!'); } /** @@ -351,6 +349,7 @@ public function testThatSerializeDoesNotSerializeMailer(): void $unserializedMessage = unserialize(serialize($message)); $this->assertNull($unserializedMessage->mailer); } + /** * @depends testSendAlternativeBody */ @@ -422,7 +421,7 @@ public function testSetupHeaders(): void /** * Finds the attachment object in the message. * @param Message $message message instance - * @return null|DataPart attachment instance. + * @return DataPart|null attachment instance. */ protected function getAttachment(Message $message): ?DataPart { diff --git a/tests/TestCase.php b/tests/TestCase.php index 5462efb..eb11124 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -35,9 +35,9 @@ protected function mockApplication($config = [], $appClass = '\yii\console\Appli protected function getVendorPath() { - $vendor = dirname(dirname(__DIR__)) . '/vendor'; + $vendor = dirname(__DIR__, 2) . '/vendor'; if (!is_dir($vendor)) { - $vendor = dirname(dirname(dirname(dirname(__DIR__)))); + $vendor = dirname(__DIR__, 4); } return $vendor; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 93fa97b..9c8e2cc 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -15,5 +15,3 @@ Yii::setAlias('@yiiunit/extensions/symfonymailer', __DIR__); Yii::setAlias('@yii/symfonymailer', dirname(__DIR__) . '/src'); - -require_once(__DIR__ . '/compatibility.php'); diff --git a/tests/compatibility.php b/tests/compatibility.php deleted file mode 100644 index 6a5794a..0000000 --- a/tests/compatibility.php +++ /dev/null @@ -1,37 +0,0 @@ -setExpectedException($exception); - } - - /** - * @param string $message - */ - public function expectExceptionMessage($message) - { - $this->setExpectedException($this->getExpectedException(), $message); - } - } - } -}