From c6c592b7e7d3646cb90cf18a164632787819ac41 Mon Sep 17 00:00:00 2001 From: HorstOeko Date: Thu, 16 Jan 2025 19:28:22 +0100 Subject: [PATCH] Revert "[CS] Code cleanup (Part 9)" This reverts commit 961103e3a3be496f3f4c2ceab79ebad9ed8d095c. Revert "[CS] Code cleanup (Part 8)" This reverts commit 17f89ae1a67db7f860c0d1ba9a09675acef003ac. Revert "[CS] Code cleanup (Part 7)" This reverts commit e58d99acea0cfc875c03d892249a8e3f591a8ffa. Revert "[CS] Code cleanup (Part 6)" This reverts commit f33f2517850a493e1b5990965cf48aa692cda41c. Revert "[CS] Code cleanup (Part 5)" This reverts commit ac62d05fbdfa67949e146a9752770251f03cf8a9. Revert "[CS] Code cleanup (Part 4)" This reverts commit 2e2a00a859e6ac18e2925899a88f0cb8f43b5f25. Revert "[CS] Code cleanup (Part 3)" This reverts commit ca1cffb39815c08dfad87b4e6f7fa6f4786901a0. Revert "[CS] Code cleanup (Part 2)"This reverts commit a7009686baa5826b2f063f1816ec7e896d00bf54. Revert "[CS] Code cleanup (Part 1)" This reverts commit 14d7eb6a40f9ce788e13467a6a56453f2e7e69c6. --- build/phprectorconfig.php | 81 ++-- build/phpstan.neon | 17 +- build/phpunit.xml | 81 ++-- src/ZugferdMailMessageBag.php | 24 +- src/ZugferdMailReader.php | 36 +- ...rdMailConsoleHandlesMailAccountOptions.php | 6 +- ...rdMailConsoleOutputsMessageBagMessages.php | 6 +- src/concerns/ZugferdMailRaisesExceptions.php | 2 +- ...ferdMailReceivesMessagesFromMessageBag.php | 1 - .../ZugferdMailSendsMessagesToMessageBag.php | 38 +- src/config/ZugferdMailAccount.php | 30 +- src/config/ZugferdMailConfig.php | 6 +- .../ZugferdMailListFoldersConsoleCommand.php | 9 +- ...ugferdMailProcessFoldersConsoleCommand.php | 6 +- src/handlers/ZugferdMailHandlerAbstract.php | 5 +- src/handlers/ZugferdMailHandlerCli.php | 6 +- .../ZugferdMailHandlerCopyMessage.php | 10 +- .../ZugferdMailHandlerDeleteMessage.php | 8 +- .../ZugferdMailHandlerMarkSeenMessage.php | 8 +- .../ZugferdMailHandlerMarkUnseenMessage.php | 8 +- .../ZugferdMailHandlerMoveMessage.php | 10 +- src/handlers/ZugferdMailHandlerNull.php | 2 +- src/handlers/ZugferdMailHandlerSaveToFile.php | 10 +- src/helpers/ZugferdMailPlaceholderHelper.php | 7 +- tests/TestCase.php | 4 +- tests/testcases/BasicTest.php | 13 + tests/testcases/BuiltinHandlersTest.php | 30 ++ tests/testcases/ZugferdMailAccountTest.php | 70 ++-- ...ConcernConsoleHandlesConfigOptionsTest.php | 2 +- ...rnConsoleHandlesMailAccountOptionsTest.php | 39 +- ...rnConsoleOutputsMessageBagMessagesTest.php | 21 +- .../ZugferdMailConcernMessageBagTest.php | 350 +++++++++--------- ...gferdMailConcernParsesPlaceholdersTest.php | 16 +- ...ZugferdMailConcernRaisesExceptionsTest.php | 14 + tests/testcases/ZugferdMailConfigTest.php | 57 +-- .../ZugferdMailPlaceholderHelperTest.php | 16 +- .../testcases/ZugferdMailStringHelperTest.php | 4 +- 37 files changed, 582 insertions(+), 471 deletions(-) create mode 100644 tests/testcases/BasicTest.php diff --git a/build/phprectorconfig.php b/build/phprectorconfig.php index 699f191..274d469 100644 --- a/build/phprectorconfig.php +++ b/build/phprectorconfig.php @@ -1,42 +1,39 @@ -withPaths([ - __DIR__ . '/../src', - __DIR__ . '/../tests', - ]) - ->withSkip([ - __DIR__ . '/../examples', - __DIR__ . '/../make', - ]) - ->withSkip([ - //ClassPropertyAssignToConstructorPromotionRector::class - ]) - ->withPhpSets(php73: true) - ->withConfiguredRule(EncapsedStringsToSprintfRector::class, [ - 'always' => true, - ]) - ->withPreparedSets( - codeQuality: true, - codingStyle: true, - deadCode: false, - typeDeclarations: true, - privatization: true, - naming: false, - instanceOf: true, - earlyReturn: true, - strictBooleans: true, - phpunitCodeQuality: true - ); +withPaths([ + __DIR__ . '/../examples', + __DIR__ . '/../make', + __DIR__ . '/../src', + __DIR__ . '/../tests', + ]) + ->withSkip([ + RemoveUselessParamTagRector::class, + RemoveUselessReturnTagRector::class, + ]) + ->withPhp73Sets() + ->withSets([ + SetList::DEAD_CODE, + SetList::CODE_QUALITY, + SetList::CODING_STYLE, + ]) + ->withConfiguredRule(EncapsedStringsToSprintfRector::class, [ + 'always' => true, + ]) + ->withRules([ + RenamePropertyToMatchTypeRector::class, + RenameParamToMatchTypeRector::class, + RenameVariableToMatchNewTypeRector::class, + ]) + ->withTypeCoverageLevel(0); diff --git a/build/phpstan.neon b/build/phpstan.neon index 5daa59a..5059614 100644 --- a/build/phpstan.neon +++ b/build/phpstan.neon @@ -1,9 +1,8 @@ -parameters: - paths: - - ../src - - ../tests - level: 5 - treatPhpDocTypesAsCertain: false - excludePaths: - - ../src/entities/* - - ../tests/helpers/TestOutputInterface.php +parameters: + paths: + - ../src + - ../tests + level: 5 + treatPhpDocTypesAsCertain: false + excludePaths: + - ../src/entities/* diff --git a/build/phpunit.xml b/build/phpunit.xml index 5afca21..b32b957 100644 --- a/build/phpunit.xml +++ b/build/phpunit.xml @@ -1,40 +1,43 @@ - - - - - ../tests/testcases/ZugferdMailConfigTest.php - ../tests/testcases/ZugferdMailAccountTest.php - ../tests/testcases/ZugferdMailStringHelperTest.php - ../tests/testcases/ZugferdMailPlaceholderHelperTest.php - - - ../tests/testcases/ZugferdMailConcernRaisesExceptionsTest.php - ../tests/testcases/ZugferdMailConcernMessageBagTest.php - ../tests/testcases/ZugferdMailConcernParsesPlaceholdersTest.php - ../tests/testcases/ZugferdMailConcernConsoleOutputsMessageBagMessagesTest.php - ../tests/testcases/ZugferdMailConcernConsoleHandlesConfigOptionsTest.php - ../tests/testcases/ZugferdMailConcernConsoleHandlesMailAccountOptionsTest.php - - - ../tests/testcases/BuiltinHandlersTest.php - - - - - ../src - - - ../src/bin/ZugferdMailConsole.php - - - - - - - - - - - - + + + + + ../tests/testcases/BasicTest.php + + + ../tests/testcases/ZugferdMailConfigTest.php + ../tests/testcases/ZugferdMailAccountTest.php + ../tests/testcases/ZugferdMailStringHelperTest.php + ../tests/testcases/ZugferdMailPlaceholderHelperTest.php + + + ../tests/testcases/ZugferdMailConcernRaisesExceptionsTest.php + ../tests/testcases/ZugferdMailConcernMessageBagTest.php + ../tests/testcases/ZugferdMailConcernParsesPlaceholdersTest.php + ../tests/testcases/ZugferdMailConcernConsoleOutputsMessageBagMessagesTest.php + ../tests/testcases/ZugferdMailConcernConsoleHandlesConfigOptionsTest.php + ../tests/testcases/ZugferdMailConcernConsoleHandlesMailAccountOptionsTest.php + + + ../tests/testcases/BuiltinHandlersTest.php + + + + + ../src + + + ../src/bin/ZugferdMailConsole.php + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ZugferdMailMessageBag.php b/src/ZugferdMailMessageBag.php index ad1461b..3e230c3 100644 --- a/src/ZugferdMailMessageBag.php +++ b/src/ZugferdMailMessageBag.php @@ -115,7 +115,7 @@ public function addMessage(string $type, string $source, string $message, array * @param array $additionalData * @return ZugferdMailMessageBag */ - public function addLogMessage(string $source, string $message, array $additionalData = []): self + public function addLogMessage(string $source, string $message, array $additionalData = []) { $this->addMessage(ZugferdMailMessageBagType::MESSAGETYPE_LOG, $source, $message, $additionalData); @@ -130,7 +130,7 @@ public function addLogMessage(string $source, string $message, array $additional * @param array $additionalData * @return ZugferdMailMessageBag */ - public function addLogSecondaryMessage(string $source, string $message, array $additionalData = []): self + public function addLogSecondaryMessage(string $source, string $message, array $additionalData = []) { $this->addMessage(ZugferdMailMessageBagType::MESSAGETYPE_LOG_SECONDARY, $source, $message, $additionalData); @@ -145,7 +145,7 @@ public function addLogSecondaryMessage(string $source, string $message, array $a * @param array $additionalData * @return ZugferdMailMessageBag */ - public function addWarningMessage(string $source, string $message, array $additionalData = []): self + public function addWarningMessage(string $source, string $message, array $additionalData = []) { $this->addMessage(ZugferdMailMessageBagType::MESSAGETYPE_WARN, $source, $message, $additionalData); @@ -160,7 +160,7 @@ public function addWarningMessage(string $source, string $message, array $additi * @param array $additionalData * @return ZugferdMailMessageBag */ - public function addErrorMessage(string $source, string $message, array $additionalData = []): self + public function addErrorMessage(string $source, string $message, array $additionalData = []) { $this->addMessage(ZugferdMailMessageBagType::MESSAGETYPE_ERROR, $source, $message, $additionalData); @@ -175,7 +175,7 @@ public function addErrorMessage(string $source, string $message, array $addition * @param array $additionalData * @return ZugferdMailMessageBag */ - public function addSuccessMessage(string $source, string $message, array $additionalData = []): self + public function addSuccessMessage(string $source, string $message, array $additionalData = []) { $this->addMessage(ZugferdMailMessageBagType::MESSAGETYPE_SUCCESS, $source, $message, $additionalData); @@ -217,7 +217,7 @@ private function getMessageBagFilteredByType(string $messageType): array { return array_filter( $this->messageContainer, - function (array $data) use ($messageType): bool { + function ($data) use ($messageType) { return $data['type'] == $messageType; } ); @@ -240,7 +240,7 @@ public function getLogMessages(): array */ public function hasNoLogMessages(): bool { - return $this->getLogMessages() === []; + return empty($this->getLogMessages()); } /** @@ -270,7 +270,7 @@ public function getLogSecondaryMessages(): array */ public function hasNoLogSecondaryMessages(): bool { - return $this->getLogSecondaryMessages() === []; + return empty($this->getLogSecondaryMessages()); } /** @@ -300,7 +300,7 @@ public function getWarningMessages(): array */ public function hasNoWarningMessages(): bool { - return $this->getWarningMessages() === []; + return empty($this->getWarningMessages()); } /** @@ -330,7 +330,7 @@ public function getErrorMessages(): array */ public function hasNoErrorMessages(): bool { - return $this->getErrorMessages() === []; + return empty($this->getErrorMessages()); } /** @@ -360,7 +360,7 @@ public function getSuccessMessages(): array */ public function hasNoSuccessMessages(): bool { - return $this->getSuccessMessages() === []; + return empty($this->getSuccessMessages()); } /** @@ -390,6 +390,6 @@ public function getAllMessages(): array */ public function hasAnyMessage(): bool { - return $this->getAllMessages() !== []; + return !empty($this->getAllMessages()); } } diff --git a/src/ZugferdMailReader.php b/src/ZugferdMailReader.php index aeaa42c..bebcdc6 100644 --- a/src/ZugferdMailReader.php +++ b/src/ZugferdMailReader.php @@ -46,10 +46,10 @@ */ class ZugferdMailReader { - use ZugferdMailSendsMessagesToMessageBag; - use ZugferdMailReceivesMessagesFromMessageBag; - use ZugferdMailClearsMessageBag; - use ZugferdMailRaisesExceptions; + use ZugferdMailSendsMessagesToMessageBag, + ZugferdMailReceivesMessagesFromMessageBag, + ZugferdMailClearsMessageBag, + ZugferdMailRaisesExceptions; /** * The config @@ -132,7 +132,7 @@ public function checkAllAccounts(): ZugferdMailReader protected function checkSingleAccount(ZugferdMailAccount $account): void { $this->clientManager->account($account->getIdentifier())->connect()->getFolders()->each( - function (Folder $folder) use ($account): void { + function (Folder $folder) use ($account) { $this->checkSingleAccountFolder($account, $folder); } ); @@ -157,14 +157,14 @@ function ($query) { return $query->unseen(); } )->get()->each( - function (Message $message) use ($account, $folder): void { + function (Message $message) use ($account, $folder) { $this->checkSingleMessage($account, $folder, $message); } ); } collect($folder->children)->each( - function (Folder $subFolder) use ($account): void { + function (Folder $subFolder) use ($account) { $this->checkSingleAccountFolder($account, $subFolder); } ); @@ -181,7 +181,7 @@ function (Folder $subFolder) use ($account): void { protected function checkSingleMessage(ZugferdMailAccount $account, Folder $folder, Message $message): void { $message->attachments()->each( - function (Attachment $attachment) use ($account, $folder, $message): void { + function (Attachment $attachment) use ($account, $folder, $message) { $this->checkSingleMessageAttachment($account, $folder, $message, $attachment); } ); @@ -217,15 +217,17 @@ protected function checkSingleMessageAttachment(ZugferdMailAccount $account, Fol $document = null; - try { - $this->addLogMessageToMessageBag('Checking for ZUGFeRD compatible PDF', $messageAdditionalData); - $document = ZugferdDocumentPdfReader::readAndGuessFromContent($attachment->getContent()); - $this->addSuccessMessageToMessageBag('Mail contains a ZUGFeRD compatible PDF', $messageAdditionalData); - $this->validateDocument($document, $messageAdditionalData); - $this->triggerHandlers($account, $folder, $message, $attachment, $document, ZugferdMailReaderRecognitionType::ZFMAIL_RECOGNITION_TYPE_PDF_CII); - $this->triggerCallbacks($account, $folder, $message, $attachment, $document, ZugferdMailReaderRecognitionType::ZFMAIL_RECOGNITION_TYPE_PDF_CII); - } catch (Throwable $e) { - $this->addWarningMessageToMessageBag(sprintf("No ZUGFeRD compatible PDF found (%s)", $e->getMessage()), $messageAdditionalData); + if (is_null($document)) { + try { + $this->addLogMessageToMessageBag('Checking for ZUGFeRD compatible PDF', $messageAdditionalData); + $document = ZugferdDocumentPdfReader::readAndGuessFromContent($attachment->getContent()); + $this->addSuccessMessageToMessageBag('Mail contains a ZUGFeRD compatible PDF', $messageAdditionalData); + $this->validateDocument($document, $messageAdditionalData); + $this->triggerHandlers($account, $folder, $message, $attachment, $document, ZugferdMailReaderRecognitionType::ZFMAIL_RECOGNITION_TYPE_PDF_CII); + $this->triggerCallbacks($account, $folder, $message, $attachment, $document, ZugferdMailReaderRecognitionType::ZFMAIL_RECOGNITION_TYPE_PDF_CII); + } catch (Throwable $e) { + $this->addWarningMessageToMessageBag(sprintf("No ZUGFeRD compatible PDF found (%s)", $e->getMessage()), $messageAdditionalData); + } } if (is_null($document)) { diff --git a/src/concerns/ZugferdMailConsoleHandlesMailAccountOptions.php b/src/concerns/ZugferdMailConsoleHandlesMailAccountOptions.php index 7bf8ee4..1cc41e1 100644 --- a/src/concerns/ZugferdMailConsoleHandlesMailAccountOptions.php +++ b/src/concerns/ZugferdMailConsoleHandlesMailAccountOptions.php @@ -139,8 +139,8 @@ protected function writeAccountInformation(OutputInterface $output, ZugferdMailA $account->getPort(), $account->getProtocol(), $account->getEncryption(), - $account->getValidateCert() ? "Yes" : "No", - $account->getAuthentication() ?? "None", + $account->getValidateCert() === true ? "Yes" : "No", + $account->getAuthentication() === null ? "None" : $account->getAuthentication(), $account->getUsername(), ], ] @@ -166,7 +166,6 @@ protected function writeAccountFoldersToWatch(OutputInterface $output, ZugferdMa foreach ($account->getFoldersTowatch() as $folderToWatch) { $table->addRow([$folderToWatch]); } - $table->render(); } @@ -188,7 +187,6 @@ protected function writeAccountMimeTypesToWatch(OutputInterface $output, Zugferd foreach ($account->getMimeTypesToWatch() as $mimeTypeToWatch) { $table->addRow([$mimeTypeToWatch]); } - $table->render(); } } diff --git a/src/concerns/ZugferdMailConsoleOutputsMessageBagMessages.php b/src/concerns/ZugferdMailConsoleOutputsMessageBagMessages.php index 056cf5c..2458e63 100644 --- a/src/concerns/ZugferdMailConsoleOutputsMessageBagMessages.php +++ b/src/concerns/ZugferdMailConsoleOutputsMessageBagMessages.php @@ -62,7 +62,7 @@ protected function outputMessagesFromMessageBagAsTableToCli(OutputInterface $out $messages = collect($this->getAllMessagesFromMessageBag()); $messages = $messages->map( - function (array $message, int $messageKey) use ($messages): array { + function ($message, int $messageKey) use ($messages) { $result = []; if ($message["message"] == "" || $message["message"] == "") { @@ -109,9 +109,9 @@ private function formatMessageBagMessage(array $message): string if ($message["type"] === ZugferdMailMessageBagType::MESSAGETYPE_ERROR) { if (isset($message["additionalData"]["errno"])) { return sprintf("%s in %s:%s", $messageText, $message["additionalData"]["errfile"], $message["additionalData"]["errline"]); + } else { + return sprintf("%s", $messageText); } - - return sprintf("%s", $messageText); } if ($message["type"] === ZugferdMailMessageBagType::MESSAGETYPE_SUCCESS) { diff --git a/src/concerns/ZugferdMailRaisesExceptions.php b/src/concerns/ZugferdMailRaisesExceptions.php index 66962df..5651377 100644 --- a/src/concerns/ZugferdMailRaisesExceptions.php +++ b/src/concerns/ZugferdMailRaisesExceptions.php @@ -33,7 +33,7 @@ trait ZugferdMailRaisesExceptions */ protected function raiseExceptionClassIf(bool $condidition, string $exceptionClass, string $message = ""): void { - if (!$condidition) { + if ($condidition !== true) { return; } diff --git a/src/concerns/ZugferdMailReceivesMessagesFromMessageBag.php b/src/concerns/ZugferdMailReceivesMessagesFromMessageBag.php index 9edd050..933eb82 100644 --- a/src/concerns/ZugferdMailReceivesMessagesFromMessageBag.php +++ b/src/concerns/ZugferdMailReceivesMessagesFromMessageBag.php @@ -52,7 +52,6 @@ public function hasLogMessagesInMessageBag(): bool { return ZugferdMailMessageBag::factory()->hasLogMessages(); } - /** * Returns an array of all log messages * diff --git a/src/concerns/ZugferdMailSendsMessagesToMessageBag.php b/src/concerns/ZugferdMailSendsMessagesToMessageBag.php index 70c84b5..c1ec99b 100644 --- a/src/concerns/ZugferdMailSendsMessagesToMessageBag.php +++ b/src/concerns/ZugferdMailSendsMessagesToMessageBag.php @@ -134,7 +134,7 @@ protected function addThrowableToMessageBag(Throwable $throwable, array $additio */ protected function addMessageToMessageBagIf(bool $condition, string $type, string $message, array $additionalData = []) { - return $condition ? $this->addMessageToMessageBag($type, $message, $additionalData) : $this; + return $condition === true ? $this->addMessageToMessageBag($type, $message, $additionalData) : $this; } /** @@ -147,7 +147,7 @@ protected function addMessageToMessageBagIf(bool $condition, string $type, strin */ protected function addLogMessageToMessageBagIf(bool $condition, string $message, array $additionalData = []) { - return $condition ? $this->addLogMessageToMessageBag($message, $additionalData) : $this; + return $condition === true ? $this->addLogMessageToMessageBag($message, $additionalData) : $this; } /** @@ -159,7 +159,7 @@ protected function addLogMessageToMessageBagIf(bool $condition, string $message, */ protected function addLogSecondaryMessageToMessageBagIf(bool $condition, string $message, array $additionalData = []) { - return $condition ? $this->addLogSecondaryMessageToMessageBag($message, $additionalData) : $this; + return $condition === true ? $this->addLogSecondaryMessageToMessageBag($message, $additionalData) : $this; } /** @@ -172,7 +172,7 @@ protected function addLogSecondaryMessageToMessageBagIf(bool $condition, string */ protected function addWarningMessageToMessageBagIf(bool $condition, string $message, array $additionalData = []) { - return $condition ? $this->addWarningMessageToMessageBag($message, $additionalData) : $this; + return $condition === true ? $this->addWarningMessageToMessageBag($message, $additionalData) : $this; } /** @@ -185,7 +185,7 @@ protected function addWarningMessageToMessageBagIf(bool $condition, string $mess */ protected function addErrorMessageToMessageBagIf(bool $condition, string $message, array $additionalData = []) { - return $condition ? $this->addErrorMessageToMessageBag($message, $additionalData) : $this; + return $condition === true ? $this->addErrorMessageToMessageBag($message, $additionalData) : $this; } /** @@ -198,7 +198,7 @@ protected function addErrorMessageToMessageBagIf(bool $condition, string $messag */ protected function addSuccessMessageToMessageBagIf(bool $condition, string $message, array $additionalData = []) { - return $condition ? $this->addSuccessMessageToMessageBag($message, $additionalData) : $this; + return $condition === true ? $this->addSuccessMessageToMessageBag($message, $additionalData) : $this; } /** @@ -211,7 +211,7 @@ protected function addSuccessMessageToMessageBagIf(bool $condition, string $mess */ protected function addThrowableToMessageBagIf(bool $condition, Throwable $throwable, array $additionalData = []) { - return $condition ? $this->addThrowableToMessageBag($throwable, $additionalData) : $this; + return $condition === true ? $this->addThrowableToMessageBag($throwable, $additionalData) : $this; } /** @@ -226,7 +226,7 @@ protected function addMultipleMessagesToMessageBag(string $type, array $messages { array_walk( $messages, - function ($message) use ($type, $additionalData): void { + function ($message) use ($type, $additionalData) { $this->addMessageToMessageBag($type, $message, $additionalData); } ); @@ -245,7 +245,7 @@ protected function addMultipleLogMessagesToMessageBag(array $messages, array $ad { array_walk( $messages, - function ($message) use ($additionalData): void { + function ($message) use ($additionalData) { $this->addLogMessageToMessageBag($message, $additionalData); } ); @@ -264,7 +264,7 @@ protected function addMultipleLogSecondaryMessagesToMessageBag(array $messages, { array_walk( $messages, - function ($message) use ($additionalData): void { + function ($message) use ($additionalData) { $this->addLogSecondaryMessageToMessageBag($message, $additionalData); } ); @@ -283,7 +283,7 @@ protected function addMultipleWarningMessagesToMessageBag(array $messages, array { array_walk( $messages, - function ($message) use ($additionalData): void { + function ($message) use ($additionalData) { $this->addWarningMessageToMessageBag($message, $additionalData); } ); @@ -302,7 +302,7 @@ protected function addMultipleErrorMessagesToMessageBag(array $messages, array $ { array_walk( $messages, - function ($message) use ($additionalData): void { + function ($message) use ($additionalData) { $this->addErrorMessageToMessageBag($message, $additionalData); } ); @@ -321,7 +321,7 @@ protected function addMultipleSuccessMessagesToMessageBag(array $messages, array { array_walk( $messages, - function ($message) use ($additionalData): void { + function ($message) use ($additionalData) { $this->addSuccessMessageToMessageBag($message, $additionalData); } ); @@ -340,7 +340,7 @@ function ($message) use ($additionalData): void { */ protected function addMultipleMessagesToMessageBagIf(bool $condition, string $type, array $messages, array $additionalData = []) { - return $condition ? $this->addMultipleMessagesToMessageBag($type, $messages, $additionalData) : $this; + return $condition === true ? $this->addMultipleMessagesToMessageBag($type, $messages, $additionalData) : $this; } /** @@ -353,7 +353,7 @@ protected function addMultipleMessagesToMessageBagIf(bool $condition, string $ty */ protected function addMultipleLogMessagesToMessageBagIf(bool $condition, array $messages, array $additionalData = []) { - return $condition ? $this->addMultipleLogMessagesToMessageBag($messages, $additionalData) : $this; + return $condition === true ? $this->addMultipleLogMessagesToMessageBag($messages, $additionalData) : $this; } /** @@ -366,7 +366,7 @@ protected function addMultipleLogMessagesToMessageBagIf(bool $condition, array $ */ protected function addMultipleLogSecondaryMessagesToMessageBagIf(bool $condition, array $messages, array $additionalData = []) { - return $condition ? $this->addMultipleLogSecondaryMessagesToMessageBag($messages, $additionalData) : $this; + return $condition === true ? $this->addMultipleLogSecondaryMessagesToMessageBag($messages, $additionalData) : $this; } /** @@ -379,7 +379,7 @@ protected function addMultipleLogSecondaryMessagesToMessageBagIf(bool $condition */ protected function addMultipleWarningMessagesToMessageBagIf(bool $condition, array $messages, array $additionalData = []) { - return $condition ? $this->addMultipleWarningMessagesToMessageBag($messages, $additionalData) : $this; + return $condition === true ? $this->addMultipleWarningMessagesToMessageBag($messages, $additionalData) : $this; } /** @@ -392,7 +392,7 @@ protected function addMultipleWarningMessagesToMessageBagIf(bool $condition, arr */ protected function addMultipleErrorMessagesToMessageBagIf(bool $condition, array $messages, array $additionalData = []) { - return $condition ? $this->addMultipleErrorMessagesToMessageBag($messages, $additionalData) : $this; + return $condition === true ? $this->addMultipleErrorMessagesToMessageBag($messages, $additionalData) : $this; } /** @@ -405,7 +405,7 @@ protected function addMultipleErrorMessagesToMessageBagIf(bool $condition, array */ protected function addMultipleSuccessMessagesToMessageBagIf(bool $condition, array $messages, array $additionalData = []) { - return $condition ? $this->addMultipleSuccessMessagesToMessageBag($messages, $additionalData) : $this; + return $condition === true ? $this->addMultipleSuccessMessagesToMessageBag($messages, $additionalData) : $this; } /** diff --git a/src/config/ZugferdMailAccount.php b/src/config/ZugferdMailAccount.php index 3ad9632..c010a71 100644 --- a/src/config/ZugferdMailAccount.php +++ b/src/config/ZugferdMailAccount.php @@ -155,7 +155,7 @@ public function getIdentifier(): string */ public function setIdentifier(string $identifier = ''): ZugferdMailAccount { - if (in_array(trim($identifier), ['', '0'], true)) { + if (empty(trim($identifier))) { $identifier = $this->createGuidForIdentifier(); } @@ -182,7 +182,7 @@ public function getHost(): string */ public function setHost(string $host): ZugferdMailAccount { - if ($host === '' || $host === '0') { + if (empty($host)) { throw new InvalidArgumentException("The host must not be empty"); } @@ -313,7 +313,7 @@ public function getUsername(): string */ public function setUsername(string $username): ZugferdMailAccount { - if ($username === '' || $username === '0') { + if (empty($username)) { throw new InvalidArgumentException("The username must be not empty"); } @@ -340,7 +340,7 @@ public function getPassword(): string */ public function setPassword(string $password): ZugferdMailAccount { - if ($password === '' || $password === '0') { + if (empty($password)) { throw new InvalidArgumentException("The password must be not empty"); } @@ -367,7 +367,7 @@ public function getAuthentication(): ?string */ public function setAuthentication(?string $authentication): ZugferdMailAccount { - if (!is_null($authentication) && $authentication !== "oauth") { + if (!is_null($authentication) && $authentication != "oauth") { throw new InvalidArgumentException("The authentication method must be one of null (NUL), oauth"); } @@ -434,7 +434,7 @@ public function setFoldersToWatch(array $folders): ZugferdMailAccount */ public function addFolderToWatch(string $folderPath): ZugferdMailAccount { - if ($folderPath === '' || $folderPath === '0') { + if (empty($folderPath)) { throw new InvalidArgumentException("Path must not be empty"); } @@ -474,7 +474,7 @@ public function setMimeTypesToWatch(array $mimeTypesToWatch): ZugferdMailAccount */ public function addMimeTypeToWatch(string $mimeTypesToWatch): ZugferdMailAccount { - if ($mimeTypesToWatch === '' || $mimeTypesToWatch === '0') { + if (empty($mimeTypesToWatch)) { throw new InvalidArgumentException("Mimetype must not be empty"); } @@ -506,12 +506,17 @@ public function getCallbacks(): array /** * Sets multiuple handlers to run when a document was found * - * @param array $handlers + * @param array $handlers * @return ZugferdMailAccount */ public function setHandlers(array $handlers): ZugferdMailAccount { - $this->handlers = $handlers; + $this->handlers = array_filter( + $handlers, + function ($handler) { + return $handler instanceof ZugferdMailHandlerAbstract; + } + ); return $this; } @@ -524,7 +529,12 @@ public function setHandlers(array $handlers): ZugferdMailAccount */ public function setCallbacks(array $callbacks): ZugferdMailAccount { - $this->callBacks = $callbacks; + $this->callBacks = array_filter( + $callbacks, + function ($callback) { + return is_callable($callback); + } + ); return $this; } diff --git a/src/config/ZugferdMailConfig.php b/src/config/ZugferdMailConfig.php index e2061e5..ff365a2 100644 --- a/src/config/ZugferdMailConfig.php +++ b/src/config/ZugferdMailConfig.php @@ -369,7 +369,7 @@ public function removeAccount(string $identifier): ZugferdMailConfig { $this->accounts = array_filter( $this->accounts, - function ($account) use ($identifier): bool { + function ($account) use ($identifier) { return strcasecmp($account->getIdentifier(), $identifier) != 0; } ); @@ -560,7 +560,7 @@ protected static function validateConfig($jsonObject): bool { $result = true; - $schemaJson = file_get_contents(__DIR__ . "/schema.json"); + $schemaJson = file_get_contents(dirname(__FILE__) . "/schema.json"); try { Schema::import( @@ -568,7 +568,7 @@ protected static function validateConfig($jsonObject): bool )->in( $jsonObject, ); - } catch (Throwable $throwable) { + } catch (Throwable $e) { $result = false; } diff --git a/src/console/ZugferdMailListFoldersConsoleCommand.php b/src/console/ZugferdMailListFoldersConsoleCommand.php index 1aaf67a..6b3672b 100644 --- a/src/console/ZugferdMailListFoldersConsoleCommand.php +++ b/src/console/ZugferdMailListFoldersConsoleCommand.php @@ -28,9 +28,10 @@ */ class ZugferdMailListFoldersConsoleCommand extends ZugferdMailBaseConsoleCommand { - use ZugferdMailConsoleHandlesConfigOptions; - use ZugferdMailConsoleHandlesMailAccountOptions; - use ZugferdMailConsoleOutputsMessageBagMessages; + use ZugferdMailConsoleHandlesConfigOptions, + ZugferdMailConsoleHandlesMailAccountOptions, + ZugferdMailConsoleOutputsMessageBagMessages; + /** * @inheritDoc */ @@ -59,7 +60,7 @@ protected function doExecute(): int $folders = $reader->getAllAvailableRootFolders(); $folders = array_map( - function (Folder $folder): array { + function (Folder $folder) { return [ $folder->full_name, count($folder->children), diff --git a/src/console/ZugferdMailProcessFoldersConsoleCommand.php b/src/console/ZugferdMailProcessFoldersConsoleCommand.php index d268da5..4406d78 100644 --- a/src/console/ZugferdMailProcessFoldersConsoleCommand.php +++ b/src/console/ZugferdMailProcessFoldersConsoleCommand.php @@ -26,9 +26,9 @@ */ class ZugferdMailProcessFoldersConsoleCommand extends ZugferdMailBaseConsoleCommand { - use ZugferdMailConsoleHandlesConfigOptions; - use ZugferdMailConsoleHandlesMailAccountOptions; - use ZugferdMailConsoleOutputsMessageBagMessages; + use ZugferdMailConsoleHandlesConfigOptions, + ZugferdMailConsoleHandlesMailAccountOptions, + ZugferdMailConsoleOutputsMessageBagMessages; /** * @inheritDoc diff --git a/src/handlers/ZugferdMailHandlerAbstract.php b/src/handlers/ZugferdMailHandlerAbstract.php index 094b65e..d952402 100644 --- a/src/handlers/ZugferdMailHandlerAbstract.php +++ b/src/handlers/ZugferdMailHandlerAbstract.php @@ -19,8 +19,9 @@ abstract class ZugferdMailHandlerAbstract { - use ZugferdMailSendsMessagesToMessageBag; - use ZugferdMailReceivesMessagesFromMessageBag; + use ZugferdMailSendsMessagesToMessageBag, + ZugferdMailReceivesMessagesFromMessageBag; + /** * The method will be call when a document was found. This method can perform * anything you want diff --git a/src/handlers/ZugferdMailHandlerCli.php b/src/handlers/ZugferdMailHandlerCli.php index ef5abc3..0f008d5 100644 --- a/src/handlers/ZugferdMailHandlerCli.php +++ b/src/handlers/ZugferdMailHandlerCli.php @@ -29,9 +29,9 @@ class ZugferdMailHandlerCli extends ZugferdMailHandlerAbstract /** * @inheritDoc */ - public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType): void + public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType) { - if (PHP_SAPI !== 'cli') { + if (php_sapi_name() !== 'cli') { return; } @@ -54,7 +54,7 @@ public function handleDocument(ZugferdMailAccount $account, Folder $folder, Mess $this->addLogMessageToMessageBag(sprintf(" - Document name %s", $documentname)); $this->addLogMessageToMessageBag(sprintf(" - Document language %s", $documentlanguage)); - if ($effectiveSpecifiedPeriod instanceof \DateTime) { + if ($effectiveSpecifiedPeriod) { $this->addLogMessageToMessageBag(sprintf(" - Period %s", $effectiveSpecifiedPeriod->format("d.m.Y"))); } } diff --git a/src/handlers/ZugferdMailHandlerCopyMessage.php b/src/handlers/ZugferdMailHandlerCopyMessage.php index c4be75e..8a5e579 100644 --- a/src/handlers/ZugferdMailHandlerCopyMessage.php +++ b/src/handlers/ZugferdMailHandlerCopyMessage.php @@ -51,16 +51,16 @@ public function __construct(string $copyToFolder) /** * @inheritDoc */ - public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType): void + public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType) { try { $copyToFolder = $this->parsePlaceholdersByZugferdDocumentReader($document, $this->getCopyToFolder()); $this->addLogMessageToMessageBag(sprintf('Copying mail to %s', $copyToFolder)); $message->copy($copyToFolder); $this->addLogMessageToMessageBag(sprintf('Successfully copied mail to %s', $copyToFolder)); - } catch (Throwable $throwable) { - $this->addErrorMessageToMessageBag(sprintf('Failed to copy mail: %s', $throwable->getMessage())); - throw $throwable; + } catch (Throwable $e) { + $this->addErrorMessageToMessageBag(sprintf('Failed to copy mail: %s', $e->getMessage())); + throw $e; } } @@ -82,7 +82,7 @@ public function getCopyToFolder(): string */ public function setCopyToFolder(string $copyToFolder): ZugferdMailHandlerCopyMessage { - if ($copyToFolder === '' || $copyToFolder === '0') { + if (empty($copyToFolder)) { throw new InvalidArgumentException("The destination folder must not be empty"); } diff --git a/src/handlers/ZugferdMailHandlerDeleteMessage.php b/src/handlers/ZugferdMailHandlerDeleteMessage.php index 4758738..1754b76 100644 --- a/src/handlers/ZugferdMailHandlerDeleteMessage.php +++ b/src/handlers/ZugferdMailHandlerDeleteMessage.php @@ -30,15 +30,15 @@ class ZugferdMailHandlerDeleteMessage extends ZugferdMailHandlerAbstract /** * @inheritDoc */ - public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType): void + public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType) { try { $this->addLogMessageToMessageBag(sprintf('Deleting message with %s', $message->getUid())); $message->delete(); $this->addLogMessageToMessageBag(sprintf('Successfully deleted message with %s', $message->getUid())); - } catch (Throwable $throwable) { - $this->addErrorMessageToMessageBag(sprintf('Failed to delete message with id %s: %s', $message->getUid(), $throwable->getMessage())); - throw $throwable; + } catch (Throwable $e) { + $this->addErrorMessageToMessageBag(sprintf('Failed to delete message with id %s: %s', $message->getUid(), $e->getMessage())); + throw $e; } } } diff --git a/src/handlers/ZugferdMailHandlerMarkSeenMessage.php b/src/handlers/ZugferdMailHandlerMarkSeenMessage.php index 8fb2ae7..59ecc1f 100644 --- a/src/handlers/ZugferdMailHandlerMarkSeenMessage.php +++ b/src/handlers/ZugferdMailHandlerMarkSeenMessage.php @@ -30,15 +30,15 @@ class ZugferdMailHandlerMarkSeenMessage extends ZugferdMailHandlerAbstract /** * @inheritDoc */ - public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType): void + public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType) { try { $this->addLogMessageToMessageBag(sprintf('Marking mail %s as seen', $message->getUid())); $message->setFlag('Seen'); $this->addLogMessageToMessageBag(sprintf('Successfully marked mail %s as seen', $message->getUid())); - } catch (Throwable $throwable) { - $this->addErrorMessageToMessageBag(sprintf('Failed to mark mail as seen: %s', $throwable->getMessage())); - throw $throwable; + } catch (Throwable $e) { + $this->addErrorMessageToMessageBag(sprintf('Failed to mark mail as seen: %s', $e->getMessage())); + throw $e; } } } diff --git a/src/handlers/ZugferdMailHandlerMarkUnseenMessage.php b/src/handlers/ZugferdMailHandlerMarkUnseenMessage.php index 4b23318..b5b6dfd 100644 --- a/src/handlers/ZugferdMailHandlerMarkUnseenMessage.php +++ b/src/handlers/ZugferdMailHandlerMarkUnseenMessage.php @@ -30,15 +30,15 @@ class ZugferdMailHandlerMarkUnseenMessage extends ZugferdMailHandlerAbstract /** * @inheritDoc */ - public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType): void + public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType) { try { $this->addLogMessageToMessageBag(sprintf('Marking mail %s as unseen', $message->getUid())); $message->removeFlag('Seen'); $this->addLogMessageToMessageBag(sprintf('Successfully marked mail %s as unseen', $message->getUid())); - } catch (Throwable $throwable) { - $this->addErrorMessageToMessageBag(sprintf('Failed to mark mail as unseen: %s', $throwable->getMessage())); - throw $throwable; + } catch (Throwable $e) { + $this->addErrorMessageToMessageBag(sprintf('Failed to mark mail as unseen: %s', $e->getMessage())); + throw $e; } } } diff --git a/src/handlers/ZugferdMailHandlerMoveMessage.php b/src/handlers/ZugferdMailHandlerMoveMessage.php index 5b34588..469e34a 100644 --- a/src/handlers/ZugferdMailHandlerMoveMessage.php +++ b/src/handlers/ZugferdMailHandlerMoveMessage.php @@ -51,16 +51,16 @@ public function __construct(string $moveToFolder) /** * @inheritDoc */ - public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType): void + public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType) { try { $moveToFolder = $this->parsePlaceholdersByZugferdDocumentReader($document, $this->getMoveToFolder()); $this->addLogMessageToMessageBag(sprintf('Moving mail to %s', $moveToFolder)); $message->move($moveToFolder); $this->addLogMessageToMessageBag(sprintf('Successfully moved mail to %s', $moveToFolder)); - } catch (Throwable $throwable) { - $this->addErrorMessageToMessageBag(sprintf('Failed to move mail: %s', $throwable->getMessage())); - throw $throwable; + } catch (Throwable $e) { + $this->addErrorMessageToMessageBag(sprintf('Failed to move mail: %s', $e->getMessage())); + throw $e; } } @@ -82,7 +82,7 @@ public function getMoveToFolder(): string */ public function setMoveToFolder(string $moveToFolder): ZugferdMailHandlerMoveMessage { - if ($moveToFolder === '' || $moveToFolder === '0') { + if (empty($moveToFolder)) { throw new InvalidArgumentException("The destination folder must not be empty"); } diff --git a/src/handlers/ZugferdMailHandlerNull.php b/src/handlers/ZugferdMailHandlerNull.php index d9ad735..515a979 100644 --- a/src/handlers/ZugferdMailHandlerNull.php +++ b/src/handlers/ZugferdMailHandlerNull.php @@ -29,7 +29,7 @@ class ZugferdMailHandlerNull extends ZugferdMailHandlerAbstract /** * @inheritDoc */ - public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType): void + public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType) { // Do nothing here... } diff --git a/src/handlers/ZugferdMailHandlerSaveToFile.php b/src/handlers/ZugferdMailHandlerSaveToFile.php index f01a969..9fe4dd7 100644 --- a/src/handlers/ZugferdMailHandlerSaveToFile.php +++ b/src/handlers/ZugferdMailHandlerSaveToFile.php @@ -68,16 +68,16 @@ public function __construct(string $filePath, string $filename) /** * @inheritDoc */ - public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType): void + public function handleDocument(ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType) { try { $finalFilename = $this->buildFileNameFrom($document, $attachment); $this->addLogMessageToMessageBag(sprintf('Saving attachment to %s%s', $this->getFilePath(), $finalFilename)); $attachment->save($this->getFilePath(), $finalFilename); $this->addLogMessageToMessageBag(sprintf('Successfully saved attachment to %s%s', $this->getFilePath(), $finalFilename)); - } catch (Throwable $throwable) { - $this->addErrorMessageToMessageBag(sprintf('Failed to save attachment: %s', $throwable->getMessage())); - throw $throwable; + } catch (Throwable $e) { + $this->addErrorMessageToMessageBag(sprintf('Failed to save attachment: %s', $e->getMessage())); + throw $e; } } @@ -158,7 +158,7 @@ private function buildFileNameFrom(ZugferdDocumentReader $document, Attachment $ $parsedFilename = preg_replace('/_+/', '_', $parsedFilename); - $parsedFilename = $fileExtension !== '' && $fileExtension !== '0' ? FileUtils::combineFilenameWithFileextension($parsedFilename, $fileExtension) : $parsedFilename; + $parsedFilename = $fileExtension ? FileUtils::combineFilenameWithFileextension($parsedFilename, $fileExtension) : $parsedFilename; return $parsedFilename; } diff --git a/src/helpers/ZugferdMailPlaceholderHelper.php b/src/helpers/ZugferdMailPlaceholderHelper.php index fde4da0..94c099b 100644 --- a/src/helpers/ZugferdMailPlaceholderHelper.php +++ b/src/helpers/ZugferdMailPlaceholderHelper.php @@ -102,7 +102,7 @@ public static function fromZugferdDocumentReader(ZugferdDocumentReader $document */ public function addPlaceholder(string $placeholderName, $placeHolderValue): ZugferdMailPlaceholderHelper { - if ($placeholderName === '' || $placeholderName === '0' || empty($placeHolderValue)) { + if (empty($placeholderName) || empty($placeHolderValue)) { return $this; } @@ -118,7 +118,6 @@ public function addPlaceholder(string $placeholderName, $placeHolderValue): Zugf foreach ($placeHolderValue as $placeHolderValueKey => $placeHolderValueData) { $this->addPlaceholder(sprintf("%s_%s", $placeholderName, $placeHolderValueKey), $placeHolderValueData); } - break; default: break; @@ -137,9 +136,9 @@ public function parseString(string $subject): string { return preg_replace_callback( '/\{(\w+)\}/', - function (array $placeholderMatch) { + function ($placeholderMatch) { $placeHolderName = $placeholderMatch[1]; - $placeHolderValhe = $this->mappingTable[$placeHolderName] ?? ""; + $placeHolderValhe = isset($this->mappingTable[$placeHolderName]) ? $this->mappingTable[$placeHolderName] : ""; return $placeHolderValhe; }, $subject diff --git a/tests/TestCase.php b/tests/TestCase.php index 2daaa6e..b831e08 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -37,7 +37,7 @@ public static function setUpBeforeClass(): void public static function tearDownAfterClass(): void { foreach (self::$registeredTestCaseFiles as $registeredTestCaseFile) { - if (file_exists($registeredTestCaseFile) && is_writable($registeredTestCaseFile)) { + if (file_exists($registeredTestCaseFile) && is_writeable($registeredTestCaseFile)) { @unlink($registeredTestCaseFile); } } @@ -63,7 +63,7 @@ protected function tearDown(): void parent::tearDown(); foreach ($this->registeredTestFiles as $registeredTestFile) { - if (file_exists($registeredTestFile) && is_writable($registeredTestFile)) { + if (file_exists($registeredTestFile) && is_writeable($registeredTestFile)) { @unlink($registeredTestFile); } } diff --git a/tests/testcases/BasicTest.php b/tests/testcases/BasicTest.php new file mode 100644 index 0000000..2e99fd0 --- /dev/null +++ b/tests/testcases/BasicTest.php @@ -0,0 +1,13 @@ +assertTrue(true); + } +} diff --git a/tests/testcases/BuiltinHandlersTest.php b/tests/testcases/BuiltinHandlersTest.php index 9a8ce95..77a5297 100644 --- a/tests/testcases/BuiltinHandlersTest.php +++ b/tests/testcases/BuiltinHandlersTest.php @@ -4,11 +4,20 @@ use InvalidArgumentException; use horstoeko\zugferdmail\tests\TestCase; +use horstoeko\zugferdmail\handlers\ZugferdMailHandlerCli; use horstoeko\zugferdmail\handlers\ZugferdMailHandlerCopyMessage; use horstoeko\zugferdmail\handlers\ZugferdMailHandlerMoveMessage; +use horstoeko\zugferdmail\handlers\ZugferdMailHandlerDeleteMessage; class BuiltinHandlersTest extends TestCase { + public function testCreateBuiltInHandlerCli(): void + { + $handler = new ZugferdMailHandlerCli(); + + $this->assertTrue(true, 'No exception should be raised'); + } + public function testCreateBuiltInHandlerCopyMessageWithEmptyFolder(): void { $this->expectException(InvalidArgumentException::class); @@ -17,6 +26,13 @@ public function testCreateBuiltInHandlerCopyMessageWithEmptyFolder(): void $handler = new ZugferdMailHandlerCopyMessage(''); } + public function testCreateBuiltInHandlerCopyMessageWithFolder(): void + { + $handler = new ZugferdMailHandlerCopyMessage('INBOX.read'); + + $this->assertTrue(true, 'No exception should be raised'); + } + public function testCreateBuiltInHandlerMoveMessageWithEmptyFolder(): void { $this->expectException(InvalidArgumentException::class); @@ -24,4 +40,18 @@ public function testCreateBuiltInHandlerMoveMessageWithEmptyFolder(): void $handler = new ZugferdMailHandlerMoveMessage(''); } + + public function testCreateBuiltInHandlerMoveMessageWithFolder(): void + { + $handler = new ZugferdMailHandlerMoveMessage('INBOX.read'); + + $this->assertTrue(true, 'No exception should be raised'); + } + + public function testCreateBuiltInHandlerDeleteMessage(): void + { + $handler = new ZugferdMailHandlerDeleteMessage(); + + $this->assertTrue(true, 'No exception should be raised'); + } } diff --git a/tests/testcases/ZugferdMailAccountTest.php b/tests/testcases/ZugferdMailAccountTest.php index 0f0a174..a346f40 100644 --- a/tests/testcases/ZugferdMailAccountTest.php +++ b/tests/testcases/ZugferdMailAccountTest.php @@ -16,17 +16,18 @@ public function testMailAccountInit(): void { $mailAccount = new ZugferdMailAccount(); + $this->assertNotNull($mailAccount); $this->assertNotEmpty($mailAccount->getIdentifier()); - $this->assertMatchesRegularExpression("/^(\{)?[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}(?(1)\})$/i", $mailAccount->getIdentifier()); - $this->assertSame("", $mailAccount->getHost()); - $this->assertSame(0, $mailAccount->getPort()); - $this->assertSame("imap", $mailAccount->getProtocol()); + $this->assertTrue(preg_match("/^(\{)?[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}(?(1)\})$/i", $mailAccount->getIdentifier()) === 1); + $this->assertEquals("", $mailAccount->getHost()); + $this->assertEquals(0, $mailAccount->getPort()); + $this->assertEquals("imap", $mailAccount->getProtocol()); $this->assertEquals("ssl", $mailAccount->getEncryption()); $this->assertEquals(true, $mailAccount->getValidateCert()); - $this->assertSame("", $mailAccount->getUsername()); - $this->assertSame("", $mailAccount->getPassword()); + $this->assertEquals("", $mailAccount->getUsername()); + $this->assertEquals("", $mailAccount->getPassword()); $this->assertNull($mailAccount->getAuthentication()); - $this->assertSame(30, $mailAccount->getTimeout()); + $this->assertEquals(30, $mailAccount->getTimeout()); $this->assertEmpty($mailAccount->getFoldersTowatch()); $this->assertEmpty($mailAccount->getMimeTypesToWatch()); $this->assertEmpty($mailAccount->getHandlers()); @@ -39,7 +40,7 @@ public function testMailAccountSetIdInvalid(): void $mailAccount = new ZugferdMailAccount(); $mailAccount->setIdentifier(""); - $this->assertMatchesRegularExpression("/^(\{)?[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}(?(1)\})$/i", $mailAccount->getIdentifier()); + $this->assertEquals(1, preg_match("/^(\{)?[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}(?(1)\})$/i", $mailAccount->getIdentifier())); } public function testMailAccountSetIdValid(): void @@ -47,7 +48,7 @@ public function testMailAccountSetIdValid(): void $mailAccount = new ZugferdMailAccount(); $mailAccount->setIdentifier("id"); - $this->assertSame("id", $mailAccount->getIdentifier()); + $this->assertEquals("id", $mailAccount->getIdentifier()); } public function testMailAccountSetHostInvalid(): void @@ -63,7 +64,7 @@ public function testMailAccountSetHostValid(): void $mailAccount = new ZugferdMailAccount(); $mailAccount->setHost("127.0.0.1"); - $this->assertSame("127.0.0.1", $mailAccount->getHost()); + $this->assertEquals("127.0.0.1", $mailAccount->getHost()); } public function testMailAccountSetPortInvalid(): void @@ -79,13 +80,13 @@ public function testMailAccountSetPortValid(): void $mailAccount = new ZugferdMailAccount(); $mailAccount->setPort(25); - $this->assertSame(25, $mailAccount->getPort()); + $this->assertEquals(25, $mailAccount->getPort()); } public function testMailAccountSetProtocolInvalid(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The protocol must be one of imap, legacy-imap, pop3 or nntp, unknown given"); + $this->expectExceptionMessage(sprintf("The protocol must be one of imap, legacy-imap, pop3 or nntp, unknown given")); $mailAccount = new ZugferdMailAccount(); $mailAccount->setProtocol("unknown"); @@ -96,7 +97,7 @@ public function testMailAccountSetProtocolValid(): void $mailAccount = new ZugferdMailAccount(); $mailAccount->setProtocol("pop3"); - $this->assertSame("pop3", $mailAccount->getProtocol()); + $this->assertEquals("pop3", $mailAccount->getProtocol()); } public function testMailAccountSetEncryptionInvalid(): void @@ -136,7 +137,7 @@ public function testMailAccountSetUsernameValid(): void $mailAccount = new ZugferdMailAccount(); $mailAccount->setUsername("demouser"); - $this->assertSame("demouser", $mailAccount->getUsername()); + $this->assertEquals("demouser", $mailAccount->getUsername()); } public function testMailAccountSetPasswordInvalid(): void @@ -152,7 +153,7 @@ public function testMailAccountSetPasswordValid(): void $mailAccount = new ZugferdMailAccount(); $mailAccount->setPassword("demopwd"); - $this->assertSame("demopwd", $mailAccount->getPassword()); + $this->assertEquals("demopwd", $mailAccount->getPassword()); } public function testMailAccountSetAuthenticationInvalid(): void @@ -168,7 +169,7 @@ public function testMailAccountSetAuthenticationValid(): void $mailAccount = new ZugferdMailAccount(); $mailAccount->setAuthentication("oauth"); - $this->assertSame("oauth", $mailAccount->getAuthentication()); + $this->assertEquals("oauth", $mailAccount->getAuthentication()); } public function testMailAccountSetTimeoutInvalid(): void @@ -184,7 +185,7 @@ public function testMailAccountSetTimeoutValid(): void $mailAccount = new ZugferdMailAccount(); $mailAccount->setTimeout(60); - $this->assertSame(60, $mailAccount->getTimeout()); + $this->assertEquals(60, $mailAccount->getTimeout()); } public function testMailAccountSetFoldersToWatchEmptyArray(): void @@ -192,6 +193,7 @@ public function testMailAccountSetFoldersToWatchEmptyArray(): void $mailAccount = new ZugferdMailAccount(); $mailAccount->setFoldersToWatch(['', '']); + $this->assertIsArray($mailAccount->getFoldersTowatch()); $this->assertEmpty($mailAccount->getFoldersTowatch()); } @@ -203,7 +205,7 @@ public function testMailAccountSetFoldersToWatchOneEmptyArray(): void $this->assertNotEmpty($mailAccount->getFoldersTowatch()); $this->assertArrayNotHasKey(0, $mailAccount->getFoldersTowatch()); $this->assertArrayHasKey(1, $mailAccount->getFoldersTowatch()); - $this->assertSame('INBOX', $mailAccount->getFoldersTowatch()[1]); + $this->assertEquals('INBOX', $mailAccount->getFoldersTowatch()[1]); } public function testMailAccountSetFoldersToWatchAllNotEmptyArray(): void @@ -215,8 +217,8 @@ public function testMailAccountSetFoldersToWatchAllNotEmptyArray(): void $this->assertArrayHasKey(0, $mailAccount->getFoldersTowatch()); $this->assertArrayHasKey(1, $mailAccount->getFoldersTowatch()); $this->assertArrayNotHasKey(2, $mailAccount->getFoldersTowatch()); - $this->assertSame('SOMEFOLDER', $mailAccount->getFoldersTowatch()[0]); - $this->assertSame('INBOX', $mailAccount->getFoldersTowatch()[1]); + $this->assertEquals('SOMEFOLDER', $mailAccount->getFoldersTowatch()[0]); + $this->assertEquals('INBOX', $mailAccount->getFoldersTowatch()[1]); } public function testMailAccountAddFoldersToWatchEmpty(): void @@ -250,6 +252,7 @@ public function testMailAccountSetMimeTypesToWatchEmptyArray(): void $mailAccount = new ZugferdMailAccount(); $mailAccount->setMimeTypesToWatch(['', '']); + $this->assertIsArray($mailAccount->getMimeTypesToWatch()); $this->assertEmpty($mailAccount->getMimeTypesToWatch()); } @@ -261,7 +264,7 @@ public function testMailAccountSetMimeTypesToWatchOneEmptyArray(): void $this->assertNotEmpty($mailAccount->getMimeTypesToWatch()); $this->assertArrayNotHasKey(0, $mailAccount->getMimeTypesToWatch()); $this->assertArrayHasKey(1, $mailAccount->getMimeTypesToWatch()); - $this->assertSame('text/xml', $mailAccount->getMimeTypesToWatch()[1]); + $this->assertEquals('text/xml', $mailAccount->getMimeTypesToWatch()[1]); } public function testMailAccountSetMimeTypesToWatchAllNotEmptyArray(): void @@ -273,8 +276,8 @@ public function testMailAccountSetMimeTypesToWatchAllNotEmptyArray(): void $this->assertArrayHasKey(0, $mailAccount->getMimeTypesToWatch()); $this->assertArrayHasKey(1, $mailAccount->getMimeTypesToWatch()); $this->assertArrayNotHasKey(2, $mailAccount->getMimeTypesToWatch()); - $this->assertSame('application/pdf', $mailAccount->getMimeTypesToWatch()[0]); - $this->assertSame('text/xml', $mailAccount->getMimeTypesToWatch()[1]); + $this->assertEquals('application/pdf', $mailAccount->getMimeTypesToWatch()[0]); + $this->assertEquals('text/xml', $mailAccount->getMimeTypesToWatch()[1]); } public function testMailAccountAddMimeTypesToWatchEmpty(): void @@ -303,6 +306,16 @@ public function testMailAccountAddMimeTypesToWatchNotEmpty(): void $this->assertEquals('text/xml', $mailAccount->getMimeTypesToWatch()[1]); } + public function testMailAccountSetHandlersOneInvalid(): void + { + $mailAccount = new ZugferdMailAccount(); + $mailAccount->setHandlers([new ZugferdMailMessageBagType(), new ZugferdMailHandlerNull()]); + + $this->assertArrayNotHasKey(0, $mailAccount->getHandlers()); + $this->assertArrayHasKey(1, $mailAccount->getHandlers()); + $this->assertInstanceOf(ZugferdMailHandlerNull::class, $mailAccount->getHandlers()[1]); + } + public function testMailAccountSetHandlersAllValid(): void { $mailAccount = new ZugferdMailAccount(); @@ -336,7 +349,7 @@ public function testMailAccountSetCallbacksOneInvalid(): void { $mailAccount = new ZugferdMailAccount(); $mailAccount->setCallbacks( - [function (): void { + [null, function () { }] ); @@ -349,8 +362,8 @@ public function testMailAccountSetCallbacksAllValid(): void { $mailAccount = new ZugferdMailAccount(); $mailAccount->setCallbacks( - [function (): void { - }, function (): void { + [function () { + }, function () { }] ); @@ -364,7 +377,7 @@ public function testMailAccountAddCallbacks(): void { $mailAccount = new ZugferdMailAccount(); $mailAccount->addCallback( - function (): void { + function () { } ); @@ -373,7 +386,7 @@ function (): void { $this->assertInstanceOf(Closure::class, $mailAccount->getCallbacks()[0]); $mailAccount->addCallback( - function (): void { + function () { } ); @@ -418,6 +431,7 @@ public function testGetMailAccountDefinition(): void $mailAccountDefinition = $mailAccount->getAccountDefinition(); + $this->assertIsArray($mailAccountDefinition); $this->assertArrayHasKey("host", $mailAccountDefinition); $this->assertArrayHasKey("port", $mailAccountDefinition); $this->assertArrayHasKey("protocol", $mailAccountDefinition); diff --git a/tests/testcases/ZugferdMailConcernConsoleHandlesConfigOptionsTest.php b/tests/testcases/ZugferdMailConcernConsoleHandlesConfigOptionsTest.php index 533c62c..b38e814 100644 --- a/tests/testcases/ZugferdMailConcernConsoleHandlesConfigOptionsTest.php +++ b/tests/testcases/ZugferdMailConcernConsoleHandlesConfigOptionsTest.php @@ -29,7 +29,7 @@ class ZugferdMailConcernConsoleHandlesConfigOptionsTest extends TestCase * @param mixed $default * @return static */ - protected function addOption(string $name, $shortcut = null, ?int $mode = null, string $description = '', $default = null): self + protected function addOption(string $name, $shortcut = null, ?int $mode = null, string $description = '', $default = null) { $this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default)); diff --git a/tests/testcases/ZugferdMailConcernConsoleHandlesMailAccountOptionsTest.php b/tests/testcases/ZugferdMailConcernConsoleHandlesMailAccountOptionsTest.php index f41d742..479708c 100644 --- a/tests/testcases/ZugferdMailConcernConsoleHandlesMailAccountOptionsTest.php +++ b/tests/testcases/ZugferdMailConcernConsoleHandlesMailAccountOptionsTest.php @@ -33,7 +33,7 @@ class ZugferdMailConcernConsoleHandlesMailAccountOptionsTest extends TestCase * @param mixed $default * @return static */ - protected function addOption(string $name, $shortcut = null, ?int $mode = null, string $description = '', $default = null): self + protected function addOption(string $name, $shortcut = null, ?int $mode = null, string $description = '', $default = null) { $this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default)); @@ -153,23 +153,26 @@ public function testCreateMailAccountFromOptionsNoWatches(): void $account = $this->createMailAccountFromOptions($arrayInput); - $this->assertSame('127.0.0.1', $account->getHost()); - $this->assertSame(993, $account->getPort()); - $this->assertSame('pop3', $account->getProtocol()); + $this->assertEquals('127.0.0.1', $account->getHost()); + $this->assertEquals('993', $account->getPort()); + $this->assertEquals('pop3', $account->getProtocol()); $this->assertEquals('tls', $account->getEncryption()); $this->assertTrue($account->getValidateCert()); - $this->assertSame('demouser', $account->getUsername()); - $this->assertSame('demopassword', $account->getPassword()); - $this->assertSame('oauth', $account->getAuthentication()); - $this->assertSame(60, $account->getTimeout()); + $this->assertEquals('demouser', $account->getUsername()); + $this->assertEquals('demopassword', $account->getPassword()); + $this->assertEquals('oauth', $account->getAuthentication()); + $this->assertEquals(60, $account->getTimeout()); $this->assertTrue($arrayInput->getOption('enableunseenonly')); + $this->assertIsArray($account->getFoldersTowatch()); $this->assertEmpty($account->getFoldersTowatch()); $this->assertCount(0, $account->getFoldersTowatch()); + $this->assertIsArray($account->getMimeTypesToWatch()); $this->assertEmpty($account->getMimeTypesToWatch()); $this->assertCount(0, $account->getMimeTypesToWatch()); + $this->assertIsArray($account->getHandlers()); $this->assertEmpty($account->getHandlers()); $this->assertCount(0, $account->getHandlers()); } @@ -200,23 +203,26 @@ public function testCreateMailAccountFromOptionsWithWatches(): void $account = $this->createMailAccountFromOptions($arrayInput); - $this->assertSame('127.0.0.1', $account->getHost()); - $this->assertSame(993, $account->getPort()); - $this->assertSame('pop3', $account->getProtocol()); + $this->assertEquals('127.0.0.1', $account->getHost()); + $this->assertEquals('993', $account->getPort()); + $this->assertEquals('pop3', $account->getProtocol()); $this->assertEquals('tls', $account->getEncryption()); $this->assertTrue($account->getValidateCert()); - $this->assertSame('demouser', $account->getUsername()); - $this->assertSame('demopassword', $account->getPassword()); - $this->assertSame('oauth', $account->getAuthentication()); - $this->assertSame(60, $account->getTimeout()); + $this->assertEquals('demouser', $account->getUsername()); + $this->assertEquals('demopassword', $account->getPassword()); + $this->assertEquals('oauth', $account->getAuthentication()); + $this->assertEquals(60, $account->getTimeout()); $this->assertTrue($arrayInput->getOption('enableunseenonly')); + $this->assertIsArray($account->getFoldersTowatch()); $this->assertNotEmpty($account->getFoldersTowatch()); $this->assertCount(2, $account->getFoldersTowatch()); + $this->assertIsArray($account->getMimeTypesToWatch()); $this->assertNotEmpty($account->getMimeTypesToWatch()); $this->assertCount(2, $account->getMimeTypesToWatch()); + $this->assertIsArray($account->getHandlers()); $this->assertNotEmpty($account->getHandlers()); $this->assertCount(2, $account->getHandlers()); } @@ -256,6 +262,7 @@ public function testWriteAccountInformation(): void $outputs = $testOutputInterface->getOutputs(); + $this->assertIsArray($outputs); $this->assertNotEmpty($outputs); $this->assertCount(5, $outputs); @@ -301,6 +308,7 @@ public function testWriteAccountFoldersToWatch(): void $outputs = $testOutputInterface->getOutputs(); + $this->assertIsArray($outputs); $this->assertNotEmpty($outputs); $this->assertCount(6, $outputs); @@ -347,6 +355,7 @@ public function testWriteAccountMimeTypesToWatch(): void $outputs = $testOutputInterface->getOutputs(); + $this->assertIsArray($outputs); $this->assertNotEmpty($outputs); $this->assertCount(6, $outputs); diff --git a/tests/testcases/ZugferdMailConcernConsoleOutputsMessageBagMessagesTest.php b/tests/testcases/ZugferdMailConcernConsoleOutputsMessageBagMessagesTest.php index c099ddc..8b8c36f 100644 --- a/tests/testcases/ZugferdMailConcernConsoleOutputsMessageBagMessagesTest.php +++ b/tests/testcases/ZugferdMailConcernConsoleOutputsMessageBagMessagesTest.php @@ -12,12 +12,12 @@ class ZugferdMailConcernConsoleOutputsMessageBagMessagesTest extends TestCase { - use ZugferdMailConsoleOutputsMessageBagMessages; - use ZugferdMailClearsMessageBag; - use ZugferdMailReceivesMessagesFromMessageBag; - use ZugferdMailSendsMessagesToMessageBag; + use ZugferdMailConsoleOutputsMessageBagMessages, + ZugferdMailClearsMessageBag, + ZugferdMailReceivesMessagesFromMessageBag, + ZugferdMailSendsMessagesToMessageBag; - public function testOutputMessagesFromMessageBagToCli(): void + public function testOutputMessagesFromMessageBagToCli() { $outputFormatter = new OutputFormatter(); $testOutputInterface = new TestOutputInterface; @@ -33,6 +33,7 @@ public function testOutputMessagesFromMessageBagToCli(): void $outputs = $testOutputInterface->getOutputs(); + $this->assertIsArray($outputs); $this->assertNotEmpty($outputs); $this->assertCount(1, $outputs); $this->assertEquals("Message 1", $outputs[0]); @@ -45,6 +46,7 @@ public function testOutputMessagesFromMessageBagToCli(): void $outputs = $testOutputInterface->getOutputs(); + $this->assertIsArray($outputs); $this->assertNotEmpty($outputs); $this->assertCount(2, $outputs); $this->assertEquals("Message 1", $outputs[0]); @@ -58,6 +60,7 @@ public function testOutputMessagesFromMessageBagToCli(): void $outputs = $testOutputInterface->getOutputs(); + $this->assertIsArray($outputs); $this->assertNotEmpty($outputs); $this->assertCount(3, $outputs); $this->assertEquals("Message 1", $outputs[0]); @@ -72,6 +75,7 @@ public function testOutputMessagesFromMessageBagToCli(): void $outputs = $testOutputInterface->getOutputs(); + $this->assertIsArray($outputs); $this->assertNotEmpty($outputs); $this->assertCount(4, $outputs); $this->assertEquals("Message 1", $outputs[0]); @@ -87,6 +91,7 @@ public function testOutputMessagesFromMessageBagToCli(): void $outputs = $testOutputInterface->getOutputs(); + $this->assertIsArray($outputs); $this->assertNotEmpty($outputs); $this->assertCount(5, $outputs); $this->assertEquals("Message 1", $outputs[0]); @@ -103,6 +108,7 @@ public function testOutputMessagesFromMessageBagToCli(): void $outputs = $testOutputInterface->getOutputs(); + $this->assertIsArray($outputs); $this->assertNotEmpty($outputs); $this->assertCount(6, $outputs); $this->assertEquals("Message 1", $outputs[0]); @@ -122,11 +128,12 @@ public function testOutputMessagesFromMessageBagToCli(): void $outputs = $testOutputInterface->getOutputs(); + $this->assertIsArray($outputs); $this->assertEmpty($outputs); $this->assertCount(0, $outputs); } - public function testOutputMessagesFromMessageBagAsTableToCli(): void + public function testOutputMessagesFromMessageBagAsTableToCli() { $outputFormatter = new OutputFormatter(); $testOutputInterface = new TestOutputInterface; @@ -138,6 +145,7 @@ public function testOutputMessagesFromMessageBagAsTableToCli(): void $outputs = $testOutputInterface->getOutputs(); + $this->assertIsArray($outputs); $this->assertEmpty($outputs); $this->assertCount(0, $outputs); @@ -151,6 +159,7 @@ public function testOutputMessagesFromMessageBagAsTableToCli(): void $outputs = $testOutputInterface->getOutputs(); + $this->assertIsArray($outputs); $this->assertNotEmpty($outputs); $this->assertCount(7, $outputs); $this->assertEquals("┌─────────────────────┬───────────┬────────────────────────────────────────────────────────┐", $outputs[0]); diff --git a/tests/testcases/ZugferdMailConcernMessageBagTest.php b/tests/testcases/ZugferdMailConcernMessageBagTest.php index 57be0cd..93f3740 100644 --- a/tests/testcases/ZugferdMailConcernMessageBagTest.php +++ b/tests/testcases/ZugferdMailConcernMessageBagTest.php @@ -11,9 +11,9 @@ class ZugferdMailConcernMessageBagTest extends TestCase { - use ZugferdMailClearsMessageBag; - use ZugferdMailReceivesMessagesFromMessageBag; - use ZugferdMailSendsMessagesToMessageBag; + use ZugferdMailClearsMessageBag, + ZugferdMailReceivesMessagesFromMessageBag, + ZugferdMailSendsMessagesToMessageBag; public function testInitialMessageBag(): void { @@ -68,13 +68,13 @@ public function testAddLogMessageToMessageBag(): void $this->assertEmpty($this->getErrorMessagesFromMessageBag()); $this->assertEmpty($this->getSuccessMessagesFromMessageBag()); - $this->assertCount(1, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); + $this->assertEquals(1, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); - $this->assertCount(1, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(1, count($this->getAllMessagesFromMessageBag())); $this->assertTrue($this->getHasAnyMessageInMessageBag()); @@ -121,13 +121,13 @@ public function testAddSecondaryLogMessageToMessageBag(): void $this->assertEmpty($this->getErrorMessagesFromMessageBag()); $this->assertEmpty($this->getSuccessMessagesFromMessageBag()); - $this->assertCount(1, $this->getLogMessagesFromMessageBag()); - $this->assertCount(1, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); + $this->assertEquals(1, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); - $this->assertCount(2, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(2, count($this->getAllMessagesFromMessageBag())); $this->assertTrue($this->getHasAnyMessageInMessageBag()); @@ -174,13 +174,13 @@ public function testAddWarningMessageToMessageBag(): void $this->assertEmpty($this->getErrorMessagesFromMessageBag()); $this->assertEmpty($this->getSuccessMessagesFromMessageBag()); - $this->assertCount(1, $this->getLogMessagesFromMessageBag()); - $this->assertCount(1, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(1, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); + $this->assertEquals(1, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); - $this->assertCount(3, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(3, count($this->getAllMessagesFromMessageBag())); $this->assertTrue($this->getHasAnyMessageInMessageBag()); @@ -227,13 +227,13 @@ public function testAddErrorMessageToMessageBag(): void $this->assertNotEmpty($this->getErrorMessagesFromMessageBag()); $this->assertEmpty($this->getSuccessMessagesFromMessageBag()); - $this->assertCount(1, $this->getLogMessagesFromMessageBag()); - $this->assertCount(1, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(1, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(1, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); + $this->assertEquals(1, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); - $this->assertCount(4, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(4, count($this->getAllMessagesFromMessageBag())); $this->assertTrue($this->getHasAnyMessageInMessageBag()); @@ -280,13 +280,13 @@ public function testAddSuccessMessageToMessageBag(): void $this->assertNotEmpty($this->getErrorMessagesFromMessageBag()); $this->assertNotEmpty($this->getSuccessMessagesFromMessageBag()); - $this->assertCount(1, $this->getLogMessagesFromMessageBag()); - $this->assertCount(1, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(1, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(1, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(1, $this->getSuccessMessagesFromMessageBag()); + $this->assertEquals(1, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getSuccessMessagesFromMessageBag())); - $this->assertCount(5, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(5, count($this->getAllMessagesFromMessageBag())); $this->assertTrue($this->getHasAnyMessageInMessageBag()); @@ -333,13 +333,13 @@ public function testAddThrowableToMessageBag(): void $this->assertNotEmpty($this->getErrorMessagesFromMessageBag()); $this->assertNotEmpty($this->getSuccessMessagesFromMessageBag()); - $this->assertCount(1, $this->getLogMessagesFromMessageBag()); - $this->assertCount(1, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(1, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(2, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(1, $this->getSuccessMessagesFromMessageBag()); + $this->assertEquals(1, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(2, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getSuccessMessagesFromMessageBag())); - $this->assertCount(6, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(6, count($this->getAllMessagesFromMessageBag())); $this->assertTrue($this->getHasAnyMessageInMessageBag()); @@ -394,13 +394,13 @@ public function testAddMessageToMessageBag(): void $this->assertNotEmpty($this->getErrorMessagesFromMessageBag()); $this->assertNotEmpty($this->getSuccessMessagesFromMessageBag()); - $this->assertCount(2, $this->getLogMessagesFromMessageBag()); - $this->assertCount(1, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(1, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(2, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(1, $this->getSuccessMessagesFromMessageBag()); + $this->assertEquals(2, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(2, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getSuccessMessagesFromMessageBag())); - $this->assertCount(7, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(7, count($this->getAllMessagesFromMessageBag())); $this->assertTrue($this->getHasAnyMessageInMessageBag()); @@ -422,7 +422,7 @@ public function testAddMessageToMessageBag(): void $this->assertInstanceOf(\DateTime::class, $message['datetime']); } - public function testClearMessageBag(): void + public function testClearMessageBag() { $this->clearMessageBag(); @@ -452,7 +452,7 @@ public function testClearMessageBag(): void $this->assertFalse($this->getHasAnyMessageInMessageBag()); } - public function testMessageBagToString(): void + public function testMessageBagToString() { $this->clearMessageBag(); $this->addLogMessageToMessageBag('Message 1'); @@ -461,7 +461,9 @@ public function testMessageBagToString(): void $messageBagAsString = (string)$messageBag; $messageBagAsJson = $messageBag->toJson(); - $this->assertSame($messageBagAsJson, $messageBagAsString); + $this->assertIsString($messageBagAsString); + $this->assertIsString($messageBagAsJson); + $this->assertEquals($messageBagAsJson, $messageBagAsString); $this->assertJson($messageBagAsJson); $this->assertJson($messageBagAsString); @@ -479,7 +481,7 @@ public function testMessageBagToString(): void $this->assertObjectHasProperty('datetime', $messageBagJson[0]); } - public function testAddMultipleMessagesToMessageBag(): void + public function testAddMultipleMessagesToMessageBag() { $this->clearMessageBag(); @@ -488,15 +490,15 @@ public function testAddMultipleMessagesToMessageBag(): void $this->addMultipleMessagesToMessageBag(ZugferdMailMessageBagType::MESSAGETYPE_LOG, ["Test 1", "Test 2"]); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(2, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(2, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(2, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(2, count($this->getAllMessagesFromMessageBag())); } - public function testAddMultipleLogMessagesToMessageBag(): void + public function testAddMultipleLogMessagesToMessageBag() { $this->clearMessageBag(); @@ -505,15 +507,15 @@ public function testAddMultipleLogMessagesToMessageBag(): void $this->addMultipleLogMessagesToMessageBag(["Test 1", "Test 2", "Test 3"]); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(3, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(3, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(3, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(3, count($this->getAllMessagesFromMessageBag())); } - public function testAddMultipleLogSecondaryMessagesToMessageBag(): void + public function testAddMultipleLogSecondaryMessagesToMessageBag() { $this->clearMessageBag(); @@ -522,15 +524,15 @@ public function testAddMultipleLogSecondaryMessagesToMessageBag(): void $this->addMultipleLogSecondaryMessagesToMessageBag(["Test 1", "Test 2", "Test 3"]); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(0, $this->getLogMessagesFromMessageBag()); - $this->assertCount(3, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(3, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(0, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(3, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(3, count($this->getAllMessagesFromMessageBag())); } - public function testAddMultipleWarningMessagesToMessageBag(): void + public function testAddMultipleWarningMessagesToMessageBag() { $this->clearMessageBag(); @@ -539,15 +541,15 @@ public function testAddMultipleWarningMessagesToMessageBag(): void $this->addMultipleWarningMessagesToMessageBag(["Test 1", "Test 2", "Test 3"]); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(0, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(3, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(3, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(0, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(3, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(3, count($this->getAllMessagesFromMessageBag())); } - public function testAddMultipleErrorMessagesToMessageBag(): void + public function testAddMultipleErrorMessagesToMessageBag() { $this->clearMessageBag(); @@ -556,15 +558,15 @@ public function testAddMultipleErrorMessagesToMessageBag(): void $this->addMultipleErrorMessagesToMessageBag(["Test 1", "Test 2", "Test 3"]); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(0, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(3, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(3, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(0, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(3, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(3, count($this->getAllMessagesFromMessageBag())); } - public function testAddMultipleSuccessMessagesToMessageBag(): void + public function testAddMultipleSuccessMessagesToMessageBag() { $this->clearMessageBag(); @@ -573,12 +575,12 @@ public function testAddMultipleSuccessMessagesToMessageBag(): void $this->addMultipleSuccessMessagesToMessageBag(["Test 1", "Test 2", "Test 3"]); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(0, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(3, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(3, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(0, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(3, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(3, count($this->getAllMessagesFromMessageBag())); } public function testAddMessageToMessageBagIf(): void @@ -592,12 +594,12 @@ public function testAddMessageToMessageBagIf(): void $this->addMessageToMessageBagIf(false, ZugferdMailMessageBagType::MESSAGETYPE_LOG, 'Message 3'); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(1, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(1, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(1, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getAllMessagesFromMessageBag())); $this->assertArrayHasKey(0, $this->getLogMessagesFromMessageBag()); $this->assertArrayNotHasKey(1, $this->getLogMessagesFromMessageBag()); @@ -615,12 +617,12 @@ public function testAddLogMessageToMessageBagIf(): void $this->addLogMessageToMessageBagIf(false, 'Message 3'); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(1, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(1, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(1, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getAllMessagesFromMessageBag())); $this->assertArrayHasKey(0, $this->getLogMessagesFromMessageBag()); $this->assertArrayNotHasKey(1, $this->getLogMessagesFromMessageBag()); @@ -638,12 +640,12 @@ public function testAddLogSecondaryMessageToMessageBagIf(): void $this->addLogSecondaryMessageToMessageBagIf(false, 'Message 3'); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(0, $this->getLogMessagesFromMessageBag()); - $this->assertCount(1, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(1, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(0, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getAllMessagesFromMessageBag())); $this->assertArrayHasKey(0, $this->getLogSecondaryMessagesFromMessageBag()); $this->assertArrayNotHasKey(1, $this->getLogSecondaryMessagesFromMessageBag()); @@ -661,12 +663,12 @@ public function testAddWarningMessageToMessageBagIf(): void $this->addWarningMessageToMessageBagIf(false, 'Message 3'); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(0, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(1, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(1, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(0, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getAllMessagesFromMessageBag())); $this->assertArrayHasKey(0, $this->getWarningMessagesFromMessageBag()); $this->assertArrayNotHasKey(1, $this->getWarningMessagesFromMessageBag()); @@ -684,12 +686,12 @@ public function testAddErrorMessageToMessageBagIf(): void $this->addErrorMessageToMessageBagIf(false, 'Message 3'); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(0, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(1, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(1, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(0, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getAllMessagesFromMessageBag())); $this->assertArrayHasKey(0, $this->getErrorMessagesFromMessageBag()); $this->assertArrayNotHasKey(1, $this->getErrorMessagesFromMessageBag()); @@ -707,12 +709,12 @@ public function testAddSuccessMessageToMessageBagIf(): void $this->addSuccessMessageToMessageBagIf(false, 'Message 3'); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(0, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(1, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(1, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(0, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getAllMessagesFromMessageBag())); $this->assertArrayHasKey(0, $this->getSuccessMessagesFromMessageBag()); $this->assertArrayNotHasKey(1, $this->getSuccessMessagesFromMessageBag()); @@ -730,19 +732,19 @@ public function testAddThrowableToMessageBagIf(): void $this->addThrowableToMessageBagIf(false, new \Exception("Message 3")); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(0, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(1, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(1, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(0, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(1, count($this->getAllMessagesFromMessageBag())); $this->assertArrayHasKey(0, $this->getErrorMessagesFromMessageBag()); $this->assertArrayNotHasKey(1, $this->getErrorMessagesFromMessageBag()); $this->assertEquals("Message 2", $this->getErrorMessagesFromMessageBag()[0]["message"]); } - public function testAddMultipleMessagesToMessageBagIf(): void + public function testAddMultipleMessagesToMessageBagIf() { $this->clearMessageBag(); @@ -755,15 +757,15 @@ public function testAddMultipleMessagesToMessageBagIf(): void $this->addMultipleMessagesToMessageBagIf(true, ZugferdMailMessageBagType::MESSAGETYPE_LOG, ["Test 1", "Test 2"]); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(2, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(2, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(2, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(2, count($this->getAllMessagesFromMessageBag())); } - public function testAddMultipleLogMessagesToMessageBagIf(): void + public function testAddMultipleLogMessagesToMessageBagIf() { $this->clearMessageBag(); @@ -776,15 +778,15 @@ public function testAddMultipleLogMessagesToMessageBagIf(): void $this->addMultipleLogMessagesToMessageBagIf(true, ["Test 1", "Test 2"]); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(2, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(2, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(2, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(2, count($this->getAllMessagesFromMessageBag())); } - public function testAddMultipleLogSecondaryMessagesToMessageBagIf(): void + public function testAddMultipleLogSecondaryMessagesToMessageBagIf() { $this->clearMessageBag(); @@ -797,15 +799,15 @@ public function testAddMultipleLogSecondaryMessagesToMessageBagIf(): void $this->addMultipleLogSecondaryMessagesToMessageBagIf(true, ["Test 1", "Test 2"]); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(0, $this->getLogMessagesFromMessageBag()); - $this->assertCount(2, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(2, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(0, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(2, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(2, count($this->getAllMessagesFromMessageBag())); } - public function testAddMultipleWarningMessagesToMessageBagIf(): void + public function testAddMultipleWarningMessagesToMessageBagIf() { $this->clearMessageBag(); @@ -818,15 +820,15 @@ public function testAddMultipleWarningMessagesToMessageBagIf(): void $this->addMultipleWarningMessagesToMessageBagIf(true, ["Test 1", "Test 2"]); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(0, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(2, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(2, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(0, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(2, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(2, count($this->getAllMessagesFromMessageBag())); } - public function testAddMultipleErrorMessagesToMessageBagIf(): void + public function testAddMultipleErrorMessagesToMessageBagIf() { $this->clearMessageBag(); @@ -839,15 +841,15 @@ public function testAddMultipleErrorMessagesToMessageBagIf(): void $this->addMultipleErrorMessagesToMessageBagIf(true, ["Test 1", "Test 2"]); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(0, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(2, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(0, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(2, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(0, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(2, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(2, count($this->getAllMessagesFromMessageBag())); } - public function testAddMultipleSuccessMessagesToMessageBagIf(): void + public function testAddMultipleSuccessMessagesToMessageBagIf() { $this->clearMessageBag(); @@ -860,11 +862,11 @@ public function testAddMultipleSuccessMessagesToMessageBagIf(): void $this->addMultipleSuccessMessagesToMessageBagIf(true, ["Test 1", "Test 2"]); $this->assertTrue($this->getHasAnyMessageInMessageBag()); - $this->assertCount(0, $this->getLogMessagesFromMessageBag()); - $this->assertCount(0, $this->getLogSecondaryMessagesFromMessageBag()); - $this->assertCount(0, $this->getWarningMessagesFromMessageBag()); - $this->assertCount(0, $this->getErrorMessagesFromMessageBag()); - $this->assertCount(2, $this->getSuccessMessagesFromMessageBag()); - $this->assertCount(2, $this->getAllMessagesFromMessageBag()); + $this->assertEquals(0, count($this->getLogMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getLogSecondaryMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getWarningMessagesFromMessageBag())); + $this->assertEquals(0, count($this->getErrorMessagesFromMessageBag())); + $this->assertEquals(2, count($this->getSuccessMessagesFromMessageBag())); + $this->assertEquals(2, count($this->getAllMessagesFromMessageBag())); } } diff --git a/tests/testcases/ZugferdMailConcernParsesPlaceholdersTest.php b/tests/testcases/ZugferdMailConcernParsesPlaceholdersTest.php index f4c1908..be0bf82 100644 --- a/tests/testcases/ZugferdMailConcernParsesPlaceholdersTest.php +++ b/tests/testcases/ZugferdMailConcernParsesPlaceholdersTest.php @@ -13,25 +13,29 @@ class ZugferdMailConcernParsesPlaceholdersTest extends TestCase public function testParsePlaceholdersByZugferdDocumentReaderEn16931(): void { - $documentReader = ZugferdDocumentReader::readAndGuessFromFile(__DIR__ . "/../assets/fx_en16931.xml"); + $documentReader = ZugferdDocumentReader::readAndGuessFromFile(dirname(__FILE__) . "/../assets/fx_en16931.xml"); - $this->assertSame(ZugferdProfiles::PROFILE_EN16931, $documentReader->getProfileId()); + $this->assertNotNull($documentReader); + $this->assertEquals(ZugferdProfiles::PROFILE_EN16931, $documentReader->getProfileId()); $testString = "Invoice_{documentno}_{documentsellername}"; $parsedString = $this->parsePlaceholdersByZugferdDocumentReader($documentReader, $testString); - $this->assertSame("Invoice_471102_Lieferant GmbH", $parsedString); + $this->assertIsString($parsedString); + $this->assertEquals("Invoice_471102_Lieferant GmbH", $parsedString); } public function testParsePlaceholdersByZugferdDocumentReaderExtended(): void { - $documentReader = ZugferdDocumentReader::readAndGuessFromFile(__DIR__ . "/../assets/fx_extended.xml"); + $documentReader = ZugferdDocumentReader::readAndGuessFromFile(dirname(__FILE__) . "/../assets/fx_extended.xml"); - $this->assertSame(ZugferdProfiles::PROFILE_EXTENDED, $documentReader->getProfileId()); + $this->assertNotNull($documentReader); + $this->assertEquals(ZugferdProfiles::PROFILE_EXTENDED, $documentReader->getProfileId()); $testString = "Invoice_{documentno}_{documentsellername}"; $parsedString = $this->parsePlaceholdersByZugferdDocumentReader($documentReader, $testString); - $this->assertSame("Invoice_471102_Lieferant GmbH", $parsedString); + $this->assertIsString($parsedString); + $this->assertEquals("Invoice_471102_Lieferant GmbH", $parsedString); } } diff --git a/tests/testcases/ZugferdMailConcernRaisesExceptionsTest.php b/tests/testcases/ZugferdMailConcernRaisesExceptionsTest.php index 952d1b1..aac5f07 100644 --- a/tests/testcases/ZugferdMailConcernRaisesExceptionsTest.php +++ b/tests/testcases/ZugferdMailConcernRaisesExceptionsTest.php @@ -20,6 +20,13 @@ public function testRaiseExceptionClassIfWithTrue(): void $this->raiseExceptionClassIf(true, RuntimeException::class, static::EXCEPTIONMESSAGE); } + public function testRaiseExceptionClassIfWithFalse(): void + { + $this->assertTrue(true); // We need one assertion in this test + + $this->raiseExceptionClassIf(false, RuntimeException::class, static::EXCEPTIONMESSAGE); + } + public function testRaiseRuntimeExceptionClassIfWithTrue(): void { $this->expectException(RuntimeException::class); @@ -27,4 +34,11 @@ public function testRaiseRuntimeExceptionClassIfWithTrue(): void $this->raiseRuntimeExceptionIf(true, static::EXCEPTIONMESSAGE); } + + public function testRaiseRuntimeExceptionClassIfWithFalse(): void + { + $this->assertTrue(true); // We need one assertion in this test + + $this->raiseRuntimeExceptionIf(false, static::EXCEPTIONMESSAGE); + } } diff --git a/tests/testcases/ZugferdMailConfigTest.php b/tests/testcases/ZugferdMailConfigTest.php index 19fdd8f..03125d4 100644 --- a/tests/testcases/ZugferdMailConfigTest.php +++ b/tests/testcases/ZugferdMailConfigTest.php @@ -19,8 +19,9 @@ public function testMailCondigInit(): void { $config = new ZugferdMailConfig(); - $this->assertSame("d-M-Y", $config->getDateFormatIdentifier()); - $this->assertSame("list", $config->getMessageKeyIdentifier()); + $this->assertNotNull($config); + $this->assertEquals("d-M-Y", $config->getDateFormatIdentifier()); + $this->assertEquals("list", $config->getMessageKeyIdentifier()); $this->assertEquals(false, $config->getUblSupportEnabled()); $this->assertEquals(false, $config->getSymfonyValidationEnabled()); $this->assertEquals(false, $config->getSymfonyValidationEnabled()); @@ -43,7 +44,7 @@ public function testMailConfigSetDateFormatValid(): void $config = new ZugferdMailConfig(); $config->setDateFormatIdentifier("d M y"); - $this->assertSame("d M y", $config->getDateFormatIdentifier()); + $this->assertEquals("d M y", $config->getDateFormatIdentifier()); } public function testMailConfigSetMessageKeyInvalid(): void @@ -60,7 +61,7 @@ public function testMailConfigSetMessageKeyValid(): void $config = new ZugferdMailConfig(); $config->setMessageKeyIdentifier("id"); - $this->assertSame("id", $config->getMessageKeyIdentifier()); + $this->assertEquals("id", $config->getMessageKeyIdentifier()); } public function testMailConfigActivateUblSupport(): void @@ -174,11 +175,13 @@ public function testMailConfigMakeClientManager(): void $clientManagher = $config->makeClientManager(); + $this->assertNotNull($clientManagher); $this->assertInstanceOf(ClientManager::class, $clientManagher); + $this->assertNotNull($clientManagher->account("test")); $this->assertInstanceOf(Client::class, $clientManagher->account("test")); - $this->assertSame("127.0.0.1", $clientManagher->account("test")->host); - $this->assertSame(993, $clientManagher->account("test")->port); - $this->assertSame("imap", $clientManagher->account("test")->protocol); + $this->assertEquals("127.0.0.1", $clientManagher->account("test")->host); + $this->assertEquals(993, $clientManagher->account("test")->port); + $this->assertEquals("imap", $clientManagher->account("test")->protocol); } public function testMailConfigAddAccount(): void @@ -192,9 +195,9 @@ public function testMailConfigAddAccount(): void $mailAccount = $config->getAccounts()[0]; - $this->assertSame("127.0.0.1", $mailAccount->getHost()); - $this->assertSame(993, $mailAccount->getPort()); - $this->assertSame("imap", $mailAccount->getProtocol()); + $this->assertEquals("127.0.0.1", $mailAccount->getHost()); + $this->assertEquals(993, $mailAccount->getPort()); + $this->assertEquals("imap", $mailAccount->getProtocol()); } public function testMailConfigAddAccountObject(): void @@ -222,12 +225,12 @@ public function testMailConfigAddAccountObject(): void $mailAccount = $config->getAccounts()[0]; - $this->assertSame("127.0.0.1", $mailAccount->getHost()); - $this->assertSame(993, $mailAccount->getPort()); - $this->assertSame("imap", $mailAccount->getProtocol()); + $this->assertEquals("127.0.0.1", $mailAccount->getHost()); + $this->assertEquals(993, $mailAccount->getPort()); + $this->assertEquals("imap", $mailAccount->getProtocol()); $this->assertEquals("tls", $mailAccount->getEncryption()); - $this->assertSame("demouser", $mailAccount->getUsername()); - $this->assertSame("demopassword", $mailAccount->getPassword()); + $this->assertEquals("demouser", $mailAccount->getUsername()); + $this->assertEquals("demopassword", $mailAccount->getPassword()); } public function testMailConfigRemoveAccount(): void @@ -257,12 +260,12 @@ public function testLoadConfigFromNotExistingFile(): void { $this->expectException(InvalidArgumentException::class); - ZugferdMailConfig::loadFromFile(__DIR__ . '/../assets/unknown.json'); + ZugferdMailConfig::loadFromFile(dirname(__FILE__) . '/../assets/unknown.json'); } public function testLoadConfigWithContentWhichIsNoJson(): void { - $configFilename = __DIR__ . '/../assets/config.nojson.json'; + $configFilename = dirname(__FILE__) . '/../assets/config.nojson.json'; $this->expectException(RuntimeException::class); $this->expectExceptionMessage(sprintf('The file %s does not seem to be a valid json.', $configFilename)); @@ -272,7 +275,7 @@ public function testLoadConfigWithContentWhichIsNoJson(): void public function testLoadConfigWithContentWhichIsInvalidJson(): void { - $configFilename = __DIR__ . '/../assets/config.invalid.json'; + $configFilename = dirname(__FILE__) . '/../assets/config.invalid.json'; $this->expectException(RuntimeException::class); $this->expectExceptionMessage(sprintf('The file %s could not be identified as a valid JSON file', $configFilename)); @@ -282,13 +285,14 @@ public function testLoadConfigWithContentWhichIsInvalidJson(): void public function testLoadConfigWithValidJson(): void { - $configFilename = __DIR__ . '/../assets/config.valid.json'; + $configFilename = dirname(__FILE__) . '/../assets/config.valid.json'; $config = ZugferdMailConfig::loadFromFile($configFilename); + $this->assertNotNull($config); $this->assertInstanceOf(ZugferdMailConfig::class, $config); - $this->assertSame("d-M-Y", $config->getDateFormatIdentifier()); - $this->assertSame("id", $config->getMessageKeyIdentifier()); + $this->assertEquals("d-M-Y", $config->getDateFormatIdentifier()); + $this->assertEquals("id", $config->getMessageKeyIdentifier()); $this->assertTrue($config->getUblSupportEnabled()); $this->assertTrue($config->getSymfonyValidationEnabled()); $this->assertTrue($config->getXsdValidationEnabled()); @@ -344,7 +348,7 @@ public function testLoadConfigWithValidJson(): void public function testSaveConfigToInvalidFilename(): void { - $configFilename = __DIR__ . '/../somefolder/config.save.json'; + $configFilename = dirname(__FILE__) . '/../somefolder/config.save.json'; $this->expectException(RuntimeException::class); $this->expectExceptionMessage(sprintf('Directory of file %s does not exist.', $configFilename)); @@ -370,7 +374,7 @@ public function testSaveConfigToInvalidFilename(): void public function testSaveConfigToValidFilename(): void { - $configFilename = __DIR__ . '/../assets/config.save.json'; + $configFilename = dirname(__FILE__) . '/../assets/config.save.json'; $mailAccount = new ZugferdMailAccount(); $mailAccount->setHost("127.0.0.1"); @@ -396,7 +400,7 @@ public function testSaveConfigToValidFilename(): void public function testSaveAndLoadConfigSameFile(): void { - $configFilename = __DIR__ . '/../assets/config.save.json'; + $configFilename = dirname(__FILE__) . '/../assets/config.save.json'; // Create config and save to config file @@ -425,9 +429,10 @@ public function testSaveAndLoadConfigSameFile(): void $config = ZugferdMailConfig::loadFromFile($configFilename); + $this->assertNotNull($config); $this->assertInstanceOf(ZugferdMailConfig::class, $config); - $this->assertSame("d-M-Y", $config->getDateFormatIdentifier()); - $this->assertSame("list", $config->getMessageKeyIdentifier()); + $this->assertEquals("d-M-Y", $config->getDateFormatIdentifier()); + $this->assertEquals("list", $config->getMessageKeyIdentifier()); $this->assertFalse($config->getUblSupportEnabled()); $this->assertTrue($config->getSymfonyValidationEnabled()); $this->assertTrue($config->getXsdValidationEnabled()); diff --git a/tests/testcases/ZugferdMailPlaceholderHelperTest.php b/tests/testcases/ZugferdMailPlaceholderHelperTest.php index 72dcd83..c3aaf1e 100644 --- a/tests/testcases/ZugferdMailPlaceholderHelperTest.php +++ b/tests/testcases/ZugferdMailPlaceholderHelperTest.php @@ -92,24 +92,25 @@ public function testCreateFromFilledArrayAndParse(): void $testString = "{test}_{test2}_{test3_ymd}_{test4_a}_{test4_b}"; $parsedstring = $placeholderHelper->parseString($testString); - $this->assertSame(sprintf("_A_%s_aa_bb", $dateTime->format("Ymd")), $parsedstring); + $this->assertEquals(sprintf("_A_%s_aa_bb", $dateTime->format("Ymd")), $parsedstring); $testString = "{test2}_{test3_ymd}_{test4_a}_{test4_b}"; $parsedstring = $placeholderHelper->parseString($testString); - $this->assertSame(sprintf("A_%s_aa_bb", $dateTime->format("Ymd")), $parsedstring); + $this->assertEquals(sprintf("A_%s_aa_bb", $dateTime->format("Ymd")), $parsedstring); $testString = "{test4_a}_{test4_b}"; $parsedstring = $placeholderHelper->parseString($testString); - $this->assertSame("aa_bb", $parsedstring); + $this->assertEquals("aa_bb", $parsedstring); } public function testCreateFromZugferdDocumentReaderEn16931(): void { - $documentReader = ZugferdDocumentReader::readAndGuessFromFile(__DIR__ . "/../assets/fx_en16931.xml"); + $documentReader = ZugferdDocumentReader::readAndGuessFromFile(dirname(__FILE__) . "/../assets/fx_en16931.xml"); - $this->assertSame(ZugferdProfiles::PROFILE_EN16931, $documentReader->getProfileId()); + $this->assertNotNull($documentReader); + $this->assertEquals(ZugferdProfiles::PROFILE_EN16931, $documentReader->getProfileId()); $placeholderHelper = ZugferdMailPlaceholderHelper::fromZugferdDocumentReader($documentReader); @@ -144,9 +145,10 @@ public function testCreateFromZugferdDocumentReaderEn16931(): void public function testCreateFromZugferdDocumentReaderExtended(): void { - $documentReader = ZugferdDocumentReader::readAndGuessFromFile(__DIR__ . "/../assets/fx_extended.xml"); + $documentReader = ZugferdDocumentReader::readAndGuessFromFile(dirname(__FILE__) . "/../assets/fx_extended.xml"); - $this->assertSame(ZugferdProfiles::PROFILE_EXTENDED, $documentReader->getProfileId()); + $this->assertNotNull($documentReader); + $this->assertEquals(ZugferdProfiles::PROFILE_EXTENDED, $documentReader->getProfileId()); $placeholderHelper = ZugferdMailPlaceholderHelper::fromZugferdDocumentReader($documentReader); diff --git a/tests/testcases/ZugferdMailStringHelperTest.php b/tests/testcases/ZugferdMailStringHelperTest.php index 86d2426..92a1d42 100644 --- a/tests/testcases/ZugferdMailStringHelperTest.php +++ b/tests/testcases/ZugferdMailStringHelperTest.php @@ -11,7 +11,7 @@ public function testTruncateString(): void { $testString = "012345678901234567890123456789"; - $this->assertSame("012345678901234567890123456...", ZugferdMailStringHelper::truncateString($testString, 30)); - $this->assertSame("012345678901234567890123456789", ZugferdMailStringHelper::truncateString($testString, 40)); + $this->assertEquals("012345678901234567890123456...", ZugferdMailStringHelper::truncateString($testString, 30)); + $this->assertEquals("012345678901234567890123456789", ZugferdMailStringHelper::truncateString($testString, 40)); } }