diff --git a/src/AddressList.php b/src/AddressList.php index 3f5708f6..2bb42c0d 100644 --- a/src/AddressList.php +++ b/src/AddressList.php @@ -105,7 +105,7 @@ public function addFromString($address, $comment = null) * @param AddressList $addressList * @return AddressList */ - public function merge(AddressList $addressList) + public function merge(self $addressList) { foreach ($addressList as $address) { $this->add($address); diff --git a/src/Header/ContentDisposition.php b/src/Header/ContentDisposition.php index 5594afb8..635e97cc 100644 --- a/src/Header/ContentDisposition.php +++ b/src/Header/ContentDisposition.php @@ -18,7 +18,7 @@ class ContentDisposition implements UnstructuredInterface * * @var int */ - const MAX_PARAMETER_LENGTH = 76; + public const MAX_PARAMETER_LENGTH = 76; /** * @var string @@ -79,7 +79,7 @@ public static function fromString($headerLine) foreach ($continuedValues as $name => $values) { $value = ''; - for ($i = 0; $i < count($values); $i++) { + for ($i = 0, $iMax = count($values); $i < $iMax; $i++) { if (! isset($values[$i])) { throw new Exception\InvalidArgumentException( 'Invalid header line for Content-Disposition string - incomplete continuation' diff --git a/src/Header/ContentType.php b/src/Header/ContentType.php index 3b57df46..4da2f00d 100644 --- a/src/Header/ContentType.php +++ b/src/Header/ContentType.php @@ -181,7 +181,8 @@ public function getParameter($name) if (isset($this->parameters[$name])) { return $this->parameters[$name]; } - return; + + return null; } /** diff --git a/src/Header/HeaderInterface.php b/src/Header/HeaderInterface.php index 3aa74fab..32505e9d 100644 --- a/src/Header/HeaderInterface.php +++ b/src/Header/HeaderInterface.php @@ -15,14 +15,14 @@ interface HeaderInterface * * @var bool */ - const FORMAT_ENCODED = true; + public const FORMAT_ENCODED = true; /** * Return value in internal encoding which is usually UTF-8 * * @var bool */ - const FORMAT_RAW = false; + public const FORMAT_RAW = false; /** * Factory to generate a header object from a string @@ -47,7 +47,7 @@ public function getFieldName(); * @param bool $format Return the value in Mime::Encoded or in Raw format * @return string */ - public function getFieldValue($format = HeaderInterface::FORMAT_RAW); + public function getFieldValue($format = self::FORMAT_RAW); /** * Set header encoding diff --git a/src/Header/HeaderLocator.php b/src/Header/HeaderLocator.php index 06046665..25d0dc09 100644 --- a/src/Header/HeaderLocator.php +++ b/src/Header/HeaderLocator.php @@ -50,7 +50,7 @@ final class HeaderLocator implements HeaderLocatorInterface public function get(string $name, ?string $default = null): ?string { $name = $this->normalizeName($name); - return isset($this->plugins[$name]) ? $this->plugins[$name] : $default; + return $this->plugins[$name] ?? $default; } public function has(string $name): bool diff --git a/src/Header/IdentificationField.php b/src/Header/IdentificationField.php index 0d00b4a5..c6eadb85 100644 --- a/src/Header/IdentificationField.php +++ b/src/Header/IdentificationField.php @@ -47,7 +47,7 @@ public static function fromString($headerLine) $value = HeaderWrap::mimeDecodeValue($value); $messageIds = array_map( - [IdentificationField::class, "trimMessageId"], + [self::class, "trimMessageId"], explode(" ", $value) ); @@ -127,7 +127,7 @@ public function setIds($ids) } } - $this->messageIds = array_map([IdentificationField::class, "trimMessageId"], $ids); + $this->messageIds = array_map([self::class, "trimMessageId"], $ids); return $this; } diff --git a/src/Header/ListParser.php b/src/Header/ListParser.php index e18c40f9..6eb50281 100644 --- a/src/Header/ListParser.php +++ b/src/Header/ListParser.php @@ -15,9 +15,9 @@ */ class ListParser { - const CHAR_QUOTES = ['\'', '"']; - const CHAR_DELIMS = [',', ';']; - const CHAR_ESCAPE = '\\'; + public const CHAR_QUOTES = ['\'', '"']; + public const CHAR_DELIMS = [',', ';']; + public const CHAR_ESCAPE = '\\'; /** * @param string $value diff --git a/src/Header/Received.php b/src/Header/Received.php index d1298685..06a4573c 100644 --- a/src/Header/Received.php +++ b/src/Header/Received.php @@ -80,7 +80,7 @@ public function toStringMultipleHeaders(array $headers) { $strings = [$this->toString()]; foreach ($headers as $header) { - if (! $header instanceof Received) { + if (! $header instanceof self) { throw new Exception\RuntimeException( 'The Received multiple header implementation can only accept an array of Received headers' ); diff --git a/src/Headers.php b/src/Headers.php index 41beb7a2..107fa97e 100644 --- a/src/Headers.php +++ b/src/Headers.php @@ -13,7 +13,6 @@ use ArrayIterator; use Countable; use Iterator; -use Laminas\Loader\PluginClassLoader; use Laminas\Loader\PluginClassLocator; use Laminas\Mail\Header\GenericHeader; use Laminas\Mail\Header\HeaderInterface; @@ -27,10 +26,10 @@ class Headers implements Countable, Iterator { /** @var string End of Line for fields */ - const EOL = "\r\n"; + public const EOL = "\r\n"; /** @var string Start of Line when folding */ - const FOLDING = "\r\n "; + public const FOLDING = "\r\n "; /** * @var null|Header\HeaderLocatorInterface @@ -391,10 +390,8 @@ public function get($name) case 1: if ($results[0] instanceof Header\MultipleHeadersInterface) { return new ArrayIterator($results); - } else { - return $results[0]; } - //fall-trough + return $results[0]; default: return new ArrayIterator($results); } @@ -541,7 +538,7 @@ public function forceLoading() */ public function loadHeader($headerLine) { - list($name, ) = Header\GenericHeader::splitHeaderLine($headerLine); + list($name) = Header\GenericHeader::splitHeaderLine($headerLine); /** @var HeaderInterface $class */ $class = $this->resolveHeaderClass($name); diff --git a/src/Protocol/AbstractProtocol.php b/src/Protocol/AbstractProtocol.php index 0882e1e0..1c6ed05d 100644 --- a/src/Protocol/AbstractProtocol.php +++ b/src/Protocol/AbstractProtocol.php @@ -21,12 +21,12 @@ abstract class AbstractProtocol /** * Mail default EOL string */ - const EOL = "\r\n"; + public const EOL = "\r\n"; /** * Default timeout in seconds for initiating session */ - const TIMEOUT_CONNECTION = 30; + public const TIMEOUT_CONNECTION = 30; /** * Maximum of the transaction log diff --git a/src/Protocol/Imap.php b/src/Protocol/Imap.php index 7130beb9..b8626913 100644 --- a/src/Protocol/Imap.php +++ b/src/Protocol/Imap.php @@ -15,7 +15,7 @@ class Imap /** * Default timeout in seconds for initiating session */ - const TIMEOUT_CONNECTION = 30; + public const TIMEOUT_CONNECTION = 30; /** * @var null|resource @@ -290,13 +290,13 @@ public function readResponse($tag, $dontParse = false) // last to chars are still needed for response code $tokens = [substr($tokens, 0, 2)]; } + // last line has response code if ($tokens[0] == 'OK') { return $lines ? $lines : true; } elseif ($tokens[0] == 'NO') { return false; } - return; } /** @@ -364,10 +364,11 @@ public function escapeString($string) if (func_num_args() < 2) { if (strpos($string, "\n") !== false) { return ['{' . strlen($string) . '}', $string]; - } else { - return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"'; } + + return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"'; } + $result = []; foreach (func_get_args() as $string) { $result[] = $this->escapeString($string); diff --git a/src/Protocol/Pop3.php b/src/Protocol/Pop3.php index 92aa3554..f3013a89 100644 --- a/src/Protocol/Pop3.php +++ b/src/Protocol/Pop3.php @@ -17,7 +17,7 @@ class Pop3 /** * Default timeout in seconds for initiating session */ - const TIMEOUT_CONNECTION = 30; + public const TIMEOUT_CONNECTION = 30; /** * saves if server supports top @@ -127,7 +127,7 @@ public function connect($host, $port = null, $ssl = false) public function sendRequest($request) { ErrorHandler::start(); - $result = fputs($this->socket, $request . "\r\n"); + $result = fwrite($this->socket, $request . "\r\n"); $error = ErrorHandler::stop(); if (! $result) { throw new Exception\RuntimeException('send failed - connection closed?', 0, $error); @@ -171,7 +171,7 @@ public function readResponse($multiline = false) } $message .= $line; $line = fgets($this->socket); - }; + } } return $message; @@ -209,7 +209,6 @@ public function logout() } } - /** * Get capabilities from POP3 server * @@ -221,7 +220,6 @@ public function capa() return explode("\n", $result); } - /** * Login to POP3 server. Can use APOP * @@ -244,7 +242,6 @@ public function login($user, $password, $tryApop = true) $this->request("PASS $password"); } - /** * Make STAT call for message count and size sum * @@ -260,7 +257,6 @@ public function status(&$messages, &$octets) list($messages, $octets) = explode(' ', $result); } - /** * Make LIST call for size of message(s) * @@ -288,7 +284,6 @@ public function getList($msgno = null) return $messages; } - /** * Make UIDL call for getting a uniqueid * @@ -319,7 +314,6 @@ public function uniqueid($msgno = null) return $messages; } - /** * Make TOP call for getting headers and maybe some body lines * This method also sets hasTop - before it it's not known if top is supported @@ -339,9 +333,9 @@ public function top($msgno, $lines = 0, $fallback = false) if ($this->hasTop === false) { if ($fallback) { return $this->retrieve($msgno); - } else { - throw new Exception\RuntimeException('top not supported and no fallback wanted'); } + + throw new Exception\RuntimeException('top not supported and no fallback wanted'); } $this->hasTop = true; diff --git a/src/Protocol/ProtocolTrait.php b/src/Protocol/ProtocolTrait.php index eaf6e296..e384be7e 100644 --- a/src/Protocol/ProtocolTrait.php +++ b/src/Protocol/ProtocolTrait.php @@ -21,7 +21,6 @@ trait ProtocolTrait */ protected $novalidatecert; - public function getCryptoMethod(): int { // Allow the best TLS version(s) we can @@ -72,7 +71,7 @@ private function prepareSocketOptions(): array 'ssl' => [ 'verify_peer_name' => false, 'verify_peer' => false, - ] + ], ] : []; } diff --git a/src/Protocol/Smtp.php b/src/Protocol/Smtp.php index dcb7ebe0..05f23381 100644 --- a/src/Protocol/Smtp.php +++ b/src/Protocol/Smtp.php @@ -260,7 +260,6 @@ protected function ehlo($host) } } - /** * Issues MAIL command * @@ -282,7 +281,6 @@ public function mail($from) $this->data = false; } - /** * Issues RCPT command * @@ -301,7 +299,6 @@ public function rcpt($to) $this->rcpt = true; } - /** * Issues DATA command * @@ -343,7 +340,6 @@ public function data($data) $this->data = true; } - /** * Issues the RSET command end validates answer * diff --git a/src/Storage.php b/src/Storage.php index 81f13197..cc2df565 100644 --- a/src/Storage.php +++ b/src/Storage.php @@ -12,12 +12,12 @@ class Storage { // maildir and IMAP flags, using IMAP names, where possible to be able to distinguish between IMAP // system flags and other flags - const FLAG_PASSED = 'Passed'; - const FLAG_SEEN = '\Seen'; - const FLAG_UNSEEN = '\Unseen'; - const FLAG_ANSWERED = '\Answered'; - const FLAG_FLAGGED = '\Flagged'; - const FLAG_DELETED = '\Deleted'; - const FLAG_DRAFT = '\Draft'; - const FLAG_RECENT = '\Recent'; + public const FLAG_PASSED = 'Passed'; + public const FLAG_SEEN = '\Seen'; + public const FLAG_UNSEEN = '\Unseen'; + public const FLAG_ANSWERED = '\Answered'; + public const FLAG_FLAGGED = '\Flagged'; + public const FLAG_DELETED = '\Deleted'; + public const FLAG_DRAFT = '\Draft'; + public const FLAG_RECENT = '\Recent'; } diff --git a/src/Storage/Folder.php b/src/Storage/Folder.php index deb590a7..ec6fa902 100644 --- a/src/Storage/Folder.php +++ b/src/Storage/Folder.php @@ -61,7 +61,7 @@ public function __construct($localName, $globalName = '', $selectable = true, ar public function hasChildren() { $current = $this->current(); - return $current && $current instanceof Folder && ! $current->isLeaf(); + return $current && $current instanceof self && ! $current->isLeaf(); } /** @@ -142,7 +142,7 @@ public function __get($name) * @param string $name local name of subfolder * @param \Laminas\Mail\Storage\Folder $folder instance for new subfolder */ - public function __set($name, Folder $folder) + public function __set($name, self $folder) { $this->folders[$name] = $folder; } diff --git a/src/Storage/Folder/Mbox.php b/src/Storage/Folder/Mbox.php index e05a9a57..fa443723 100644 --- a/src/Storage/Folder/Mbox.php +++ b/src/Storage/Folder/Mbox.php @@ -8,6 +8,7 @@ namespace Laminas\Mail\Storage\Folder; +use Laminas\Config\Config; use Laminas\Mail\Storage; use Laminas\Mail\Storage\Exception; use Laminas\Stdlib\ErrorHandler; @@ -43,7 +44,7 @@ class Mbox extends Storage\Mbox implements FolderInterface * - dirname rootdir of mbox structure * - folder initial selected folder, default is 'INBOX' * - * @param $params array mail reader specific parameters + * @param $params array|object|Config mail reader specific parameters * @throws Exception\InvalidArgumentException */ public function __construct($params) diff --git a/src/Storage/Imap.php b/src/Storage/Imap.php index e4acf9e1..d5b90dd5 100644 --- a/src/Storage/Imap.php +++ b/src/Storage/Imap.php @@ -121,7 +121,7 @@ public function getMessage($id) $flags = []; foreach ($data['FLAGS'] as $flag) { - $flags[] = isset(static::$knownFlags[$flag]) ? static::$knownFlags[$flag] : $flag; + $flags[] = static::$knownFlags[$flag] ?? $flag; } return new $this->messageClass(['handler' => $this, 'id' => $id, 'headers' => $header, 'flags' => $flags]); diff --git a/src/Storage/Maildir.php b/src/Storage/Maildir.php index aab9d0c5..b7e46650 100644 --- a/src/Storage/Maildir.php +++ b/src/Storage/Maildir.php @@ -8,6 +8,7 @@ namespace Laminas\Mail\Storage; +use Laminas\Config\Config; use Laminas\Mail; use Laminas\Stdlib\ErrorHandler; @@ -112,12 +113,12 @@ public function getSize($id = null) { if ($id !== null) { $filedata = $this->getFileData($id); - return isset($filedata['size']) ? $filedata['size'] : filesize($filedata['filename']); + return $filedata['size'] ?? filesize($filedata['filename']); } $result = []; foreach ($this->files as $num => $data) { - $result[$num + 1] = isset($data['size']) ? $data['size'] : filesize($data['filename']); + $result[$num + 1] = $data['size'] ?? filesize($data['filename']); } return $result; @@ -215,7 +216,7 @@ public function getRawContent($id, $part = null) * Supported parameters are: * - dirname dirname of mbox file * - * @param $params array mail reader specific parameters + * @param $params array|object|Config mail reader specific parameters * @throws Exception\InvalidArgumentException */ public function __construct($params) @@ -322,14 +323,14 @@ protected function getMaildirFiles($dh, $dirname, $defaultFlags = []) $length = strlen($flags); for ($i = 0; $i < $length; ++$i) { $flag = $flags[$i]; - $namedFlags[$flag] = isset(static::$knownFlags[$flag]) ? static::$knownFlags[$flag] : $flag; + $namedFlags[$flag] = static::$knownFlags[$flag] ?? $flag; } $data = [ 'uniq' => $uniq, 'flags' => $namedFlags, 'flaglookup' => array_flip($namedFlags), - 'filename' => $dirname . $entry + 'filename' => $dirname . $entry, ]; if ($size !== null) { $data['size'] = (int) $size; diff --git a/src/Storage/Mbox.php b/src/Storage/Mbox.php index eb98b59d..3e48a6c6 100644 --- a/src/Storage/Mbox.php +++ b/src/Storage/Mbox.php @@ -8,6 +8,7 @@ namespace Laminas\Mail\Storage; +use Laminas\Config\Config; use Laminas\Stdlib\ErrorHandler; class Mbox extends AbstractStorage @@ -115,7 +116,7 @@ public function getMessage($id) $messageClassParams = [ 'file' => $this->fh, 'startPos' => $messagePos['start'], - 'endPos' => $messagePos['end'] + 'endPos' => $messagePos['end'], ]; if (isset($this->messageEOL)) { @@ -184,7 +185,7 @@ public function getRawContent($id, $part = null) * Supported parameters are: * - filename filename of mbox file * - * @param $params array mail reader specific parameters + * @param $params array|object|Config mail reader specific parameters * @throws Exception\InvalidArgumentException */ public function __construct($params) @@ -312,7 +313,6 @@ public function close() $this->positions = []; } - /** * Waste some CPU cycles doing nothing. * @@ -323,7 +323,6 @@ public function noop() return true; } - /** * stub for not supported message deletion * diff --git a/src/Storage/Part.php b/src/Storage/Part.php index 4807e49b..8eb7e683 100644 --- a/src/Storage/Part.php +++ b/src/Storage/Part.php @@ -92,7 +92,7 @@ public function __construct(array $params) $this->messageNum = $params['id']; } - $params['strict'] = isset($params['strict']) ? $params['strict'] : false; + $params['strict'] = $params['strict'] ?? false; if (isset($params['raw'])) { Mime\Decode::splitMessage( @@ -134,7 +134,6 @@ public function isMultipart() } } - /** * Body of part * @@ -168,7 +167,6 @@ public function getSize() return strlen($this->getContent()); } - /** * Cache content and split in parts if multipart * @@ -409,7 +407,7 @@ public function __toString() public function hasChildren() { $current = $this->current(); - return $current && $current instanceof Part && $current->isMultipart(); + return $current && $current instanceof self && $current->isMultipart(); } /** diff --git a/src/Storage/Part/File.php b/src/Storage/Part/File.php index 3a19331a..43bd2e41 100644 --- a/src/Storage/Part/File.php +++ b/src/Storage/Part/File.php @@ -48,7 +48,7 @@ public function __construct(array $params) fseek($this->fh, $params['startPos']); } $header = ''; - $endPos = isset($params['endPos']) ? $params['endPos'] : null; + $endPos = $params['endPos'] ?? null; while (($endPos === null || ftell($this->fh) < $endPos) && trim($line = fgets($this->fh))) { $header .= $line; } @@ -151,7 +151,10 @@ public function getPart($num) throw new Exception\RuntimeException('part not found'); } - return new static(['file' => $this->fh, 'startPos' => $this->partPos[$num][0], - 'endPos' => $this->partPos[$num][1]]); + return new static([ + 'file' => $this->fh, + 'startPos' => $this->partPos[$num][0], + 'endPos' => $this->partPos[$num][1], + ]); } } diff --git a/src/Storage/Pop3.php b/src/Storage/Pop3.php index 3549763a..ac1dbff6 100644 --- a/src/Storage/Pop3.php +++ b/src/Storage/Pop3.php @@ -60,8 +60,12 @@ public function getMessage($id) $bodyLines = 0; $message = $this->protocol->top($id, $bodyLines, true); - return new $this->messageClass(['handler' => $this, 'id' => $id, 'headers' => $message, - 'noToplines' => $bodyLines < 1]); + return new $this->messageClass([ + 'handler' => $this, + 'id' => $id, + 'headers' => $message, + 'noToplines' => $bodyLines < 1, + ]); } /* diff --git a/src/Storage/Writable/Maildir.php b/src/Storage/Writable/Maildir.php index b8c30174..58d678bd 100644 --- a/src/Storage/Writable/Maildir.php +++ b/src/Storage/Writable/Maildir.php @@ -51,9 +51,9 @@ public static function initMaildir($dir) throw new StorageException\InvalidArgumentException("parent $dir not found", 0, $error); } elseif (! is_dir($dir)) { throw new StorageException\InvalidArgumentException("parent $dir not a directory", 0, $error); - } else { - throw new StorageException\RuntimeException('cannot create maildir', 0, $error); } + + throw new StorageException\RuntimeException('cannot create maildir', 0, $error); } } @@ -390,10 +390,12 @@ protected function createTmpFile($folder = 'INBOX') ); } - return ['dirname' => $this->rootdir . '.' . $folder, - 'uniq' => $uniq, - 'filename' => $tmpdir . $uniq, - 'handle' => $fh]; + return [ + 'dirname' => $this->rootdir . '.' . $folder, + 'uniq' => $uniq, + 'filename' => $tmpdir . $uniq, + 'handle' => $fh, + ]; } /** @@ -495,9 +497,11 @@ public function appendMessage($message, $folder = null, $flags = null, $recent = throw $exception; } - $this->files[] = ['uniq' => $tempFile['uniq'], - 'flags' => $flags, - 'filename' => $newFilename]; + $this->files[] = [ + 'uniq' => $tempFile['uniq'], + 'flags' => $flags, + 'filename' => $newFilename, + ]; if ($this->quota) { $this->addQuotaEntry((int) $size, 1); } @@ -563,9 +567,11 @@ public function copyMessage($id, $folder) if ($folder->getGlobalName() == $this->currentFolder || ($this->currentFolder == 'INBOX' && $folder->getGlobalName() == '/') ) { - $this->files[] = ['uniq' => $tempFile['uniq'], - 'flags' => $flags, - 'filename' => $newFile]; + $this->files[] = [ + 'uniq' => $tempFile['uniq'], + 'flags' => $flags, + 'filename' => $newFile, + ]; } if ($this->quota) { @@ -650,7 +656,7 @@ public function setFlags($id, $flags) // NOTE: double dirname to make sure we always move to cur. if recent // flag has been set (message is in new) it will be moved to cur. - $newFilename = dirname(dirname($filedata['filename'])) + $newFilename = dirname($filedata['filename'], 2) . DIRECTORY_SEPARATOR . 'cur' . DIRECTORY_SEPARATOR @@ -841,9 +847,11 @@ protected function calculateMaildirsize() } } - return ['size' => $totalSize, - 'count' => $messages, - 'quota' => $quota]; + return [ + 'size' => $totalSize, + 'count' => $messages, + 'quota' => $quota, + ]; } /** @@ -921,10 +929,12 @@ protected function calculateQuota($forceRecalc = false) fclose($fh); } - return ['size' => $totalSize, - 'count' => $messages, - 'quota' => $quota, - 'over_quota' => $overQuota]; + return [ + 'size' => $totalSize, + 'count' => $messages, + 'quota' => $quota, + 'over_quota' => $overQuota, + ]; } protected function addQuotaEntry($size, $count = 1) diff --git a/src/Transport/Factory.php b/src/Transport/Factory.php index 88301aa4..45979ec7 100644 --- a/src/Transport/Factory.php +++ b/src/Transport/Factory.php @@ -45,7 +45,7 @@ public static function create($spec = []) )); } - $type = isset($spec['type']) ? $spec['type'] : 'sendmail'; + $type = $spec['type'] ?? 'sendmail'; $normalizedType = strtolower($type); @@ -61,7 +61,7 @@ public static function create($spec = []) )); } - $transport = new $type; + $transport = new $type(); if (! $transport instanceof TransportInterface) { throw new Exception\DomainException(sprintf( diff --git a/test/AddressListTest.php b/test/AddressListTest.php index 3c35d9ed..1d4d641a 100644 --- a/test/AddressListTest.php +++ b/test/AddressListTest.php @@ -24,69 +24,69 @@ class AddressListTest extends TestCase /** @var AddressList */ private $list; - public function setUp() + public function setUp(): void { $this->list = new AddressList(); } - public function testImplementsCountable() + public function testImplementsCountable(): void { $this->assertInstanceOf(\Countable::class, $this->list); } - public function testIsEmptyByDefault() + public function testIsEmptyByDefault(): void { $this->assertEquals(0, count($this->list)); } - public function testAddingEmailsIncreasesCount() + public function testAddingEmailsIncreasesCount(): void { $this->list->add('test@example.com'); $this->assertEquals(1, count($this->list)); } - public function testAddingEmailFromStringIncreasesCount() + public function testAddingEmailFromStringIncreasesCount(): void { $this->list->addFromString('test@example.com'); $this->assertEquals(1, count($this->list)); } - public function testImplementsTraversable() + public function testImplementsTraversable(): void { $this->assertInstanceOf(\Traversable::class, $this->list); } - public function testHasReturnsFalseWhenAddressNotInList() + public function testHasReturnsFalseWhenAddressNotInList(): void { $this->assertFalse($this->list->has('foo@example.com')); } - public function testHasReturnsTrueWhenAddressInList() + public function testHasReturnsTrueWhenAddressInList(): void { $this->list->add('test@example.com'); $this->assertTrue($this->list->has('test@example.com')); } - public function testGetReturnsFalseWhenEmailNotFound() + public function testGetReturnsFalseWhenEmailNotFound(): void { $this->assertFalse($this->list->get('foo@example.com')); } - public function testThrowExceptionOnInvalidInputAdd() + public function testThrowExceptionOnInvalidInputAdd(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('add expects an email address or Laminas\Mail\Address object'); $this->list->add(null); } - public function testThrowExceptionOnInvalidInputAddMany() + public function testThrowExceptionOnInvalidInputAddMany(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('add expects an email address or Laminas\Mail\Address object'); $this->list->addMany([null]); } - public function testGetReturnsAddressObjectWhenEmailFound() + public function testGetReturnsAddressObjectWhenEmailFound(): void { $this->list->add('test@example.com'); $address = $this->list->get('test@example.com'); @@ -94,7 +94,7 @@ public function testGetReturnsAddressObjectWhenEmailFound() $this->assertEquals('test@example.com', $address->getEmail()); } - public function testCanAddAddressWithName() + public function testCanAddAddressWithName(): void { $this->list->add('test@example.com', 'Example Test'); $address = $this->list->get('test@example.com'); @@ -103,7 +103,7 @@ public function testCanAddAddressWithName() $this->assertEquals('Example Test', $address->getName()); } - public function testCanAddManyAddressesAtOnce() + public function testCanAddManyAddressesAtOnce(): void { $addresses = [ 'test@example.com', @@ -117,7 +117,7 @@ public function testCanAddManyAddressesAtOnce() $this->assertTrue($this->list->has('announce@example.com')); } - public function testCanAddFromStringFluently() + public function testCanAddFromStringFluently(): void { $this->list->addFromString('test_fromstring_fluency1@example.com') ->addFromString('test_fromstring_fluency2@example.com'); @@ -126,7 +126,7 @@ public function testCanAddFromStringFluently() $this->assertTrue($this->list->has('test_fromstring_fluency2@example.com')); } - public function testLosesParensInName() + public function testLosesParensInName(): void { $header = '"Supports (E-mail)" '; @@ -138,7 +138,7 @@ public function testLosesParensInName() $this->assertEquals('support@example.org', $address->getEmail()); } - public function testDoesNotStoreDuplicatesAndFirstWins() + public function testDoesNotStoreDuplicatesAndFirstWins(): void { $addresses = [ 'test@example.com', @@ -156,7 +156,7 @@ public function testDoesNotStoreDuplicatesAndFirstWins() * * @see https://blogs.msdn.microsoft.com/oldnewthing/20150119-00/?p=44883 */ - public function testSemicolonSeparator() + public function testSemicolonSeparator(): void { $header = 'Some User ; uzer2.surname@example.org;' . ' asda.fasd@example.net, root@example.org'; @@ -176,7 +176,7 @@ public function testSemicolonSeparator() $this->assertTrue($addressList->has('root@example.org')); } - public function testMergeTwoLists() + public function testMergeTwoLists(): void { $otherList = new AddressList(); $this->list->add('one@example.net'); @@ -185,19 +185,19 @@ public function testMergeTwoLists() $this->assertEquals(2, count($this->list)); } - public function testDeleteSuccess() + public function testDeleteSuccess(): void { $this->list->add('test@example.com'); $this->assertTrue($this->list->delete('test@example.com')); $this->assertEquals(0, count($this->list)); } - public function testDeleteNotExist() + public function testDeleteNotExist(): void { $this->assertFalse($this->list->delete('test@example.com')); } - public function testKey() + public function testKey(): void { $this->assertNull($this->list->key()); $this->list->add('test@example.com'); @@ -214,7 +214,7 @@ public function testKey() /** * If name-field is quoted with "", then ' inside it should not treated as terminator, but as value. */ - public function testMixedQuotesInName() + public function testMixedQuotesInName(): void { $header = '"Bob O\'Reilly" ,blah@example.com'; diff --git a/test/AddressTest.php b/test/AddressTest.php index 596b109a..a19d555e 100644 --- a/test/AddressTest.php +++ b/test/AddressTest.php @@ -17,21 +17,21 @@ */ class AddressTest extends TestCase { - public function testDoesNotRequireNameForInstantiation() + public function testDoesNotRequireNameForInstantiation(): void { $address = new Address('test@example.com'); $this->assertEquals('test@example.com', $address->getEmail()); $this->assertNull($address->getName()); } - public function testAcceptsNameViaConstructor() + public function testAcceptsNameViaConstructor(): void { $address = new Address('test@example.com', 'Example Test'); $this->assertEquals('test@example.com', $address->getEmail()); $this->assertEquals('Example Test', $address->getName()); } - public function testToStringCreatesStringRepresentation() + public function testToStringCreatesStringRepresentation(): void { $address = new Address('test@example.com', 'Example Test'); $this->assertEquals('Example Test ', $address->toString()); @@ -43,13 +43,13 @@ public function testToStringCreatesStringRepresentation() * @param string $email * @param null|string $name */ - public function testSetAddressInvalidAddressObject($email, $name) + public function testSetAddressInvalidAddressObject($email, $name): void { $this->expectException(Exception\InvalidArgumentException::class); new Address($email, $name); } - public function invalidSenderDataProvider() + public function invalidSenderDataProvider(): array { return [ // Description => [sender address, sender name], @@ -74,13 +74,13 @@ public function invalidSenderDataProvider() * @param string $email * @param null|string $name */ - public function testSetAddressValidAddressObject($email, $name) + public function testSetAddressValidAddressObject($email, $name): void { $address = new Address($email, $name); $this->assertInstanceOf(Address::class, $address); } - public function validSenderDataProvider() + public function validSenderDataProvider(): array { return [ // Description => [sender address, sender name], diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index 03588200..bd3b7ebd 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -17,7 +17,7 @@ */ class ConfigProviderTest extends TestCase { - public function testInvoke() + public function testInvoke(): void { $configProvider = new ConfigProvider(); $config = $configProvider(); diff --git a/test/Header/AddressListHeaderTest.php b/test/Header/AddressListHeaderTest.php index 2822bc25..1fac03b9 100644 --- a/test/Header/AddressListHeaderTest.php +++ b/test/Header/AddressListHeaderTest.php @@ -23,7 +23,7 @@ */ class AddressListHeaderTest extends TestCase { - public static function getHeaderInstances() + public static function getHeaderInstances(): array { return [ [new Bcc(), 'Bcc'], @@ -37,7 +37,7 @@ public static function getHeaderInstances() /** * @dataProvider getHeaderInstances */ - public function testConcreteHeadersExtendAbstractAddressListHeader($header) + public function testConcreteHeadersExtendAbstractAddressListHeader($header): void { $this->assertInstanceOf(AbstractAddressList::class, $header); } @@ -45,7 +45,7 @@ public function testConcreteHeadersExtendAbstractAddressListHeader($header) /** * @dataProvider getHeaderInstances */ - public function testConcreteHeaderFieldNamesAreDiscrete($header, $type) + public function testConcreteHeaderFieldNamesAreDiscrete($header, $type): void { $this->assertEquals($type, $header->getFieldName()); } @@ -53,19 +53,19 @@ public function testConcreteHeaderFieldNamesAreDiscrete($header, $type) /** * @dataProvider getHeaderInstances */ - public function testConcreteHeadersComposeAddressLists($header) + public function testConcreteHeadersComposeAddressLists($header): void { $list = $header->getAddressList(); $this->assertInstanceOf(AddressList::class, $list); } - public function testFieldValueIsEmptyByDefault() + public function testFieldValueIsEmptyByDefault(): void { $header = new To(); $this->assertEquals('', $header->getFieldValue()); } - public function testFieldValueIsCreatedFromAddressList() + public function testFieldValueIsCreatedFromAddressList(): void { $header = new To(); $list = $header->getAddressList(); @@ -74,7 +74,7 @@ public function testFieldValueIsCreatedFromAddressList() $this->assertEquals($expected, $header->getFieldValue()); } - public function populateAddressList(AddressList $list) + public function populateAddressList(AddressList $list): void { $address = new Address('test@example.com', 'Example Test'); $list->add($address); @@ -83,7 +83,7 @@ public function populateAddressList(AddressList $list) $list->add('first@last.example.com', 'Last, First'); } - public function getExpectedFieldValue() + public function getExpectedFieldValue(): string { // @codingStandardsIgnoreStart return "Example Test ,\r\n list@example.com,\r\n Example Announce List ,\r\n \"Last, First\" "; @@ -93,14 +93,14 @@ public function getExpectedFieldValue() /** * @dataProvider getHeaderInstances */ - public function testStringRepresentationIncludesHeaderAndFieldValue($header, $type) + public function testStringRepresentationIncludesHeaderAndFieldValue($header, $type): void { $this->populateAddressList($header->getAddressList()); $expected = sprintf('%s: %s', $type, $this->getExpectedFieldValue()); $this->assertEquals($expected, $header->toString()); } - public function getStringHeaders() + public function getStringHeaders(): array { $value = $this->getExpectedFieldValue(); return [ @@ -115,7 +115,7 @@ public function getStringHeaders() /** * @dataProvider getStringHeaders */ - public function testDeserializationFromString($headerLine, $class) + public function testDeserializationFromString($headerLine, $class): void { $callback = sprintf('%s::fromString', $class); $header = $callback($headerLine); @@ -136,7 +136,7 @@ public function testDeserializationFromString($headerLine, $class) $this->assertEquals('Last, First', $address->getName()); } - public function getStringHeadersWithNoWhitespaceSeparator() + public function getStringHeadersWithNoWhitespaceSeparator(): array { $value = $this->getExpectedFieldValue(); return [ @@ -151,7 +151,7 @@ public function getStringHeadersWithNoWhitespaceSeparator() /** * @dataProvider getHeadersWithComments */ - public function testDeserializationFromStringWithComments($value) + public function testDeserializationFromStringWithComments($value): void { $header = From::fromString($value); $list = $header->getAddressList(); @@ -159,7 +159,7 @@ public function testDeserializationFromStringWithComments($value) $this->assertTrue($list->has('user@example.com')); } - public function getHeadersWithComments() + public function getHeadersWithComments(): array { return [ ['From: user@example.com (Comment)'], @@ -172,7 +172,7 @@ public function getHeadersWithComments() * @group 3789 * @dataProvider getStringHeadersWithNoWhitespaceSeparator */ - public function testAllowsNoWhitespaceBetweenHeaderAndValue($headerLine, $class) + public function testAllowsNoWhitespaceBetweenHeaderAndValue($headerLine, $class): void { $callback = sprintf('%s::fromString', $class); $header = $callback($headerLine); @@ -196,7 +196,7 @@ public function testAllowsNoWhitespaceBetweenHeaderAndValue($headerLine, $class) /** * @dataProvider getAddressListsWithGroup */ - public function testAddressListWithGroup($input, $count, $sample) + public function testAddressListWithGroup($input, $count, $sample): void { $header = To::fromString($input); $list = $header->getAddressList(); @@ -206,7 +206,7 @@ public function testAddressListWithGroup($input, $count, $sample) } } - public function getAddressListsWithGroup() + public function getAddressListsWithGroup(): array { return [ ['To: undisclosed-recipients:;', 0, null], @@ -214,26 +214,26 @@ public function getAddressListsWithGroup() ]; } - public function specialCharHeaderProvider() + public function specialCharHeaderProvider(): array { return [ [ "To: =?UTF-8?B?dGVzdCxsYWJlbA==?= , john2@example.com", ['john@example.com' => 'test,label', 'john2@example.com' => null], - 'UTF-8' + 'UTF-8', ], [ 'To: "TEST\",QUOTE" , john2@example.com', ['john@example.com' => 'TEST",QUOTE', 'john2@example.com' => null], - 'ASCII' - ] + 'ASCII', + ], ]; } /** * @dataProvider specialCharHeaderProvider */ - public function testDeserializationFromSpecialCharString($headerLine, $expected, $encoding) + public function testDeserializationFromSpecialCharString($headerLine, $expected, $encoding): void { $header = To::fromString($headerLine); diff --git a/test/Header/ContentDispositionTest.php b/test/Header/ContentDispositionTest.php index e62f2774..fdfbaaac 100644 --- a/test/Header/ContentDispositionTest.php +++ b/test/Header/ContentDispositionTest.php @@ -20,7 +20,7 @@ */ class ContentDispositionTest extends TestCase { - public function testImplementsHeaderInterface() + public function testImplementsHeaderInterface(): void { $header = new ContentDisposition(); @@ -28,7 +28,7 @@ public function testImplementsHeaderInterface() $this->assertInstanceOf(HeaderInterface::class, $header); } - public function testTrailingSemiColonFromString() + public function testTrailingSemiColonFromString(): void { $contentTypeHeader = ContentDisposition::fromString( 'Content-Disposition: attachment; filename="test-case.txt";' @@ -37,20 +37,20 @@ public function testTrailingSemiColonFromString() $this->assertEquals(['filename' => 'test-case.txt'], $params); } - public static function getLiteralData() + public static function getLiteralData(): array { return [ [ ['filename' => 'foo; bar.txt'], - 'attachment; filename="foo; bar.txt"' + 'attachment; filename="foo; bar.txt"', ], [ ['filename' => 'foo&bar.txt'], - 'attachment; filename="foo&bar.txt"' + 'attachment; filename="foo&bar.txt"', ], [ [], - 'inline' + 'inline', ], ]; } @@ -58,7 +58,7 @@ public static function getLiteralData() /** * @dataProvider getLiteralData */ - public function testHandlesLiterals($expected, $header) + public function testHandlesLiterals($expected, $header): void { $header = ContentDisposition::fromString('Content-Disposition: ' . $header); $this->assertEquals($expected, $header->getParameters()); @@ -67,7 +67,7 @@ public function testHandlesLiterals($expected, $header) /** * @dataProvider setDispositionProvider */ - public function testFromString($disposition, $parameters, $fieldValue, $expectedToString) + public function testFromString($disposition, $parameters, $fieldValue, $expectedToString): void { $header = ContentDisposition::fromString($expectedToString); @@ -82,7 +82,7 @@ public function testFromString($disposition, $parameters, $fieldValue, $expected /** * @dataProvider setDispositionProvider */ - public function testSetDisposition($disposition, $parameters, $fieldValue, $expectedToString) + public function testSetDisposition($disposition, $parameters, $fieldValue, $expectedToString): void { $header = new ContentDisposition(); @@ -98,7 +98,7 @@ public function testSetDisposition($disposition, $parameters, $fieldValue, $expe $this->assertEquals($expectedToString, $header->toString(), 'toString() value not match'); } - public function testGetSetEncoding() + public function testGetSetEncoding(): void { $header = new ContentDisposition(); @@ -115,14 +115,14 @@ public function testGetSetEncoding() /** * @dataProvider invalidHeaderLinesProvider */ - public function testFromStringThrowException($headerLine, $expectedException, $exceptionMessage) + public function testFromStringThrowException($headerLine, $expectedException, $exceptionMessage): void { $this->expectException($expectedException); $this->expectExceptionMessage($exceptionMessage); ContentDisposition::fromString($headerLine); } - public function testFromStringHandlesContinuations() + public function testFromStringHandlesContinuations(): void { $header = ContentDisposition::fromString("Content-Disposition: attachment;\r\n level=1"); $this->assertEquals('attachment', $header->getDisposition()); @@ -132,7 +132,7 @@ public function testFromStringHandlesContinuations() /** * @dataProvider invalidParametersProvider */ - public function testSetParameterThrowException($paramName, $paramValue, $expectedException, $exceptionMessage) + public function testSetParameterThrowException($paramName, $paramValue, $expectedException, $exceptionMessage): void { $header = new ContentDisposition(); $header->setDisposition('attachment'); @@ -145,13 +145,13 @@ public function testSetParameterThrowException($paramName, $paramValue, $expecte /** * @dataProvider getParameterProvider */ - public function testGetParameter($fromString, $paramName, $paramValue) + public function testGetParameter($fromString, $paramName, $paramValue): void { $header = ContentDisposition::fromString($fromString); $this->assertEquals($paramValue, $header->getParameter($paramName)); } - public function testRemoveParameter() + public function testRemoveParameter(): void { $header = ContentDisposition::fromString('Content-Disposition: inline'); @@ -161,7 +161,7 @@ public function testRemoveParameter() $this->assertEquals(true, $header->removeParameter('name')); } - public function setDispositionProvider() + public function setDispositionProvider(): array { // @codingStandardsIgnoreStart $foldingFieldValue = "attachment;\r\n filename=\"this-test-filename-is-long-enough-to-flow-to-two-lines.txt\""; @@ -201,7 +201,7 @@ public function setDispositionProvider() // @codingStandardsIgnoreEnd } - public function invalidParametersProvider() + public function invalidParametersProvider(): array { $invalidArgumentException = InvalidArgumentException::class; @@ -214,7 +214,7 @@ public function invalidParametersProvider() // @codingStandardsIgnoreEnd } - public function invalidHeaderLinesProvider() + public function invalidHeaderLinesProvider(): array { $invalidArgumentException = InvalidArgumentException::class; @@ -226,12 +226,12 @@ public function invalidHeaderLinesProvider() 'newline' => ["Content-Disposition: inline;\nlevel=1", $invalidArgumentException, 'header value'], 'cr-lf' => ["Content-Disposition: inline\r\n;level=1", $invalidArgumentException, 'header value'], 'multiline' => ["Content-Disposition: inline;\r\nlevel=1\r\nq=0.1", $invalidArgumentException, 'header value'], - 'incomplete sequence' => ["Content-Disposition: attachment;\r\n filename*0=\"first-part\";\r\n filename*2=\"third-part\"", $invalidArgumentException, 'incomplete continuation'] + 'incomplete sequence' => ["Content-Disposition: attachment;\r\n filename*0=\"first-part\";\r\n filename*2=\"third-part\"", $invalidArgumentException, 'incomplete continuation'], ]; // @codingStandardsIgnoreEnd } - public function getParameterProvider() + public function getParameterProvider(): array { // @codingStandardsIgnoreStart return [ @@ -242,7 +242,7 @@ public function getParameterProvider() "Content-Disposition: attachment;\r\n filename*0=\"this-file-name-is-so-long-that-it-does-not-even\";\r\n filename*1=\"-fit-on-a-whole-line-by-itself-so-we-need-to-sp\";\r\n filename*2=\"lit-it-with-value-continuation.txt\"", 'filename', 'this-file-name-is-so-long-that-it-does-not-even-fit-on-a-whole-line-by-itself-so-we-need-to-split-it-with-value-continuation.txt', - ] + ], ]; // @codingStandardsIgnoreEnd } diff --git a/test/Header/ContentTransferEncodingTest.php b/test/Header/ContentTransferEncodingTest.php index 91f15251..913e0306 100644 --- a/test/Header/ContentTransferEncodingTest.php +++ b/test/Header/ContentTransferEncodingTest.php @@ -19,7 +19,7 @@ */ class ContentTransferEncodingTest extends TestCase { - public function dataValidEncodings() + public function dataValidEncodings(): array { return [ ['7bit'], @@ -29,7 +29,7 @@ public function dataValidEncodings() ]; } - public function dataInvalidEncodings() + public function dataInvalidEncodings(): array { return [ ['9bit'], @@ -40,7 +40,7 @@ public function dataInvalidEncodings() /** * @dataProvider dataValidEncodings */ - public function testContentTransferEncodingFromStringCreatesValidContentTransferEncodingHeader($encoding) + public function testContentTransferEncodingFromStringCreatesValidContentTransferEncodingHeader($encoding): void { $contentTransferEncodingHeader = ContentTransferEncoding::fromString('Content-Transfer-Encoding: '.$encoding); $this->assertInstanceOf(HeaderInterface::class, $contentTransferEncodingHeader); @@ -50,13 +50,13 @@ public function testContentTransferEncodingFromStringCreatesValidContentTransfer /** * @dataProvider dataInvalidEncodings */ - public function testContentTransferEncodingFromStringRaisesException($encoding) + public function testContentTransferEncodingFromStringRaisesException($encoding): void { $this->expectException(Exception\InvalidArgumentException::class); $contentTransferEncodingHeader = ContentTransferEncoding::fromString('Content-Transfer-Encoding: '.$encoding); } - public function testContentTransferEncodingGetFieldNameReturnsHeaderName() + public function testContentTransferEncodingGetFieldNameReturnsHeaderName(): void { $contentTransferEncodingHeader = new ContentTransferEncoding(); $this->assertEquals('Content-Transfer-Encoding', $contentTransferEncodingHeader->getFieldName()); @@ -65,7 +65,7 @@ public function testContentTransferEncodingGetFieldNameReturnsHeaderName() /** * @dataProvider dataValidEncodings */ - public function testContentTransferEncodingGetFieldValueReturnsProperValue($encoding) + public function testContentTransferEncodingGetFieldValueReturnsProperValue($encoding): void { $contentTransferEncodingHeader = new ContentTransferEncoding(); $contentTransferEncodingHeader->setTransferEncoding($encoding); @@ -76,7 +76,7 @@ public function testContentTransferEncodingGetFieldValueReturnsProperValue($enco /** * @dataProvider dataValidEncodings */ - public function testContentTransferEncodingHandlesCaseInsensitivity($encoding) + public function testContentTransferEncodingHandlesCaseInsensitivity($encoding): void { $header = new ContentTransferEncoding(); $header->setTransferEncoding(strtoupper(substr($encoding, 0, 4)).substr($encoding, 4)); @@ -86,14 +86,14 @@ public function testContentTransferEncodingHandlesCaseInsensitivity($encoding) /** * @dataProvider dataValidEncodings */ - public function testContentTransferEncodingToStringReturnsHeaderFormattedString($encoding) + public function testContentTransferEncodingToStringReturnsHeaderFormattedString($encoding): void { $contentTransferEncodingHeader = new ContentTransferEncoding(); $contentTransferEncodingHeader->setTransferEncoding($encoding); $this->assertEquals("Content-Transfer-Encoding: ".$encoding, $contentTransferEncodingHeader->toString()); } - public function testProvidingParametersIntroducesHeaderFolding() + public function testProvidingParametersIntroducesHeaderFolding(): void { $header = new ContentTransferEncoding(); $header->setTransferEncoding('quoted-printable'); @@ -105,13 +105,13 @@ public function testProvidingParametersIntroducesHeaderFolding() /** * @group ZF2015-04 */ - public function testFromStringRaisesExceptionOnInvalidHeaderName() + public function testFromStringRaisesExceptionOnInvalidHeaderName(): void { $this->expectException(Exception\InvalidArgumentException::class); ContentTransferEncoding::fromString('Content-Transfer-Encoding' . chr(32) . ': 8bit'); } - public function headerLines() + public function headerLines(): array { return [ 'newline' => ["Content-Transfer-Encoding: 8bit\n7bit"], @@ -124,7 +124,7 @@ public function headerLines() * @dataProvider headerLines * @group ZF2015-04 */ - public function testFromStringRaisesExceptionForInvalidMultilineValues($headerLine) + public function testFromStringRaisesExceptionForInvalidMultilineValues($headerLine): void { $this->expectException(Exception\InvalidArgumentException::class); ContentTransferEncoding::fromString($headerLine); @@ -133,7 +133,7 @@ public function testFromStringRaisesExceptionForInvalidMultilineValues($headerLi /** * @group ZF2015-04 */ - public function testFromStringRaisesExceptionForContinuations() + public function testFromStringRaisesExceptionForContinuations(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('expects'); @@ -143,7 +143,7 @@ public function testFromStringRaisesExceptionForContinuations() /** * @group ZF2015-04 */ - public function testSetTransferEncodingRaisesExceptionForInvalidValues() + public function testSetTransferEncodingRaisesExceptionForInvalidValues(): void { $header = new ContentTransferEncoding(); $this->expectException(Exception\InvalidArgumentException::class); @@ -151,22 +151,22 @@ public function testSetTransferEncodingRaisesExceptionForInvalidValues() $header->setTransferEncoding("8bit\r\n 7bit"); } - public function testFromStringRaisesExceptionOnInvalidHeader() + public function testFromStringRaisesExceptionOnInvalidHeader(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid header line for Content-Transfer-Encoding string'); ContentTransferEncoding::fromString('Foo: bar'); } - public function testDefaultEncoding() + public function testDefaultEncoding(): void { - $header = new ContentTransferEncoding('today'); + $header = new ContentTransferEncoding(); $this->assertSame('ASCII', $header->getEncoding()); } - public function testChangeEncodingHasNoEffect() + public function testChangeEncodingHasNoEffect(): void { - $header = new ContentTransferEncoding('today'); + $header = new ContentTransferEncoding(); $header->setEncoding('UTF-8'); $this->assertSame('ASCII', $header->getEncoding()); } diff --git a/test/Header/ContentTypeTest.php b/test/Header/ContentTypeTest.php index 4d3f9b3a..7cb504e6 100644 --- a/test/Header/ContentTypeTest.php +++ b/test/Header/ContentTypeTest.php @@ -20,7 +20,7 @@ */ class ContentTypeTest extends TestCase { - public function testImplementsHeaderInterface() + public function testImplementsHeaderInterface(): void { $header = new ContentType(); @@ -31,7 +31,7 @@ public function testImplementsHeaderInterface() /** * @group 6491 */ - public function testTrailingSemiColonFromString() + public function testTrailingSemiColonFromString(): void { $contentTypeHeader = ContentType::fromString( 'Content-Type: multipart/alternative; boundary="Apple-Mail=_1B852F10-F9C6-463D-AADD-CD503A5428DD";' @@ -40,22 +40,22 @@ public function testTrailingSemiColonFromString() $this->assertEquals(['boundary' => 'Apple-Mail=_1B852F10-F9C6-463D-AADD-CD503A5428DD'], $params); } - public function testExtractsExtraInformationWithoutBeingConfusedByTrailingSemicolon() + public function testExtractsExtraInformationWithoutBeingConfusedByTrailingSemicolon(): void { $header = ContentType::fromString('Content-Type: application/pdf;name="foo.pdf";'); $this->assertEquals($header->getParameters(), ['name' => 'foo.pdf']); } - public static function getLiteralData() + public static function getLiteralData(): array { return [ [ ['name' => 'foo; bar.txt'], - 'text/plain; name="foo; bar.txt"' + 'text/plain; name="foo; bar.txt"', ], [ ['name' => 'foo&bar.txt'], - 'text/plain; name="foo&bar.txt"' + 'text/plain; name="foo&bar.txt"', ], ]; } @@ -63,7 +63,7 @@ public static function getLiteralData() /** * @dataProvider getLiteralData */ - public function testHandlesLiterals(array $expected, $header) + public function testHandlesLiterals(array $expected, $header): void { $header = ContentType::fromString('Content-Type: '.$header); $this->assertEquals($expected, $header->getParameters()); @@ -72,7 +72,7 @@ public function testHandlesLiterals(array $expected, $header) /** * @dataProvider setTypeProvider */ - public function testFromString($type, $parameters, $fieldValue, $expectedToString) + public function testFromString($type, $parameters, $fieldValue, $expectedToString): void { $header = ContentType::fromString($expectedToString); @@ -87,7 +87,7 @@ public function testFromString($type, $parameters, $fieldValue, $expectedToStrin /** * @dataProvider setTypeProvider */ - public function testSetType($type, $parameters, $fieldValue, $expectedToString) + public function testSetType($type, $parameters, $fieldValue, $expectedToString): void { $header = new ContentType(); @@ -106,7 +106,7 @@ public function testSetType($type, $parameters, $fieldValue, $expectedToString) /** * @dataProvider invalidHeaderLinesProvider */ - public function testFromStringThrowException($headerLine, $expectedException, $exceptionMessage) + public function testFromStringThrowException($headerLine, $expectedException, $exceptionMessage): void { $this->expectException($expectedException); $this->expectExceptionMessage($exceptionMessage); @@ -116,7 +116,7 @@ public function testFromStringThrowException($headerLine, $expectedException, $e /** * @group ZF2015-04 */ - public function testFromStringHandlesContinuations() + public function testFromStringHandlesContinuations(): void { $header = ContentType::fromString("Content-Type: text/html;\r\n level=1"); $this->assertEquals('text/html', $header->getType()); @@ -126,7 +126,7 @@ public function testFromStringHandlesContinuations() /** * @dataProvider invalidParametersProvider */ - public function testAddParameterThrowException($paramName, $paramValue, $expectedException, $exceptionMessage) + public function testAddParameterThrowException($paramName, $paramValue, $expectedException, $exceptionMessage): void { $header = new ContentType(); $header->setType('text/html'); @@ -136,7 +136,7 @@ public function testAddParameterThrowException($paramName, $paramValue, $expecte $header->addParameter($paramName, $paramValue); } - public function setTypeProvider() + public function setTypeProvider(): array { $foldingHeaderLine = "Content-Type: foo/baz;\r\n charset=\"us-ascii\""; $foldingFieldValue = "foo/baz;\r\n charset=\"us-ascii\""; @@ -157,7 +157,7 @@ public function setTypeProvider() // @codingStandardsIgnoreEnd } - public function invalidParametersProvider() + public function invalidParametersProvider(): array { $invalidArgumentException = Exception\InvalidArgumentException::class; @@ -171,7 +171,7 @@ public function invalidParametersProvider() // @codingStandardsIgnoreEnd } - public function invalidHeaderLinesProvider() + public function invalidHeaderLinesProvider(): array { $invalidArgumentException = Exception\InvalidArgumentException::class; @@ -188,27 +188,27 @@ public function invalidHeaderLinesProvider() // @codingStandardsIgnoreEnd } - public function testFromStringRaisesExceptionOnInvalidHeader() + public function testFromStringRaisesExceptionOnInvalidHeader(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid header line for Content-Type string'); ContentType::fromString('Foo: bar'); } - public function testDefaultEncoding() + public function testDefaultEncoding(): void { - $header = new ContentType('today'); + $header = new ContentType(); $this->assertSame('ASCII', $header->getEncoding()); } - public function testSetEncoding() + public function testSetEncoding(): void { - $header = new ContentType('today'); + $header = new ContentType(); $header->setEncoding('UTF-8'); $this->assertSame('UTF-8', $header->getEncoding()); } - public function testSetTypeThrowsOnInvalidValue() + public function testSetTypeThrowsOnInvalidValue(): void { $header = new ContentType(); $this->expectException(Exception\InvalidArgumentException::class); @@ -216,31 +216,31 @@ public function testSetTypeThrowsOnInvalidValue() $header->setType('invalid'); } - public function testGetParameter() + public function testGetParameter(): void { $header = ContentType::fromString('content-type: text/plain; level=top'); $this->assertSame('top', $header->getParameter('level')); } - public function testGetParameterWithSpaceTrimmed() + public function testGetParameterWithSpaceTrimmed(): void { $header = ContentType::fromString('content-type: text/plain; level=top; name="logfile.log";'); $this->assertSame('logfile.log', $header->getParameter('name')); } - public function testGetParameterNotExists() + public function testGetParameterNotExists(): void { $header = ContentType::fromString('content-type: text/plain'); $this->assertNull($header->getParameter('level')); } - public function testRemoveParameter() + public function testRemoveParameter(): void { $header = ContentType::fromString('content-type: text/plain; level=top'); $this->assertTrue($header->removeParameter('level')); } - public function testRemoveParameterNotExists() + public function testRemoveParameterNotExists(): void { $header = ContentType::fromString('content-type: text/plain'); $this->assertFalse($header->removeParameter('level')); diff --git a/test/Header/DateTest.php b/test/Header/DateTest.php index 2d36950f..940b8885 100644 --- a/test/Header/DateTest.php +++ b/test/Header/DateTest.php @@ -17,7 +17,7 @@ */ class DateTest extends TestCase { - public function headerLines() + public function headerLines(): array { return [ 'newline' => ["Date: xxx yyy\n"], @@ -31,7 +31,7 @@ public function headerLines() * @dataProvider headerLines * @group ZF2015-04 */ - public function testFromStringRaisesExceptionOnCrlfInjectionAttempt($header) + public function testFromStringRaisesExceptionOnCrlfInjectionAttempt($header): void { $this->expectException(Exception\InvalidArgumentException::class); Header\Date::fromString($header); @@ -40,33 +40,33 @@ public function testFromStringRaisesExceptionOnCrlfInjectionAttempt($header) /** * @group ZF2015-04 */ - public function testPreventsCRLFInjectionViaConstructor() + public function testPreventsCRLFInjectionViaConstructor(): void { $this->expectException(Exception\InvalidArgumentException::class); $address = new Header\Date("This\ris\r\na\nCRLF Attack"); } - public function testFromStringRaisesExceptionOnInvalidHeader() + public function testFromStringRaisesExceptionOnInvalidHeader(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid header line for Date string'); Header\Date::fromString('Foo: bar'); } - public function testDefaultEncoding() + public function testDefaultEncoding(): void { $header = new Header\Date('today'); $this->assertSame('ASCII', $header->getEncoding()); } - public function testSetEncodingHasNoEffect() + public function testSetEncodingHasNoEffect(): void { $header = new Header\Date('today'); $header->setEncoding('UTF-8'); $this->assertSame('ASCII', $header->getEncoding()); } - public function testToString() + public function testToString(): void { $header = new Header\Date('today'); $this->assertEquals('Date: today', $header->toString()); diff --git a/test/Header/GenericHeaderTest.php b/test/Header/GenericHeaderTest.php index b655b12e..eca46fe6 100644 --- a/test/Header/GenericHeaderTest.php +++ b/test/Header/GenericHeaderTest.php @@ -17,7 +17,7 @@ */ class GenericHeaderTest extends TestCase { - public function invalidHeaderLines() + public function invalidHeaderLines(): array { return [ 'append-chr-32' => [ @@ -39,14 +39,14 @@ public function invalidHeaderLines() * @dataProvider invalidHeaderLines * @group ZF2015-04 */ - public function testSplitHeaderLineRaisesExceptionOnInvalidHeader($line, $message) + public function testSplitHeaderLineRaisesExceptionOnInvalidHeader($line, $message): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage($message); GenericHeader::splitHeaderLine($line); } - public function fieldNames() + public function fieldNames(): array { return [ 'append-chr-13' => ["Subject" . chr(13)], @@ -59,7 +59,7 @@ public function fieldNames() * @dataProvider fieldNames * @group ZF2015-04 */ - public function testRaisesExceptionOnInvalidFieldName($fieldName) + public function testRaisesExceptionOnInvalidFieldName($fieldName): void { $header = new GenericHeader(); $this->expectException(Exception\InvalidArgumentException::class); @@ -67,7 +67,7 @@ public function testRaisesExceptionOnInvalidFieldName($fieldName) $header->setFieldName($fieldName); } - public function fieldValues() + public function fieldValues(): array { return [ 'empty-lines' => ["\n\n\r\n\r\n\n"], @@ -86,7 +86,7 @@ public function fieldValues() * @group ZF2015-04 * @param string $fieldValue */ - public function testCRLFsequencesAreEncodedOnToString($fieldValue) + public function testCRLFsequencesAreEncodedOnToString($fieldValue): void { $header = new GenericHeader('Foo'); $header->setFieldValue($fieldValue); @@ -103,7 +103,7 @@ public function testCRLFsequencesAreEncodedOnToString($fieldValue) * @param string $encodedValue * @param string $encoding */ - public function testParseValidSubjectHeader($decodedValue, $encodedValue, $encoding) + public function testParseValidSubjectHeader($decodedValue, $encodedValue, $encoding): void { $header = GenericHeader::fromString('Foo:' . $encodedValue); @@ -118,7 +118,7 @@ public function testParseValidSubjectHeader($decodedValue, $encodedValue, $encod * @param string $encodedValue * @param string $encoding */ - public function testSetFieldValueValidValue($decodedValue, $encodedValue, $encoding) + public function testSetFieldValueValidValue($decodedValue, $encodedValue, $encoding): void { $header = new GenericHeader('Foo'); $header->setFieldValue($decodedValue); @@ -128,7 +128,7 @@ public function testSetFieldValueValidValue($decodedValue, $encodedValue, $encod $this->assertEquals($encoding, $header->getEncoding()); } - public function validFieldValuesProvider() + public function validFieldValuesProvider(): array { return [ // Description => [decoded format, encoded format, encoding], @@ -149,7 +149,7 @@ public function validFieldValuesProvider() /** * @group ZF2015-04 */ - public function testCastingToStringHandlesContinuationsProperly() + public function testCastingToStringHandlesContinuationsProperly(): void { $encoded = '=?UTF-8?Q?foo=0D=0A=20bar?='; $raw = "foo\r\n bar"; @@ -162,36 +162,36 @@ public function testCastingToStringHandlesContinuationsProperly() $this->assertEquals('Foo: ' . $encoded, $header->toString()); } - public function testAllowZeroInHeaderValueInConstructor() + public function testAllowZeroInHeaderValueInConstructor(): void { $header = new GenericHeader('Foo', 0); $this->assertEquals(0, $header->getFieldValue()); $this->assertEquals('Foo: 0', $header->toString()); } - public function testDefaultEncoding() + public function testDefaultEncoding(): void { $header = new GenericHeader('Foo'); $this->assertSame('ASCII', $header->getEncoding()); } - public function testSetEncoding() + public function testSetEncoding(): void { $header = new GenericHeader('Foo'); $header->setEncoding('UTF-8'); $this->assertSame('UTF-8', $header->getEncoding()); } - public function testToStringThrowsWithoutFieldName() + public function testToStringThrowsWithoutFieldName(): void { - $header = new GenericHeader; + $header = new GenericHeader(); $this->expectException(Exception\RuntimeException::class); $this->expectExceptionMessage('Header name is not set, use setFieldName()'); $header->toString(); } - public function testChangeEncodingToAsciiNotAllowedWhenHeaderValueContainsUtf8Characters() + public function testChangeEncodingToAsciiNotAllowedWhenHeaderValueContainsUtf8Characters(): void { $subject = new GenericHeader(); $subject->setFieldValue('Accents òàùèéì'); @@ -202,7 +202,7 @@ public function testChangeEncodingToAsciiNotAllowedWhenHeaderValueContainsUtf8Ch self::assertSame('UTF-8', $subject->getEncoding()); } - public function testChangeEncodingBackToAscii() + public function testChangeEncodingBackToAscii(): void { $subject = new GenericHeader('X-Test'); $subject->setFieldValue('test'); @@ -216,7 +216,7 @@ public function testChangeEncodingBackToAscii() self::assertSame('ASCII', $subject->getEncoding()); } - public function testSetNullEncoding() + public function testSetNullEncoding(): void { $subject = GenericHeader::fromString('X-Test: test'); self::assertSame('ASCII', $subject->getEncoding()); @@ -225,7 +225,7 @@ public function testSetNullEncoding() self::assertSame('ASCII', $subject->getEncoding()); } - public function testSettingFieldValueCanChangeEncoding() + public function testSettingFieldValueCanChangeEncoding(): void { $subject = GenericHeader::fromString('X-Test: test'); self::assertSame('ASCII', $subject->getEncoding()); @@ -234,7 +234,7 @@ public function testSettingFieldValueCanChangeEncoding() self::assertSame('UTF-8', $subject->getEncoding()); } - public function testSettingTheSameEncoding() + public function testSettingTheSameEncoding(): void { $subject = GenericHeader::fromString('X-Test: test'); self::assertSame('ASCII', $subject->getEncoding()); diff --git a/test/Header/GenericMultiHeaderTest.php b/test/Header/GenericMultiHeaderTest.php index 1e050ce6..d3729d69 100644 --- a/test/Header/GenericMultiHeaderTest.php +++ b/test/Header/GenericMultiHeaderTest.php @@ -17,13 +17,13 @@ */ class GenericMultiHeaderTest extends TestCase { - public function testFromStringSingle() + public function testFromStringSingle(): void { $multiHeader = GenericMultiHeader::fromString('x-custom: test'); $this->assertSame(GenericMultiHeader::class, \get_class($multiHeader)); } - public function testFromStringMultiple() + public function testFromStringMultiple(): void { $headers = GenericMultiHeader::fromString('x-custom: foo,bar'); $this->assertSame(2, \count($headers)); @@ -32,14 +32,14 @@ public function testFromStringMultiple() } } - public function testToStringSingle() + public function testToStringSingle(): void { $multiHeader = new GenericMultiHeader('x-custom', 'test'); $this->assertSame('X-Custom: test', $multiHeader->toStringMultipleHeaders([])); } - public function testToStringMultiple() + public function testToStringMultiple(): void { $multiHeader = new GenericMultiHeader('x-custom', 'test'); $anotherHeader = new GenericMultiHeader('x-custom', 'two'); @@ -47,7 +47,7 @@ public function testToStringMultiple() $this->assertSame('X-Custom: test,two', $multiHeader->toStringMultipleHeaders([$anotherHeader])); } - public function testToStringInvalid() + public function testToStringInvalid(): void { $multiHeader = new GenericMultiHeader('x-custom', 'test'); diff --git a/test/Header/HeaderLocatorTest.php b/test/Header/HeaderLocatorTest.php index ca0d3ef6..99d6728d 100644 --- a/test/Header/HeaderLocatorTest.php +++ b/test/Header/HeaderLocatorTest.php @@ -18,12 +18,12 @@ class HeaderLocatorTest extends TestCase */ private $headerLocator; - public function setUp() + public function setUp(): void { $this->headerLocator = new Header\HeaderLocator(); } - public function provideHeaderNames() + public function provideHeaderNames(): array { return [ 'with existing name' => ['to', Header\To::class], @@ -38,12 +38,12 @@ public function provideHeaderNames() * @param $default * @dataProvider provideHeaderNames */ - public function testHeaderIsProperlyLoaded($name, $expected, $default = null) + public function testHeaderIsProperlyLoaded($name, $expected, $default = null): void { $this->assertEquals($expected, $this->headerLocator->get($name, $default)); } - public function testHeaderExistenceIsProperlyChecked() + public function testHeaderExistenceIsProperlyChecked(): void { $this->assertTrue($this->headerLocator->has('to')); $this->assertTrue($this->headerLocator->has('To')); @@ -53,21 +53,21 @@ public function testHeaderExistenceIsProperlyChecked() $this->assertFalse($this->headerLocator->has('bar')); } - public function testHeaderCanBeAdded() + public function testHeaderCanBeAdded(): void { $this->assertFalse($this->headerLocator->has('foo')); $this->headerLocator->add('foo', Header\GenericHeader::class); $this->assertTrue($this->headerLocator->has('foo')); } - public function testHeaderCanBeRemoved() + public function testHeaderCanBeRemoved(): void { $this->assertTrue($this->headerLocator->has('to')); $this->headerLocator->remove('to'); $this->assertFalse($this->headerLocator->has('to')); } - public static function expectedHeaders() + public static function expectedHeaders(): array { return [ 'bcc' => ['bcc', Header\Bcc::class], @@ -95,7 +95,7 @@ public static function expectedHeaders() * @param string $name * @param Header\HeaderInterface $class */ - public function testDefaultHeadersMapResolvesProperHeader($name, $class) + public function testDefaultHeadersMapResolvesProperHeader($name, $class): void { $this->assertEquals($class, $this->headerLocator->get($name)); } diff --git a/test/Header/HeaderNameTest.php b/test/Header/HeaderNameTest.php index d0e68e84..5fb53bb9 100644 --- a/test/Header/HeaderNameTest.php +++ b/test/Header/HeaderNameTest.php @@ -20,7 +20,7 @@ class HeaderNameTest extends TestCase /** * Data for filter name */ - public function getFilterNames() + public function getFilterNames(): array { return [ ['Subject', 'Subject'], @@ -37,13 +37,13 @@ public function getFilterNames() * @dataProvider getFilterNames * @group ZF2015-04 */ - public function testFilterName($name, $expected) + public function testFilterName($name, $expected): void { HeaderName::assertValid($expected); $this->assertEquals($expected, HeaderName::filter($name)); } - public function validateNames() + public function validateNames(): array { return [ ['Subject', 'assertTrue'], @@ -60,12 +60,12 @@ public function validateNames() * @dataProvider validateNames * @group ZF2015-04 */ - public function testValidateName($name, $assertion) + public function testValidateName($name, $assertion): void { $this->{$assertion}(HeaderName::isValid($name)); } - public function assertNames() + public function assertNames(): array { return [ ['Subject:'], @@ -79,7 +79,7 @@ public function assertNames() * @dataProvider assertNames * @group ZF2015-04 */ - public function testAssertValidRaisesExceptionForInvalidNames($name) + public function testAssertValidRaisesExceptionForInvalidNames($name): void { $this->expectException(Exception\RuntimeException::class); $this->expectExceptionMessage('Invalid'); diff --git a/test/Header/HeaderValueTest.php b/test/Header/HeaderValueTest.php index bb9c412a..87543c9b 100644 --- a/test/Header/HeaderValueTest.php +++ b/test/Header/HeaderValueTest.php @@ -20,7 +20,7 @@ class HeaderValueTest extends TestCase /** * Data for filter value */ - public function getFilterValues() + public function getFilterValues(): array { return [ ["This is a\n test", "This is a test"], @@ -42,12 +42,12 @@ public function getFilterValues() * @dataProvider getFilterValues * @group ZF2015-04 */ - public function testFilterValue($value, $expected) + public function testFilterValue($value, $expected): void { $this->assertEquals($expected, HeaderValue::filter($value)); } - public function validateValues() + public function validateValues(): array { return [ ["This is a\n test", 'assertFalse'], @@ -73,12 +73,12 @@ public function validateValues() * @dataProvider validateValues * @group ZF2015-04 */ - public function testValidateValue($value, $assertion) + public function testValidateValue($value, $assertion): void { $this->{$assertion}(HeaderValue::isValid($value)); } - public function assertValues() + public function assertValues(): array { return [ ["This is a\n test"], @@ -98,7 +98,7 @@ public function assertValues() * @dataProvider assertValues * @group ZF2015-04 */ - public function testAssertValidRaisesExceptionForInvalidValues($value) + public function testAssertValidRaisesExceptionForInvalidValues($value): void { $this->expectException(Exception\RuntimeException::class); $this->expectExceptionMessage('Invalid'); diff --git a/test/Header/HeaderWrapTest.php b/test/Header/HeaderWrapTest.php index 91314b10..a94aa4ce 100644 --- a/test/Header/HeaderWrapTest.php +++ b/test/Header/HeaderWrapTest.php @@ -19,7 +19,7 @@ */ class HeaderWrapTest extends TestCase { - public function testWrapUnstructuredHeaderAscii() + public function testWrapUnstructuredHeaderAscii(): void { $string = str_repeat('foobarblahblahblah baz bat', 4); $header = $this->createMock(UnstructuredInterface::class); @@ -35,7 +35,7 @@ public function testWrapUnstructuredHeaderAscii() /** * @group Laminas-258 */ - public function testWrapUnstructuredHeaderMime() + public function testWrapUnstructuredHeaderMime(): void { $string = str_repeat('foobarblahblahblah baz bat', 3); $header = $this->createMock(UnstructuredInterface::class); @@ -50,7 +50,7 @@ public function testWrapUnstructuredHeaderMime() $this->assertEquals($string, iconv_mime_decode($test, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8')); } - public function testWrapUnknownHeaderType() + public function testWrapUnknownHeaderType(): void { $header = new \Laminas\Mail\Header\Bcc('test@example.org'); $value = 'value unmodified by wrap function'; @@ -60,7 +60,7 @@ public function testWrapUnknownHeaderType() /** * @group Laminas-359 */ - public function testMimeEncoding() + public function testMimeEncoding(): void { $string = 'Umlauts: ä'; $expected = '=?UTF-8?Q?Umlauts:=20=C3=A4?='; @@ -70,7 +70,7 @@ public function testMimeEncoding() $this->assertEquals($string, iconv_mime_decode($test, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8')); } - public function testMimeDecoding() + public function testMimeDecoding(): void { $expected = str_repeat('foobarblahblahblah baz bat', 3); $encoded = "=?UTF-8?Q?foobarblahblahblah=20baz=20batfoobarblahblahblah=20baz=20?=\r\n" @@ -86,7 +86,7 @@ public function testMimeDecoding() * because undocumented behavior in iconv_mime_decode() * @see https://github.com/zendframework/zend-mail/pull/187 */ - public function testMimeDecodeBreakageBug() + public function testMimeDecodeBreakageBug(): void { $headerValue = 'v=1; a=rsa-sha25; c=relaxed/simple; d=example.org; h=' . "\r\n\t" . 'content-language:content-type:content-type:in-reply-to'; @@ -113,7 +113,7 @@ public function testMimeDecodeBreakageBug() * which can be triggered as: * $header = new GenericHeader($name, $value); */ - public function testCanBeEncoded() + public function testCanBeEncoded(): void { // @codingStandardsIgnoreStart $value = "[#77675] New Issue:xxxxxxxxx xxxxxxx xxxxxxxx xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxx, tähtaeg xx.xx, xxxx"; @@ -126,7 +126,7 @@ public function testCanBeEncoded() /** * @requires extension imap */ - public function testMultilineWithMultibyteSplitAcrossCharacter() + public function testMultilineWithMultibyteSplitAcrossCharacter(): void { $originalValue = 'аф'; diff --git a/test/Header/IdentificationFieldTest.php b/test/Header/IdentificationFieldTest.php index b0ce2e4d..797c0c0d 100644 --- a/test/Header/IdentificationFieldTest.php +++ b/test/Header/IdentificationFieldTest.php @@ -16,34 +16,34 @@ class IdentificationFieldTest extends TestCase { - public function stringHeadersProvider() + public function stringHeadersProvider(): array { return array_merge( [ [ References::class, 'References: <1234@local.machine.example> <3456@example.net>', - ['1234@local.machine.example', '3456@example.net'] - ] + ['1234@local.machine.example', '3456@example.net'], + ], ], $this->reversibleStringHeadersProvider() ); } - public function reversibleStringHeadersProvider() + public function reversibleStringHeadersProvider(): array { return [ [References::class, 'References: <1234@local.machine.example>', ['1234@local.machine.example']], [ References::class, "References: <1234@local.machine.example>\r\n <3456@example.net>", - ['1234@local.machine.example', '3456@example.net'] + ['1234@local.machine.example', '3456@example.net'], ], - [InReplyTo::class, 'In-Reply-To: <3456@example.net>', ['3456@example.net']] + [InReplyTo::class, 'In-Reply-To: <3456@example.net>', ['3456@example.net']], ]; } - public function invalidIds() + public function invalidIds(): array { return [ [References::class, ["1234@local.machine.example\r\n"]], @@ -58,7 +58,7 @@ public function invalidIds() * @param string $headerString * @param string[] $ids */ - public function testDeserializationFromString($className, $headerString, $ids) + public function testDeserializationFromString($className, $headerString, $ids): void { /** @var IdentificationField $header */ $header = $className::fromString($headerString); @@ -71,7 +71,7 @@ public function testDeserializationFromString($className, $headerString, $ids) * @param string $headerString * @param string[] $ids */ - public function testSerializationToString($className, $headerString, $ids) + public function testSerializationToString($className, $headerString, $ids): void { /** @var IdentificationField $header */ $header = new $className(); @@ -85,7 +85,7 @@ public function testSerializationToString($className, $headerString, $ids) * @param string $headerString * @param string[] $ids */ - public function testDefaultEncoding($className, $headerString, array $ids) + public function testDefaultEncoding($className, $headerString, array $ids): void { /** @var IdentificationField $header */ $header = $className::fromString($headerString); @@ -98,7 +98,7 @@ public function testDefaultEncoding($className, $headerString, array $ids) * @param string $headerString * @param string[] $ids */ - public function testSetEncodingHasNoEffect($className, $headerString, array $ids) + public function testSetEncodingHasNoEffect($className, $headerString, array $ids): void { /** @var IdentificationField $header */ $header = $className::fromString($headerString); @@ -111,7 +111,7 @@ public function testSetEncodingHasNoEffect($className, $headerString, array $ids * @param string $className * @param string[] $ids */ - public function testSetIdsThrowsOnInvalidInput($className, $ids) + public function testSetIdsThrowsOnInvalidInput($className, $ids): void { /** @var IdentificationField $header */ $header = new $className(); @@ -125,7 +125,7 @@ public function testSetIdsThrowsOnInvalidInput($className, $ids) * @param string $className * @param string[] $ids */ - public function testFromStringRaisesExceptionOnInvalidHeader($className, $ids) + public function testFromStringRaisesExceptionOnInvalidHeader($className, $ids): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid header line'); diff --git a/test/Header/MessageIdTest.php b/test/Header/MessageIdTest.php index b38e1851..9c4705fc 100644 --- a/test/Header/MessageIdTest.php +++ b/test/Header/MessageIdTest.php @@ -18,7 +18,7 @@ */ class MessageIdTest extends TestCase { - public function testSettingManually() + public function testSettingManually(): void { $id = "CALTvGe4_oYgf9WsYgauv7qXh2-6=KbPLExmJNG7fCs9B=1nOYg@mail.example.com"; $messageid = new Header\MessageId(); @@ -30,7 +30,7 @@ public function testSettingManually() $this->assertEquals("Message-ID: $expected", $messageid->toString()); } - public function testAutoGeneration() + public function testAutoGeneration(): void { $messageid = new Header\MessageId(); $messageid->setId(); @@ -38,7 +38,7 @@ public function testAutoGeneration() $this->assertContains('@', $messageid->getFieldValue()); } - public function testAutoGenerationWithServerVars() + public function testAutoGenerationWithServerVars(): void { $serverBeforeTest = $_SERVER; $_SERVER['REMOTE_ADDR'] = '172.16.0.1'; @@ -50,7 +50,7 @@ public function testAutoGenerationWithServerVars() $_SERVER = $serverBeforeTest; } - public function headerLines() + public function headerLines(): array { return [ 'newline' => ["Message-ID: foo\nbar"], @@ -64,13 +64,13 @@ public function headerLines() * @dataProvider headerLines * @group ZF2015-04 */ - public function testFromStringPreventsCrlfInjectionOnDetection($header) + public function testFromStringPreventsCrlfInjectionOnDetection($header): void { $this->expectException(Exception\InvalidArgumentException::class); $messageid = Header\MessageId::fromString($header); } - public function invalidIdentifiers() + public function invalidIdentifiers(): array { return [ 'newline' => ["foo\nbar"], @@ -85,27 +85,27 @@ public function invalidIdentifiers() * @dataProvider invalidIdentifiers * @group ZF2015-04 */ - public function testInvalidIdentifierRaisesException($id) + public function testInvalidIdentifierRaisesException($id): void { $header = new Header\MessageId(); $this->expectException(Exception\InvalidArgumentException::class); $header->setId($id); } - public function testFromStringRaisesExceptionOnInvalidHeader() + public function testFromStringRaisesExceptionOnInvalidHeader(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid header line for Message-ID string'); Header\MessageId::fromString('Foo: bar'); } - public function testDefaultEncoding() + public function testDefaultEncoding(): void { $header = new Header\MessageId(); $this->assertSame('ASCII', $header->getEncoding()); } - public function testSetEncodingHasNoEffect() + public function testSetEncodingHasNoEffect(): void { $header = new Header\MessageId(); $header->setEncoding('UTF-8'); diff --git a/test/Header/MimeVersionTest.php b/test/Header/MimeVersionTest.php index 3d42e096..daffff3b 100644 --- a/test/Header/MimeVersionTest.php +++ b/test/Header/MimeVersionTest.php @@ -18,7 +18,7 @@ */ class MimeVersionTest extends TestCase { - public function testSettingManually() + public function testSettingManually(): void { $version = "2.0"; $mime = new Header\MimeVersion(); @@ -26,14 +26,14 @@ public function testSettingManually() $this->assertEquals($version, $mime->getFieldValue()); } - public function testDefaultVersion() + public function testDefaultVersion(): void { $mime = new Header\MimeVersion(); $this->assertEquals('1.0', $mime->getVersion()); $this->assertEquals('MIME-Version: 1.0', $mime->toString()); } - public function headerLines() + public function headerLines(): array { return [ 'newline' => ["MIME-Version: 5.0\nbar"], @@ -47,13 +47,13 @@ public function headerLines() * @dataProvider headerLines * @group ZF2015-04 */ - public function testFromStringRaisesExceptionOnDetectionOfCrlfInjection($header) + public function testFromStringRaisesExceptionOnDetectionOfCrlfInjection($header): void { $this->expectException(Exception\InvalidArgumentException::class); $mime = Header\MimeVersion::fromString($header); } - public function invalidVersions() + public function invalidVersions(): array { return [ 'no-decimal' => ['1'], @@ -67,29 +67,29 @@ public function invalidVersions() * @dataProvider invalidVersions * @group ZF2015-04 */ - public function testRaisesExceptionOnInvalidVersionFromSetVersion($value) + public function testRaisesExceptionOnInvalidVersionFromSetVersion($value): void { $header = new Header\MimeVersion(); $this->expectException(Exception\InvalidArgumentException::class); $header->setVersion($value); } - public function testFromStringRaisesExceptionOnInvalidHeader() + public function testFromStringRaisesExceptionOnInvalidHeader(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid header line for MIME-Version string'); Header\MimeVersion::fromString('Foo: bar'); } - public function testDefaultEncoding() + public function testDefaultEncoding(): void { - $header = new Header\MimeVersion('1.0'); + $header = new Header\MimeVersion(); $this->assertSame('ASCII', $header->getEncoding()); } - public function testSetEncodingHasNoEffect() + public function testSetEncodingHasNoEffect(): void { - $header = new Header\MimeVersion('1.0'); + $header = new Header\MimeVersion(); $header->setEncoding('UTF-8'); $this->assertSame('ASCII', $header->getEncoding()); } diff --git a/test/Header/ReceivedTest.php b/test/Header/ReceivedTest.php index f94e97f1..15d02490 100644 --- a/test/Header/ReceivedTest.php +++ b/test/Header/ReceivedTest.php @@ -20,20 +20,20 @@ */ class ReceivedTest extends TestCase { - public function testFromStringCreatesValidReceivedHeader() + public function testFromStringCreatesValidReceivedHeader(): void { $receivedHeader = Header\Received::fromString('Received: xxx'); $this->assertInstanceOf(HeaderInterface::class, $receivedHeader); $this->assertInstanceOf(Received::class, $receivedHeader); } - public function testGetFieldNameReturnsHeaderName() + public function testGetFieldNameReturnsHeaderName(): void { $receivedHeader = new Header\Received(); $this->assertEquals('Received', $receivedHeader->getFieldName()); } - public function testReceivedGetFieldValueReturnsProperValue() + public function testReceivedGetFieldValueReturnsProperValue(): void { $this->markTestIncomplete('Received needs to be completed'); @@ -41,7 +41,7 @@ public function testReceivedGetFieldValueReturnsProperValue() $this->assertEquals('xxx', $receivedHeader->getFieldValue()); } - public function testReceivedToStringReturnsHeaderFormattedString() + public function testReceivedToStringReturnsHeaderFormattedString(): void { $this->markTestIncomplete('Received needs to be completed'); @@ -53,7 +53,7 @@ public function testReceivedToStringReturnsHeaderFormattedString() /** Implementation specific tests here */ - public function headerLines() + public function headerLines(): array { return [ 'newline' => ["Received: xx\nx"], @@ -68,13 +68,13 @@ public function headerLines() * @dataProvider headerLines * @group ZF2015-04 */ - public function testRaisesExceptionViaFromStringOnDetectionOfCrlfInjection($header) + public function testRaisesExceptionViaFromStringOnDetectionOfCrlfInjection($header): void { $this->expectException(Exception\InvalidArgumentException::class); $received = Header\Received::fromString($header); } - public function invalidValues() + public function invalidValues(): array { return [ 'newline' => ["xx\nx"], @@ -88,39 +88,39 @@ public function invalidValues() * @dataProvider invalidValues * @group ZF2015-04 */ - public function testConstructorRaisesExceptionOnValueWithCRLFInjectionAttempt($value) + public function testConstructorRaisesExceptionOnValueWithCRLFInjectionAttempt($value): void { $this->expectException(Exception\InvalidArgumentException::class); new Header\Received($value); } - public function testFromStringRaisesExceptionOnInvalidHeader() + public function testFromStringRaisesExceptionOnInvalidHeader(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid header line for Received string'); Header\Received::fromString('Foo: bar'); } - public function testDefaultEncoding() + public function testDefaultEncoding(): void { $header = Header\Received::fromString('Received: test'); $this->assertSame('ASCII', $header->getEncoding()); } - public function testSetEncodingHasNoEffect() + public function testSetEncodingHasNoEffect(): void { $header = Header\Received::fromString('Received: test'); $header->setEncoding('UTF-8'); $this->assertSame('ASCII', $header->getEncoding()); } - public function testToString() + public function testToString(): void { $header = new Header\Received('test'); $this->assertEquals('Received: test', $header->toString()); } - public function testToStringMultipleHeaders() + public function testToStringMultipleHeaders(): void { $header = new Header\Received('test'); $this->assertEquals('Received: test', $header->toStringMultipleHeaders([])); @@ -138,7 +138,7 @@ public function testToStringMultipleHeaders() ); } - public function testToStringMultipleHeadersThrows() + public function testToStringMultipleHeadersThrows(): void { $header = new Header\Received('test'); $this->expectException(Exception\RuntimeException::class); diff --git a/test/Header/SenderTest.php b/test/Header/SenderTest.php index 56e65450..f680a8a2 100644 --- a/test/Header/SenderTest.php +++ b/test/Header/SenderTest.php @@ -21,14 +21,14 @@ */ class SenderTest extends TestCase { - public function testFromStringCreatesValidReceivedHeader() + public function testFromStringCreatesValidReceivedHeader(): void { $sender = Header\Sender::fromString('Sender: '); $this->assertInstanceOf(HeaderInterface::class, $sender); $this->assertInstanceOf(Sender::class, $sender); } - public function testGetFieldNameReturnsHeaderName() + public function testGetFieldNameReturnsHeaderName(): void { $sender = new Header\Sender(); $this->assertEquals('Sender', $sender->getFieldName()); @@ -43,7 +43,7 @@ public function testGetFieldNameReturnsHeaderName() * @param string $encodedValue * @param string $encoding */ - public function testParseValidSenderHeader($expectedFieldValue, $encodedValue, $encoding) + public function testParseValidSenderHeader($expectedFieldValue, $encodedValue, $encoding): void { $header = Header\Sender::fromString('Sender:' . $encodedValue); @@ -60,7 +60,7 @@ public function testParseValidSenderHeader($expectedFieldValue, $encodedValue, $ public function testParseInvalidSenderHeaderThrowException( $decodedValue, $expectedException - ) { + ): void { $this->expectException($expectedException); Header\Sender::fromString('Sender:' . $decodedValue); } @@ -74,7 +74,7 @@ public function testParseInvalidSenderHeaderThrowException( * @param string $expectedFieldValue, * @param string $encoding */ - public function testSetAddressValidValue($email, $name, $expectedFieldValue, $encodedValue, $encoding) + public function testSetAddressValidValue($email, $name, $expectedFieldValue, $encodedValue, $encoding): void { $header = new Header\Sender(); $header->setAddress($email, $name); @@ -90,7 +90,7 @@ public function testSetAddressValidValue($email, $name, $expectedFieldValue, $en * @param string $email * @param null|string $name */ - public function testSetAddressInvalidValue($email, $name) + public function testSetAddressInvalidValue($email, $name): void { $header = new Header\Sender(); $this->expectException(Exception\InvalidArgumentException::class); @@ -106,7 +106,7 @@ public function testSetAddressInvalidValue($email, $name) * @param string $encodedValue * @param string $encoding */ - public function testSetAddressValidAddressObject($email, $name, $expectedFieldValue, $encodedValue, $encoding) + public function testSetAddressValidAddressObject($email, $name, $expectedFieldValue, $encodedValue, $encoding): void { $address = new Address($email, $name); @@ -119,7 +119,7 @@ public function testSetAddressValidAddressObject($email, $name, $expectedFieldVa $this->assertEquals($encoding, $header->getEncoding()); } - public function validSenderDataProvider() + public function validSenderDataProvider(): array { return [ // Description => [sender address, sender name, getFieldValue, encoded version, encoding], @@ -128,26 +128,26 @@ public function validSenderDataProvider() null, '', '', - 'ASCII' + 'ASCII', ], 'ASCII name' => [ 'foo@bar', 'foo', 'foo ', 'foo ', - 'ASCII' + 'ASCII', ], 'UTF-8 name' => [ 'foo@bar', 'ázÁZ09', 'ázÁZ09 ', '=?UTF-8?Q?=C3=A1z=C3=81Z09?= ', - 'UTF-8' + 'UTF-8', ], ]; } - public function validSenderHeaderDataProvider() + public function validSenderHeaderDataProvider(): array { return array_merge(array_map(function ($parameters) { return array_slice($parameters, 2); @@ -156,12 +156,12 @@ public function validSenderHeaderDataProvider() 'Unbracketed email' => [ '', 'foo@bar', - 'ASCII' - ] + 'ASCII', + ], ]); } - public function invalidSenderDataProvider() + public function invalidSenderDataProvider(): array { $mailInvalidArgumentException = Exception\InvalidArgumentException::class; @@ -184,7 +184,7 @@ public function invalidSenderDataProvider() ]; } - public function invalidSenderEncodedDataProvider() + public function invalidSenderEncodedDataProvider(): array { $mailInvalidArgumentException = Exception\InvalidArgumentException::class; $headerInvalidArgumentException = Header\Exception\InvalidArgumentException::class; @@ -215,7 +215,7 @@ public function invalidSenderEncodedDataProvider() * * @dataProvider validHeaderLinesProvider */ - public function testFromStringWithValidInput($headerString, $expectedName, $expectedEmail) + public function testFromStringWithValidInput($headerString, $expectedName, $expectedEmail): void { $header = Header\Sender::fromString($headerString); @@ -223,7 +223,7 @@ public function testFromStringWithValidInput($headerString, $expectedName, $expe $this->assertSame($expectedEmail, $header->getAddress()->getEmail()); } - public function validHeaderLinesProvider() + public function validHeaderLinesProvider(): array { // @codingStandardsIgnoreStart return [ @@ -246,7 +246,7 @@ public function validHeaderLinesProvider() * * @dataProvider invalidHeaderLinesProvider */ - public function testFromStringWithInvalidInput($headerString, $expectedException, $expectedMessagePart = '') + public function testFromStringWithInvalidInput($headerString, $expectedException, $expectedMessagePart = ''): void { $this->expectException($expectedException); if ($expectedMessagePart) { @@ -256,7 +256,7 @@ public function testFromStringWithInvalidInput($headerString, $expectedException Header\Sender::fromString($headerString); } - public function invalidHeaderLinesProvider() + public function invalidHeaderLinesProvider(): array { $mailInvalidArgumentException = Exception\InvalidArgumentException::class; $headerInvalidArgumentException = Header\Exception\InvalidArgumentException::class; @@ -269,20 +269,20 @@ public function invalidHeaderLinesProvider() ]; } - public function testDefaultEncoding() + public function testDefaultEncoding(): void { - $header = new Header\Sender(''); + $header = new Header\Sender(); $this->assertSame('ASCII', $header->getEncoding()); } - public function testSetEncoding() + public function testSetEncoding(): void { - $header = new Header\Sender(''); + $header = new Header\Sender(); $header->setEncoding('UTF-8'); $this->assertSame('UTF-8', $header->getEncoding()); } - public function testFromStringRaisesExceptionOnInvalidHeader() + public function testFromStringRaisesExceptionOnInvalidHeader(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid header name for Sender string'); diff --git a/test/Header/SubjectTest.php b/test/Header/SubjectTest.php index 4e8f18c7..b2c34504 100644 --- a/test/Header/SubjectTest.php +++ b/test/Header/SubjectTest.php @@ -18,7 +18,7 @@ */ class SubjectTest extends TestCase { - public function testHeaderFolding() + public function testHeaderFolding(): void { $string = str_repeat('foobarblahblahblah baz bat', 10); $subject = new Header\Subject(); @@ -29,13 +29,13 @@ public function testHeaderFolding() $this->assertEquals($expected, $test); } - public function testDefaultEncoding() + public function testDefaultEncoding(): void { $header = Header\Subject::fromString('Subject: test'); $this->assertSame('ASCII', $header->getEncoding()); } - public function testSetEncoding() + public function testSetEncoding(): void { $header = Header\Subject::fromString('Subject: test'); $header->setEncoding('UTF-8'); @@ -49,7 +49,7 @@ public function testSetEncoding() * @param string $encodedValue * @param string $encoding */ - public function testParseValidSubjectHeader($decodedValue, $encodedValue, $encoding) + public function testParseValidSubjectHeader($decodedValue, $encodedValue, $encoding): void { $header = Header\Subject::fromString('Subject:' . $encodedValue); @@ -68,13 +68,13 @@ public function testParseInvalidSubjectHeaderThrowException( $decodedValue, $expectedException, $expectedExceptionMessage - ) { + ): void { $this->expectException($expectedException); $this->expectExceptionMessage($expectedExceptionMessage); Header\Subject::fromString('Subject:' . $decodedValue); } - public function testFromStringRaisesExceptionOnInvalidHeader() + public function testFromStringRaisesExceptionOnInvalidHeader(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid header line for Subject string'); @@ -88,7 +88,7 @@ public function testFromStringRaisesExceptionOnInvalidHeader() * @param string $encodedValue * @param string $encoding */ - public function testSetSubjectValidValue($decodedValue, $encodedValue, $encoding) + public function testSetSubjectValidValue($decodedValue, $encodedValue, $encoding): void { $header = new Header\Subject(); $header->setSubject($decodedValue); @@ -98,7 +98,7 @@ public function testSetSubjectValidValue($decodedValue, $encodedValue, $encoding $this->assertEquals($encoding, $header->getEncoding()); } - public function validSubjectValuesProvider() + public function validSubjectValuesProvider(): array { return [ // Description => [decoded format, encoded format, encoding], @@ -116,7 +116,7 @@ public function validSubjectValuesProvider() ]; } - public function invalidSubjectValuesProvider() + public function invalidSubjectValuesProvider(): array { $invalidArgumentException = Exception\InvalidArgumentException::class; $invalidHeaderValueDetected = 'Invalid header value detected'; @@ -130,7 +130,7 @@ public function invalidSubjectValuesProvider() ]; } - public function testChangeEncodingToAsciiNotAllowedWhenSubjectContainsUtf8Characters() + public function testChangeEncodingToAsciiNotAllowedWhenSubjectContainsUtf8Characters(): void { $subject = new Header\Subject(); $subject->setSubject('Accents òàùèéì'); @@ -141,7 +141,7 @@ public function testChangeEncodingToAsciiNotAllowedWhenSubjectContainsUtf8Charac self::assertSame('UTF-8', $subject->getEncoding()); } - public function testChangeEncodingBackToAscii() + public function testChangeEncodingBackToAscii(): void { $subject = new Header\Subject(); $subject->setSubject('test'); @@ -155,7 +155,7 @@ public function testChangeEncodingBackToAscii() self::assertSame('ASCII', $subject->getEncoding()); } - public function testSetNullEncoding() + public function testSetNullEncoding(): void { $subject = Header\Subject::fromString('Subject: test'); self::assertSame('ASCII', $subject->getEncoding()); @@ -164,7 +164,7 @@ public function testSetNullEncoding() self::assertSame('ASCII', $subject->getEncoding()); } - public function testSettingSubjectCanChangeEncoding() + public function testSettingSubjectCanChangeEncoding(): void { $subject = Header\Subject::fromString('Subject: test'); self::assertSame('ASCII', $subject->getEncoding()); @@ -173,7 +173,7 @@ public function testSettingSubjectCanChangeEncoding() self::assertSame('UTF-8', $subject->getEncoding()); } - public function testSettingTheSameEncoding() + public function testSettingTheSameEncoding(): void { $subject = Header\Subject::fromString('Subject: test'); self::assertSame('ASCII', $subject->getEncoding()); diff --git a/test/Header/ToTest.php b/test/Header/ToTest.php index 8f5db30d..7ec92c73 100644 --- a/test/Header/ToTest.php +++ b/test/Header/ToTest.php @@ -21,7 +21,7 @@ */ class ToTest extends TestCase { - public function testHeaderFoldingOccursProperly() + public function testHeaderFoldingOccursProperly(): void { $header = new Header\To(); $list = $header->getAddressList(); @@ -33,7 +33,7 @@ public function testHeaderFoldingOccursProperly() $this->assertEquals(10, count($emails)); } - public function headerLines() + public function headerLines(): array { return [ 'newline' => ["To: xxx yyy\n"], @@ -47,7 +47,7 @@ public function headerLines() * @dataProvider headerLines * @group ZF2015-04 */ - public function testFromStringRaisesExceptionWhenCrlfInjectionIsDetected($header) + public function testFromStringRaisesExceptionWhenCrlfInjectionIsDetected($header): void { $this->expectException(Exception\InvalidArgumentException::class); Header\To::fromString($header); diff --git a/test/HeadersTest.php b/test/HeadersTest.php index aa9ce4fe..d9b40005 100644 --- a/test/HeadersTest.php +++ b/test/HeadersTest.php @@ -42,7 +42,7 @@ public function tearDown(): void public function setDeprecationErrorHandler(): void { $this->originalErrorHandler = set_error_handler( - function (int $errno, string $errstr, string $errfile, int $errline) { + function (int $errno, string $errstr, string $errfile, int $errline): void { throw new Deprecated($errstr, $errno, $errfile, $errline); }, E_USER_DEPRECATED @@ -59,14 +59,14 @@ public function restoreErrorHandler(): void $this->originalErrorHandler = null; } - public function testHeadersImplementsProperClasses() + public function testHeadersImplementsProperClasses(): void { $headers = new Mail\Headers(); $this->assertInstanceOf(\Iterator::class, $headers); $this->assertInstanceOf(\Countable::class, $headers); } - public function testHeadersFromStringFactoryCreatesSingleObject() + public function testHeadersFromStringFactoryCreatesSingleObject(): void { $headers = Mail\Headers::fromString("Fake: foo-bar"); $this->assertEquals(1, $headers->count()); @@ -77,7 +77,7 @@ public function testHeadersFromStringFactoryCreatesSingleObject() $this->assertEquals('foo-bar', $header->getFieldValue()); } - public function testHeadersFromStringFactoryHandlesMissingWhitespace() + public function testHeadersFromStringFactoryHandlesMissingWhitespace(): void { $headers = Mail\Headers::fromString("Fake:foo-bar"); $this->assertEquals(1, $headers->count()); @@ -91,7 +91,7 @@ public function testHeadersFromStringFactoryHandlesMissingWhitespace() /** * @group 6657 */ - public function testHeadersFromStringFactoryCreatesSingleObjectWithContinuationLine() + public function testHeadersFromStringFactoryCreatesSingleObjectWithContinuationLine(): void { $headers = Mail\Headers::fromString("Fake: foo-bar,\r\n blah-blah"); $this->assertEquals(1, $headers->count()); @@ -102,7 +102,7 @@ public function testHeadersFromStringFactoryCreatesSingleObjectWithContinuationL $this->assertEquals('foo-bar, blah-blah', $header->getFieldValue()); } - public function testHeadersFromStringFactoryCreatesSingleObjectWithHeaderBreakLine() + public function testHeadersFromStringFactoryCreatesSingleObjectWithHeaderBreakLine(): void { $headers = Mail\Headers::fromString("Fake: foo-bar\r\n\r\n"); $this->assertEquals(1, $headers->count()); @@ -113,21 +113,21 @@ public function testHeadersFromStringFactoryCreatesSingleObjectWithHeaderBreakLi $this->assertEquals('foo-bar', $header->getFieldValue()); } - public function testHeadersFromStringFactoryThrowsExceptionOnMalformedHeaderLine() + public function testHeadersFromStringFactoryThrowsExceptionOnMalformedHeaderLine(): void { $this->expectException(Mail\Exception\RuntimeException::class); $this->expectExceptionMessage('does not match'); Mail\Headers::fromString("Fake = foo-bar\r\n\r\n"); } - public function testHeadersFromStringFactoryThrowsExceptionOnMalformedHeaderLines() + public function testHeadersFromStringFactoryThrowsExceptionOnMalformedHeaderLines(): void { $this->expectException(Mail\Exception\RuntimeException::class); $this->expectExceptionMessage('Malformed header detected'); Mail\Headers::fromString("Fake: foo-bar\r\n\r\n\r\n\r\nAnother-Fake: boo-baz"); } - public function testHeadersFromStringFactoryCreatesMultipleObjects() + public function testHeadersFromStringFactoryCreatesMultipleObjects(): void { $headers = Mail\Headers::fromString("Fake: foo-bar\r\nAnother-Fake: boo-baz"); $this->assertEquals(2, $headers->count()); @@ -143,7 +143,7 @@ public function testHeadersFromStringFactoryCreatesMultipleObjects() $this->assertEquals('boo-baz', $header->getFieldValue()); } - public function testHeadersFromStringMultiHeaderWillAggregateLazyLoadedHeaders() + public function testHeadersFromStringMultiHeaderWillAggregateLazyLoadedHeaders(): void { $headers = new Mail\Headers(); $loader = $headers->getHeaderLocator(); @@ -153,7 +153,7 @@ public function testHeadersFromStringMultiHeaderWillAggregateLazyLoadedHeaders() $this->assertEquals(3, $headers->count()); } - public function testHeadersHasAndGetWorkProperly() + public function testHeadersHasAndGetWorkProperly(): void { $headers = new Mail\Headers(); $headers->addHeaders([ @@ -166,7 +166,7 @@ public function testHeadersHasAndGetWorkProperly() $this->assertEquals('bar', $headers->get('foo')->getFieldValue()); } - public function testHeadersAggregatesHeaderObjects() + public function testHeadersAggregatesHeaderObjects(): void { $fakeHeader = new Header\GenericHeader('Fake', 'bar'); $headers = new Mail\Headers(); @@ -175,7 +175,7 @@ public function testHeadersAggregatesHeaderObjects() $this->assertEquals('bar', $headers->get('Fake')->getFieldValue()); } - public function testHeadersAggregatesHeaderThroughAddHeader() + public function testHeadersAggregatesHeaderThroughAddHeader(): void { $headers = new Mail\Headers(); $headers->addHeader(new Header\GenericHeader('Fake', 'bar')); @@ -183,7 +183,7 @@ public function testHeadersAggregatesHeaderThroughAddHeader() $this->assertInstanceOf(GenericHeader::class, $headers->get('Fake')); } - public function testHeadersAggregatesHeaderThroughAddHeaderLine() + public function testHeadersAggregatesHeaderThroughAddHeaderLine(): void { $headers = new Mail\Headers(); $headers->addHeaderLine('Fake', 'bar'); @@ -191,7 +191,7 @@ public function testHeadersAggregatesHeaderThroughAddHeaderLine() $this->assertInstanceOf(GenericHeader::class, $headers->get('Fake')); } - public function testHeadersAddHeaderLineThrowsExceptionOnMissingFieldValue() + public function testHeadersAddHeaderLineThrowsExceptionOnMissingFieldValue(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Header must match with the format "name:value"'); @@ -199,7 +199,7 @@ public function testHeadersAddHeaderLineThrowsExceptionOnMissingFieldValue() $headers->addHeaderLine('Foo'); } - public function testHeadersAddHeaderLineThrowsExceptionOnInvalidFieldNull() + public function testHeadersAddHeaderLineThrowsExceptionOnInvalidFieldNull(): void { $headers = new Mail\Headers(); @@ -208,7 +208,7 @@ public function testHeadersAddHeaderLineThrowsExceptionOnInvalidFieldNull() $headers->addHeaderLine(null); } - public function testHeadersAddHeaderLineThrowsExceptionOnInvalidFieldObject() + public function testHeadersAddHeaderLineThrowsExceptionOnInvalidFieldObject(): void { $headers = new Mail\Headers(); $object = new \stdClass(); @@ -218,7 +218,7 @@ public function testHeadersAddHeaderLineThrowsExceptionOnInvalidFieldObject() $headers->addHeaderLine($object); } - public function testHeadersAggregatesHeadersThroughAddHeaders() + public function testHeadersAggregatesHeadersThroughAddHeaders(): void { $headers = new Mail\Headers(); $headers->addHeaders([new Header\GenericHeader('Foo', 'bar'), new Header\GenericHeader('Baz', 'baz')]); @@ -256,7 +256,7 @@ public function testHeadersAggregatesHeadersThroughAddHeaders() $this->assertEquals('baz', $headers->get('baz')->getFieldValue()); } - public function testHeadersAddHeadersThrowsExceptionOnInvalidArguments() + public function testHeadersAddHeadersThrowsExceptionOnInvalidArguments(): void { $this->expectException(Mail\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Expected array or Traversable'); @@ -264,7 +264,7 @@ public function testHeadersAddHeadersThrowsExceptionOnInvalidArguments() $headers->addHeaders('foo'); } - public function testHeadersCanRemoveHeader() + public function testHeadersCanRemoveHeader(): void { $headers = new Mail\Headers(); $headers->addHeaders(['Foo' => 'bar', 'Baz' => 'baz']); @@ -275,7 +275,7 @@ public function testHeadersCanRemoveHeader() $this->assertTrue($headers->has('baz')); } - public function testRemoveHeaderWithFieldNameWillRemoveAllInstances() + public function testRemoveHeaderWithFieldNameWillRemoveAllInstances(): void { $headers = new Mail\Headers(); $headers->addHeaders([['Foo' => 'foo'], ['Foo' => 'bar'], 'Baz' => 'baz']); @@ -286,7 +286,7 @@ public function testRemoveHeaderWithFieldNameWillRemoveAllInstances() $this->assertTrue($headers->has('baz')); } - public function testRemoveHeaderWithInstanceWillRemoveThatInstance() + public function testRemoveHeaderWithInstanceWillRemoveThatInstance(): void { $headers = new Mail\Headers(); $headers->addHeaders([['Foo' => 'foo'], ['Foo' => 'bar'], 'Baz' => 'baz']); @@ -298,13 +298,13 @@ public function testRemoveHeaderWithInstanceWillRemoveThatInstance() $this->assertNotSame($header, $headers->get('foo')); } - public function testRemoveHeaderWhenEmpty() + public function testRemoveHeaderWhenEmpty(): void { $headers = new Mail\Headers(); $this->assertFalse($headers->removeHeader('')); } - public function testHeadersCanClearAllHeaders() + public function testHeadersCanClearAllHeaders(): void { $headers = new Mail\Headers(); $headers->addHeaders(['Foo' => 'bar', 'Baz' => 'baz']); @@ -313,7 +313,7 @@ public function testHeadersCanClearAllHeaders() $this->assertEquals(0, $headers->count()); } - public function testHeadersCanBeIterated() + public function testHeadersCanBeIterated(): void { $headers = new Mail\Headers(); $headers->addHeaders(['Foo' => 'bar', 'Baz' => 'baz']); @@ -335,21 +335,21 @@ public function testHeadersCanBeIterated() $this->assertEquals(2, $iterations); } - public function testHeadersCanBeCastToString() + public function testHeadersCanBeCastToString(): void { $headers = new Mail\Headers(); $headers->addHeaders(['Foo' => 'bar', 'Baz' => 'baz']); $this->assertEquals('Foo: bar' . "\r\n" . 'Baz: baz' . "\r\n", $headers->toString()); } - public function testHeadersCanBeCastToArray() + public function testHeadersCanBeCastToArray(): void { $headers = new Mail\Headers(); $headers->addHeaders(['Foo' => 'bar', 'Baz' => 'baz']); $this->assertEquals(['Foo' => 'bar', 'Baz' => 'baz'], $headers->toArray()); } - public function testCastingToArrayReturnsMultiHeadersAsArrays() + public function testCastingToArrayReturnsMultiHeadersAsArrays(): void { $headers = new Mail\Headers(); @@ -370,7 +370,7 @@ public function testCastingToArrayReturnsMultiHeadersAsArrays() $this->assertEquals($expected, $array); } - public function testCastingToStringReturnsAllMultiHeaderValues() + public function testCastingToStringReturnsAllMultiHeaderValues(): void { $headers = new Mail\Headers(); @@ -390,7 +390,7 @@ public function testCastingToStringReturnsAllMultiHeaderValues() $this->assertEquals($expected, $string); } - public function testGetReturnsArrayIterator() + public function testGetReturnsArrayIterator(): void { $headers = new Mail\Headers(); $received = Header\Received::fromString('Received: from framework (localhost [127.0.0.1])'); @@ -401,10 +401,10 @@ public function testGetReturnsArrayIterator() } /** - * @test that toArray can take format parameter - * @link https://github.com/zendframework/zend-mail/pull/61 + * Test that toArray can take format parameter + * @see https://github.com/zendframework/zend-mail/pull/61 */ - public function testToArrayFormatRaw() + public function testToArrayFormatRaw(): void { $raw_subject = '=?ISO-8859-2?Q?PD=3A_My=3A_Go=B3?= =?ISO-8859-2?Q?blahblah?='; $headers = new Mail\Headers(); @@ -419,10 +419,10 @@ public function testToArrayFormatRaw() } /** - * @test that toArray can take format parameter - * @link https://github.com/zendframework/zend-mail/pull/61 + * Test that toArray can take format parameter + * @see https://github.com/zendframework/zend-mail/pull/61 */ - public function testToArrayFormatEncoded() + public function testToArrayFormatEncoded(): void { $raw_subject = '=?ISO-8859-2?Q?PD=3A_My=3A_Go=B3?= =?ISO-8859-2?Q?blahblah?='; $headers = new Mail\Headers(); @@ -437,7 +437,7 @@ public function testToArrayFormatEncoded() $this->assertEquals($expected, $array); } - public function testClone() + public function testClone(): void { $headers = new Mail\Headers(); $headers->addHeader(new Header\Bcc()); @@ -451,7 +451,7 @@ public function testClone() /** * @group ZF2015-04 */ - public function testHeaderCrLfAttackFromString() + public function testHeaderCrLfAttackFromString(): void { $this->expectException(Mail\Exception\RuntimeException::class); Mail\Headers::fromString("Fake: foo-bar\r\n\r\nevilContent"); @@ -460,7 +460,7 @@ public function testHeaderCrLfAttackFromString() /** * @group ZF2015-04 */ - public function testHeaderCrLfAttackAddHeaderLineSingle() + public function testHeaderCrLfAttackAddHeaderLineSingle(): void { $headers = new Mail\Headers(); $this->expectException(Exception\InvalidArgumentException::class); @@ -470,7 +470,7 @@ public function testHeaderCrLfAttackAddHeaderLineSingle() /** * @group ZF2015-04 */ - public function testHeaderCrLfAttackAddHeaderLineWithValue() + public function testHeaderCrLfAttackAddHeaderLineWithValue(): void { $headers = new Mail\Headers(); $this->expectException(Exception\InvalidArgumentException::class); @@ -480,7 +480,7 @@ public function testHeaderCrLfAttackAddHeaderLineWithValue() /** * @group ZF2015-04 */ - public function testHeaderCrLfAttackAddHeaderLineMultiple() + public function testHeaderCrLfAttackAddHeaderLineMultiple(): void { $headers = new Mail\Headers(); $this->expectException(Exception\InvalidArgumentException::class); @@ -491,7 +491,7 @@ public function testHeaderCrLfAttackAddHeaderLineMultiple() /** * @group ZF2015-04 */ - public function testHeaderCrLfAttackAddHeadersSingle() + public function testHeaderCrLfAttackAddHeadersSingle(): void { $headers = new Mail\Headers(); $this->expectException(Exception\InvalidArgumentException::class); @@ -501,7 +501,7 @@ public function testHeaderCrLfAttackAddHeadersSingle() /** * @group ZF2015-04 */ - public function testHeaderCrLfAttackAddHeadersWithValue() + public function testHeaderCrLfAttackAddHeadersWithValue(): void { $headers = new Mail\Headers(); $this->expectException(Exception\InvalidArgumentException::class); @@ -511,7 +511,7 @@ public function testHeaderCrLfAttackAddHeadersWithValue() /** * @group ZF2015-04 */ - public function testHeaderCrLfAttackAddHeadersMultiple() + public function testHeaderCrLfAttackAddHeadersMultiple(): void { $headers = new Mail\Headers(); $this->expectException(Exception\InvalidArgumentException::class); @@ -519,9 +519,9 @@ public function testHeaderCrLfAttackAddHeadersMultiple() $headers->forceLoading(); } - public function testAddressListGetEncodedFieldValueWithUtf8Domain() + public function testAddressListGetEncodedFieldValueWithUtf8Domain(): void { - $to = new Header\To; + $to = new Header\To(); $to->setEncoding('UTF-8'); $to->getAddressList()->add('local-part@ä-umlaut.de'); $encodedValue = $to->getFieldValue(Header\HeaderInterface::FORMAT_ENCODED); @@ -545,7 +545,7 @@ public function testAddressListGetEncodedFieldValueWithUtf8Domain() * * @see https://github.com/zendframework/zend-mail/issues/127 */ - public function testEmailNameParser() + public function testEmailNameParser(): void { $to = Header\To::fromString('To: "=?UTF-8?Q?=C3=B5lu?= '); @@ -561,20 +561,20 @@ public function testEmailNameParser() $this->assertEquals('õlu ', $encodedValue); } - public function testDefaultEncoding() + public function testDefaultEncoding(): void { $headers = new Mail\Headers(); $this->assertSame('ASCII', $headers->getEncoding()); } - public function testSetEncodingNoHeaders() + public function testSetEncodingNoHeaders(): void { $headers = new Mail\Headers(); $headers->setEncoding('UTF-8'); $this->assertSame('UTF-8', $headers->getEncoding()); } - public function testSetEncodingWithHeaders() + public function testSetEncodingWithHeaders(): void { $headers = new Mail\Headers(); $headers->addHeaderLine('To: test@example.com'); @@ -584,7 +584,7 @@ public function testSetEncodingWithHeaders() $this->assertSame('UTF-8', $headers->getEncoding()); } - public function testAddHeaderCallsSetEncoding() + public function testAddHeaderCallsSetEncoding(): void { $headers = new Mail\Headers(); $headers->setEncoding('UTF-8'); @@ -601,7 +601,7 @@ public function testAddHeaderCallsSetEncoding() /** * @todo Remove for 3.0.0 */ - public function testGetPluginClassLoaderEmitsDeprecationNotice() + public function testGetPluginClassLoaderEmitsDeprecationNotice(): void { $this->setDeprecationErrorHandler(); $headers = new Mail\Headers(); @@ -614,7 +614,7 @@ public function testGetPluginClassLoaderEmitsDeprecationNotice() /** * @todo Remove for 3.0.0 */ - public function testSetPluginClassLoaderEmitsDeprecationNotice() + public function testSetPluginClassLoaderEmitsDeprecationNotice(): void { $this->setDeprecationErrorHandler(); $headers = new Mail\Headers(); @@ -625,14 +625,14 @@ public function testSetPluginClassLoaderEmitsDeprecationNotice() $headers->setPluginClassLoader($loader); } - public function testGetHeaderLocatorReturnsHeaderLocatorInstanceByDefault() + public function testGetHeaderLocatorReturnsHeaderLocatorInstanceByDefault(): void { $headers = new Mail\Headers(); $locator = $headers->getHeaderLocator(); $this->assertInstanceOf(Mail\Header\HeaderLocator::class, $locator); } - public function testCanInjectAlternateHeaderLocatorInstance() + public function testCanInjectAlternateHeaderLocatorInstance(): void { $headers = new Mail\Headers(); $locator = $this->prophesize(Mail\Header\HeaderLocatorInterface::class)->reveal(); diff --git a/test/MessageFactoryTest.php b/test/MessageFactoryTest.php index 09696f7f..e1835e0a 100644 --- a/test/MessageFactoryTest.php +++ b/test/MessageFactoryTest.php @@ -21,7 +21,7 @@ */ class MessageFactoryTest extends TestCase { - public function testConstructMessageWithOptions() + public function testConstructMessageWithOptions(): void { $options = [ 'encoding' => 'UTF-8', @@ -60,7 +60,7 @@ public function testConstructMessageWithOptions() } } - public function testCanCreateMessageWithMultipleRecipientsViaArrayValue() + public function testCanCreateMessageWithMultipleRecipientsViaArrayValue(): void { $options = [ 'from' => ['matthew@example.com' => 'Matthew'], @@ -85,7 +85,7 @@ public function testCanCreateMessageWithMultipleRecipientsViaArrayValue() $this->assertTrue($to->has('list@example.com')); } - public function testIgnoresUnreconizedOptions() + public function testIgnoresUnreconizedOptions(): void { $options = [ 'foo' => 'bar', @@ -94,14 +94,13 @@ public function testIgnoresUnreconizedOptions() $this->assertInstanceOf(Message::class, $mail); } - public function testEmptyOption() + public function testEmptyOption(): void { - $options = []; $mail = MessageFactory::getInstance(); $this->assertInstanceOf(Message::class, $mail); } - public function invalidMessageOptions() + public function invalidMessageOptions(): array { return [ 'null' => [null], @@ -119,7 +118,7 @@ public function invalidMessageOptions() /** * @dataProvider invalidMessageOptions */ - public function testExceptionForOptionsNotArrayOrTraversable($options) + public function testExceptionForOptionsNotArrayOrTraversable($options): void { $this->expectException(Exception\InvalidArgumentException::class); MessageFactory::getInstance($options); diff --git a/test/MessageTest.php b/test/MessageTest.php index 734ca227..c3920070 100644 --- a/test/MessageTest.php +++ b/test/MessageTest.php @@ -31,17 +31,17 @@ class MessageTest extends TestCase /** @var Message */ public $message; - public function setUp() + public function setUp(): void { $this->message = new Message(); } - public function testInvalidByDefault() + public function testInvalidByDefault(): void { $this->assertFalse($this->message->isValid()); } - public function testSetsOrigDateHeaderByDefault() + public function testSetsOrigDateHeaderByDefault(): void { $headers = $this->message->getHeaders(); $this->assertInstanceOf(Headers::class, $headers); @@ -54,26 +54,26 @@ public function testSetsOrigDateHeaderByDefault() $this->assertEquals($date, $test); } - public function testAddingFromAddressMarksAsValid() + public function testAddingFromAddressMarksAsValid(): void { $this->message->addFrom('test@example.com'); $this->assertTrue($this->message->isValid()); } - public function testHeadersMethodReturnsHeadersObject() + public function testHeadersMethodReturnsHeadersObject(): void { $headers = $this->message->getHeaders(); $this->assertInstanceOf(Headers::class, $headers); } - public function testToMethodReturnsAddressListObject() + public function testToMethodReturnsAddressListObject(): void { $this->message->addTo('test@example.com'); $to = $this->message->getTo(); $this->assertInstanceOf(AddressList::class, $to); } - public function testToAddressListLivesInHeaders() + public function testToAddressListLivesInHeaders(): void { $this->message->addTo('test@example.com'); $to = $this->message->getTo(); @@ -84,14 +84,14 @@ public function testToAddressListLivesInHeaders() $this->assertSame($header->getAddressList(), $to); } - public function testFromMethodReturnsAddressListObject() + public function testFromMethodReturnsAddressListObject(): void { $this->message->addFrom('test@example.com'); $from = $this->message->getFrom(); $this->assertInstanceOf(AddressList::class, $from); } - public function testFromAddressListLivesInHeaders() + public function testFromAddressListLivesInHeaders(): void { $this->message->addFrom('test@example.com'); $from = $this->message->getFrom(); @@ -102,14 +102,14 @@ public function testFromAddressListLivesInHeaders() $this->assertSame($header->getAddressList(), $from); } - public function testCcMethodReturnsAddressListObject() + public function testCcMethodReturnsAddressListObject(): void { $this->message->addCc('test@example.com'); $cc = $this->message->getCc(); $this->assertInstanceOf(AddressList::class, $cc); } - public function testCcAddressListLivesInHeaders() + public function testCcAddressListLivesInHeaders(): void { $this->message->addCc('test@example.com'); $cc = $this->message->getCc(); @@ -120,14 +120,14 @@ public function testCcAddressListLivesInHeaders() $this->assertSame($header->getAddressList(), $cc); } - public function testBccMethodReturnsAddressListObject() + public function testBccMethodReturnsAddressListObject(): void { $this->message->addBcc('test@example.com'); $bcc = $this->message->getBcc(); $this->assertInstanceOf(AddressList::class, $bcc); } - public function testBccAddressListLivesInHeaders() + public function testBccAddressListLivesInHeaders(): void { $this->message->addBcc('test@example.com'); $bcc = $this->message->getBcc(); @@ -138,14 +138,14 @@ public function testBccAddressListLivesInHeaders() $this->assertSame($header->getAddressList(), $bcc); } - public function testReplyToMethodReturnsAddressListObject() + public function testReplyToMethodReturnsAddressListObject(): void { $this->message->addReplyTo('test@example.com'); $replyTo = $this->message->getReplyTo(); $this->assertInstanceOf(AddressList::class, $replyTo); } - public function testReplyToAddressListLivesInHeaders() + public function testReplyToAddressListLivesInHeaders(): void { $this->message->addReplyTo('test@example.com'); $replyTo = $this->message->getReplyTo(); @@ -156,26 +156,26 @@ public function testReplyToAddressListLivesInHeaders() $this->assertSame($header->getAddressList(), $replyTo); } - public function testSenderIsNullByDefault() + public function testSenderIsNullByDefault(): void { $this->assertNull($this->message->getSender()); } - public function testNullSenderDoesNotCreateHeader() + public function testNullSenderDoesNotCreateHeader(): void { $sender = $this->message->getSender(); $headers = $this->message->getHeaders(); $this->assertFalse($headers->has('sender')); } - public function testSettingSenderCreatesAddressObject() + public function testSettingSenderCreatesAddressObject(): void { $this->message->setSender('test@example.com'); $sender = $this->message->getSender(); $this->assertInstanceOf(Address::class, $sender); } - public function testCanSpecifyNameWhenSettingSender() + public function testCanSpecifyNameWhenSettingSender(): void { $this->message->setSender('test@example.com', 'Example Test'); $sender = $this->message->getSender(); @@ -183,7 +183,7 @@ public function testCanSpecifyNameWhenSettingSender() $this->assertEquals('Example Test', $sender->getName()); } - public function testCanProvideAddressObjectWhenSettingSender() + public function testCanProvideAddressObjectWhenSettingSender(): void { $sender = new Address('test@example.com'); $this->message->setSender($sender); @@ -191,7 +191,7 @@ public function testCanProvideAddressObjectWhenSettingSender() $this->assertSame($sender, $test); } - public function testSenderAccessorsProxyToSenderHeader() + public function testSenderAccessorsProxyToSenderHeader(): void { $header = new Header\Sender(); $this->message->getHeaders()->addHeader($header); @@ -200,7 +200,7 @@ public function testSenderAccessorsProxyToSenderHeader() $this->assertSame($address, $header->getAddress()); } - public function testCanAddFromAddressUsingName() + public function testCanAddFromAddressUsingName(): void { $this->message->addFrom('test@example.com', 'Example Test'); $addresses = $this->message->getFrom(); @@ -210,7 +210,7 @@ public function testCanAddFromAddressUsingName() $this->assertEquals('Example Test', $address->getName()); } - public function testCanAddFromAddressUsingEmailAndNameAsString() + public function testCanAddFromAddressUsingEmailAndNameAsString(): void { $this->message->addFrom('Example Test '); $addresses = $this->message->getFrom(); @@ -220,7 +220,7 @@ public function testCanAddFromAddressUsingEmailAndNameAsString() $this->assertEquals('Example Test', $address->getName()); } - public function testCanAddFromAddressUsingAddressObject() + public function testCanAddFromAddressUsingAddressObject(): void { $address = new Address('test@example.com', 'Example Test'); $this->message->addFrom($address); @@ -231,7 +231,7 @@ public function testCanAddFromAddressUsingAddressObject() $this->assertSame($address, $test); } - public function testCanAddManyFromAddressesUsingArray() + public function testCanAddManyFromAddressesUsingArray(): void { $addresses = [ 'test@example.com', @@ -248,7 +248,7 @@ public function testCanAddManyFromAddressesUsingArray() $this->assertTrue($from->has('announce@example.com')); } - public function testCanAddManyFromAddressesUsingAddressListObject() + public function testCanAddManyFromAddressesUsingAddressListObject(): void { $list = new AddressList(); $list->add('test@example.com'); @@ -261,7 +261,7 @@ public function testCanAddManyFromAddressesUsingAddressListObject() $this->assertTrue($from->has('test@example.com')); } - public function testCanSetFromListFromAddressList() + public function testCanSetFromListFromAddressList(): void { $list = new AddressList(); $list->add('test@example.com'); @@ -274,7 +274,7 @@ public function testCanSetFromListFromAddressList() $this->assertTrue($from->has('test@example.com')); } - public function testCanAddCcAddressUsingName() + public function testCanAddCcAddressUsingName(): void { $this->message->addCc('test@example.com', 'Example Test'); $addresses = $this->message->getCc(); @@ -284,7 +284,7 @@ public function testCanAddCcAddressUsingName() $this->assertEquals('Example Test', $address->getName()); } - public function testCanAddCcAddressUsingAddressObject() + public function testCanAddCcAddressUsingAddressObject(): void { $address = new Address('test@example.com', 'Example Test'); $this->message->addCc($address); @@ -295,7 +295,7 @@ public function testCanAddCcAddressUsingAddressObject() $this->assertSame($address, $test); } - public function testCanAddManyCcAddressesUsingArray() + public function testCanAddManyCcAddressesUsingArray(): void { $addresses = [ 'test@example.com', @@ -312,7 +312,7 @@ public function testCanAddManyCcAddressesUsingArray() $this->assertTrue($cc->has('announce@example.com')); } - public function testCanAddManyCcAddressesUsingAddressListObject() + public function testCanAddManyCcAddressesUsingAddressListObject(): void { $list = new AddressList(); $list->add('test@example.com'); @@ -325,7 +325,7 @@ public function testCanAddManyCcAddressesUsingAddressListObject() $this->assertTrue($cc->has('test@example.com')); } - public function testCanSetCcListFromAddressList() + public function testCanSetCcListFromAddressList(): void { $list = new AddressList(); $list->add('test@example.com'); @@ -338,7 +338,7 @@ public function testCanSetCcListFromAddressList() $this->assertTrue($cc->has('test@example.com')); } - public function testCanAddBccAddressUsingName() + public function testCanAddBccAddressUsingName(): void { $this->message->addBcc('test@example.com', 'Example Test'); $addresses = $this->message->getBcc(); @@ -348,7 +348,7 @@ public function testCanAddBccAddressUsingName() $this->assertEquals('Example Test', $address->getName()); } - public function testCanAddBccAddressUsingAddressObject() + public function testCanAddBccAddressUsingAddressObject(): void { $address = new Address('test@example.com', 'Example Test'); $this->message->addBcc($address); @@ -359,7 +359,7 @@ public function testCanAddBccAddressUsingAddressObject() $this->assertSame($address, $test); } - public function testCanAddManyBccAddressesUsingArray() + public function testCanAddManyBccAddressesUsingArray(): void { $addresses = [ 'test@example.com', @@ -376,7 +376,7 @@ public function testCanAddManyBccAddressesUsingArray() $this->assertTrue($bcc->has('announce@example.com')); } - public function testCanAddManyBccAddressesUsingAddressListObject() + public function testCanAddManyBccAddressesUsingAddressListObject(): void { $list = new AddressList(); $list->add('test@example.com'); @@ -389,7 +389,7 @@ public function testCanAddManyBccAddressesUsingAddressListObject() $this->assertTrue($bcc->has('test@example.com')); } - public function testCanSetBccListFromAddressList() + public function testCanSetBccListFromAddressList(): void { $list = new AddressList(); $list->add('test@example.com'); @@ -402,7 +402,7 @@ public function testCanSetBccListFromAddressList() $this->assertTrue($bcc->has('test@example.com')); } - public function testCanAddReplyToAddressUsingName() + public function testCanAddReplyToAddressUsingName(): void { $this->message->addReplyTo('test@example.com', 'Example Test'); $addresses = $this->message->getReplyTo(); @@ -412,7 +412,7 @@ public function testCanAddReplyToAddressUsingName() $this->assertEquals('Example Test', $address->getName()); } - public function testCanAddReplyToAddressUsingAddressObject() + public function testCanAddReplyToAddressUsingAddressObject(): void { $address = new Address('test@example.com', 'Example Test'); $this->message->addReplyTo($address); @@ -423,7 +423,7 @@ public function testCanAddReplyToAddressUsingAddressObject() $this->assertSame($address, $test); } - public function testCanAddManyReplyToAddressesUsingArray() + public function testCanAddManyReplyToAddressesUsingArray(): void { $addresses = [ 'test@example.com', @@ -440,7 +440,7 @@ public function testCanAddManyReplyToAddressesUsingArray() $this->assertTrue($replyTo->has('announce@example.com')); } - public function testCanAddManyReplyToAddressesUsingAddressListObject() + public function testCanAddManyReplyToAddressesUsingAddressListObject(): void { $list = new AddressList(); $list->add('test@example.com'); @@ -453,7 +453,7 @@ public function testCanAddManyReplyToAddressesUsingAddressListObject() $this->assertTrue($replyTo->has('test@example.com')); } - public function testCanSetReplyToListFromAddressList() + public function testCanSetReplyToListFromAddressList(): void { $list = new AddressList(); $list->add('test@example.com'); @@ -466,26 +466,26 @@ public function testCanSetReplyToListFromAddressList() $this->assertTrue($replyTo->has('test@example.com')); } - public function testSubjectIsEmptyByDefault() + public function testSubjectIsEmptyByDefault(): void { $this->assertNull($this->message->getSubject()); } - public function testSubjectIsMutable() + public function testSubjectIsMutable(): void { $this->message->setSubject('test subject'); $subject = $this->message->getSubject(); $this->assertEquals('test subject', $subject); } - public function testSubjectIsMutableReplaceExisting() + public function testSubjectIsMutableReplaceExisting(): void { $this->message->setSubject('test subject'); $this->message->setSubject('new subject'); $this->assertSame('new subject', $this->message->getSubject()); } - public function testSettingSubjectProxiesToHeader() + public function testSettingSubjectProxiesToHeader(): void { $this->message->setSubject('test subject'); $headers = $this->message->getHeaders(); @@ -495,18 +495,18 @@ public function testSettingSubjectProxiesToHeader() $this->assertEquals('test subject', $header->getFieldValue()); } - public function testBodyIsEmptyByDefault() + public function testBodyIsEmptyByDefault(): void { $this->assertNull($this->message->getBody()); } - public function testMaySetBodyFromString() + public function testMaySetBodyFromString(): void { $this->message->setBody('body'); $this->assertEquals('body', $this->message->getBody()); } - public function testMaySetBodyFromStringSerializableObject() + public function testMaySetBodyFromStringSerializableObject(): void { $object = new TestAsset\StringSerializableObject('body'); $this->message->setBody($object); @@ -514,39 +514,39 @@ public function testMaySetBodyFromStringSerializableObject() $this->assertEquals('body', $this->message->getBodyText()); } - public function testMaySetBodyFromMimeMessage() + public function testMaySetBodyFromMimeMessage(): void { $body = new MimeMessage(); $this->message->setBody($body); $this->assertSame($body, $this->message->getBody()); } - public function testMaySetNullBody() + public function testMaySetNullBody(): void { $this->message->setBody(null); $this->assertNull($this->message->getBody()); } - public static function invalidBodyValues() + public static function invalidBodyValues(): array { return [ [['foo']], [true], [false], - [new stdClass], + [new stdClass()], ]; } /** * @dataProvider invalidBodyValues */ - public function testSettingNonScalarNonMimeNonStringSerializableValueForBodyRaisesException($body) + public function testSettingNonScalarNonMimeNonStringSerializableValueForBodyRaisesException($body): void { $this->expectException(Exception\InvalidArgumentException::class); $this->message->setBody($body); } - public function testSettingBodyFromSinglePartMimeMessageSetsAppropriateHeaders() + public function testSettingBodyFromSinglePartMimeMessageSetsAppropriateHeaders(): void { $mime = new Mime('foo-bar'); $part = new MimePart('foo'); @@ -568,7 +568,7 @@ public function testSettingBodyFromSinglePartMimeMessageSetsAppropriateHeaders() $this->assertEquals('text/html', $header->getFieldValue()); } - public function testSettingUtf8MailBodyFromSinglePartMimeUtf8MessageSetsAppropriateHeaders() + public function testSettingUtf8MailBodyFromSinglePartMimeUtf8MessageSetsAppropriateHeaders(): void { $mime = new Mime('foo-bar'); $part = new MimePart('UTF-8 TestString: AaÜüÄäÖöß'); @@ -589,7 +589,7 @@ public function testSettingUtf8MailBodyFromSinglePartMimeUtf8MessageSetsAppropri ); } - public function testSettingBodyFromMultiPartMimeMessageSetsAppropriateHeaders() + public function testSettingBodyFromMultiPartMimeMessageSetsAppropriateHeaders(): void { $mime = new Mime('foo-bar'); $text = new MimePart('foo'); @@ -614,7 +614,7 @@ public function testSettingBodyFromMultiPartMimeMessageSetsAppropriateHeaders() $this->assertEquals("multipart/mixed;\r\n boundary=\"foo-bar\"", $header->getFieldValue()); } - public function testRetrievingBodyTextFromMessageWithMultiPartMimeBodyReturnsMimeSerialization() + public function testRetrievingBodyTextFromMessageWithMultiPartMimeBodyReturnsMimeSerialization(): void { $mime = new Mime('foo-bar'); $text = new MimePart('foo'); @@ -636,25 +636,25 @@ public function testRetrievingBodyTextFromMessageWithMultiPartMimeBodyReturnsMim $this->assertContains('Content-Type: text/html', $text); } - public function testEncodingIsAsciiByDefault() + public function testEncodingIsAsciiByDefault(): void { $this->assertEquals('ASCII', $this->message->getEncoding()); } - public function testEncodingIsMutable() + public function testEncodingIsMutable(): void { $this->message->setEncoding('UTF-8'); $this->assertEquals('UTF-8', $this->message->getEncoding()); } - public function testMessageReturnsNonEncodedSubject() + public function testMessageReturnsNonEncodedSubject(): void { $this->message->setSubject('This is a subject'); $this->message->setEncoding('UTF-8'); $this->assertEquals('This is a subject', $this->message->getSubject()); } - public function testSettingNonAsciiEncodingForcesMimeEncodingOfSomeHeaders() + public function testSettingNonAsciiEncodingForcesMimeEncodingOfSomeHeaders(): void { $this->message->addTo('test@example.com', 'Laminas DevTeam'); $this->message->addFrom('matthew@example.com', "Matthew Weier O'Phinney"); @@ -688,7 +688,7 @@ public function testSettingNonAsciiEncodingForcesMimeEncodingOfSomeHeaders() /** * @group Laminas-507 */ - public function testDefaultDateHeaderEncodingIsAlwaysAscii() + public function testDefaultDateHeaderEncodingIsAlwaysAscii(): void { $this->message->setEncoding('utf-8'); $headers = $this->message->getHeaders(); @@ -700,7 +700,7 @@ public function testDefaultDateHeaderEncodingIsAlwaysAscii() $this->assertEquals($date, $test); } - public function testRestoreFromSerializedString() + public function testRestoreFromSerializedString(): void { $this->message->addTo('test@example.com', 'Example Test'); $this->message->addFrom('matthew@example.com', "Matthew Weier O'Phinney"); @@ -715,7 +715,7 @@ public function testRestoreFromSerializedString() /** * @group 45 */ - public function testCanRestoreFromSerializedStringWhenBodyContainsMultipleNewlines() + public function testCanRestoreFromSerializedStringWhenBodyContainsMultipleNewlines(): void { $this->message->addTo('test@example.com', 'Example Test'); $this->message->addFrom('matthew@example.com', "Matthew Weier O'Phinney"); @@ -730,7 +730,7 @@ public function testCanRestoreFromSerializedStringWhenBodyContainsMultipleNewlin /** * @group Laminas-5962 */ - public function testPassEmptyArrayIntoSetPartsOfMimeMessageShouldReturnEmptyBodyString() + public function testPassEmptyArrayIntoSetPartsOfMimeMessageShouldReturnEmptyBodyString(): void { $mimeMessage = new MimeMessage(); $mimeMessage->setParts([]); @@ -739,7 +739,7 @@ public function testPassEmptyArrayIntoSetPartsOfMimeMessageShouldReturnEmptyBody $this->assertEquals('', $this->message->getBodyText()); } - public function messageRecipients() + public function messageRecipients(): array { return [ 'setFrom' => ['setFrom'], @@ -759,7 +759,7 @@ public function messageRecipients() * @group ZF2015-04 * @dataProvider messageRecipients */ - public function testRaisesExceptionWhenAttemptingToSerializeMessageWithCRLFInjectionViaHeader($recipientMethod) + public function testExceptionWhenAttemptingToSerializeMessageWithCRLFInjectionViaHeader($recipientMethod): void { $subject = [ 'test1', @@ -774,7 +774,7 @@ public function testRaisesExceptionWhenAttemptingToSerializeMessageWithCRLFInjec /** * @group ZF2015-04 */ - public function testDetectsCRLFInjectionViaSubject() + public function testDetectsCRLFInjectionViaSubject(): void { $subject = [ 'test1', @@ -789,7 +789,7 @@ public function testDetectsCRLFInjectionViaSubject() $this->assertNotContains("\r\n", $serializedHeaders); } - public function testHeaderUnfoldingWorksAsExpectedForMultipartMessages() + public function testHeaderUnfoldingWorksAsExpectedForMultipartMessages(): void { $text = new MimePart('Test content'); $text->type = Mime::TYPE_TEXT; @@ -827,7 +827,7 @@ public function testHeaderUnfoldingWorksAsExpectedForMultipartMessages() /** * @group 19 */ - public function testCanParseMultipartReport() + public function testCanParseMultipartReport(): void { $raw = file_get_contents(__DIR__ . '/_files/laminas-mail-19.txt'); $message = Message::fromString($raw); @@ -849,7 +849,7 @@ public function testCanParseMultipartReport() $this->assertEquals('multipart/report', $contentType->getType()); } - public function testMailHeaderContainsZeroValue() + public function testMailHeaderContainsZeroValue(): void { $message = "From: someone@example.com\r\n" @@ -867,7 +867,7 @@ public function testMailHeaderContainsZeroValue() /** * @ref CVE-2016-10033 which targeted WordPress */ - public function testSecondCodeInjectionInFromHeader() + public function testSecondCodeInjectionInFromHeader(): void { $message = new Message(); $this->expectException(Exception\InvalidArgumentException::class); @@ -876,7 +876,7 @@ public function testSecondCodeInjectionInFromHeader() // @codingStandardsIgnoreEnd } - public function testMessageSubjectFromString() + public function testMessageSubjectFromString(): void { $rawMessage = 'Subject: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=' . "\r\n" . ' =?UTF-8?Q?vowels=20=C3=B2=C3=A0=C3=B9=C3=A8=C3=A9=C3=AC?='; @@ -889,7 +889,7 @@ public function testMessageSubjectFromString() ); } - public function testMessageSubjectSetSubject() + public function testMessageSubjectSetSubject(): void { $mail = new Message(); $mail->setSubject('Non “ascii” characters like accented vowels òàùèéì'); @@ -901,7 +901,7 @@ public function testMessageSubjectSetSubject() ); } - public function testCorrectHeaderEncodingAddHeader() + public function testCorrectHeaderEncodingAddHeader(): void { $mail = new Message(); $header = new GenericHeader('X-Test', 'Non “ascii” characters like accented vowels òàùèéì'); @@ -914,7 +914,7 @@ public function testCorrectHeaderEncodingAddHeader() ); } - public function testCorrectHeaderEncodingSetHeaders() + public function testCorrectHeaderEncodingSetHeaders(): void { $mail = new Message(); $header = new GenericHeader('X-Test', 'Non “ascii” characters like accented vowels òàùèéì'); @@ -929,7 +929,7 @@ public function testCorrectHeaderEncodingSetHeaders() ); } - public function testCorrectHeaderEncodingFromString() + public function testCorrectHeaderEncodingFromString(): void { $mail = new Message(); $str = 'X-Test: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=' . "\r\n" @@ -944,7 +944,7 @@ public function testCorrectHeaderEncodingFromString() ); } - public function testCorrectHeaderEncodingFromStringAndSetHeaders() + public function testCorrectHeaderEncodingFromStringAndSetHeaders(): void { $mail = new Message(); $str = 'X-Test: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=' . "\r\n" @@ -962,7 +962,7 @@ public function testCorrectHeaderEncodingFromStringAndSetHeaders() ); } - public function testMessageSubjectEncodingWhenEncodingSetAfterTheSubject() + public function testMessageSubjectEncodingWhenEncodingSetAfterTheSubject(): void { $mail = new Message(); $mail->setSubject('hello world'); @@ -975,7 +975,7 @@ public function testMessageSubjectEncodingWhenEncodingSetAfterTheSubject() ); } - public function testMessageSubjectEncodingWhenEcodingSetBeforeTheSubject() + public function testMessageSubjectEncodingWhenEcodingSetBeforeTheSubject(): void { $mail = new Message(); $mail->setEncoding('UTF-8'); diff --git a/test/ModuleTest.php b/test/ModuleTest.php index 1f31b4d6..1979e2c6 100644 --- a/test/ModuleTest.php +++ b/test/ModuleTest.php @@ -17,7 +17,7 @@ */ class ModuleTest extends TestCase { - public function testInvoke() + public function testInvoke(): void { $module = new Module(); $config = $module->getConfig(); diff --git a/test/Protocol/ProtocolTraitTest.php b/test/Protocol/ProtocolTraitTest.php index e541212a..1dfa48f5 100644 --- a/test/Protocol/ProtocolTraitTest.php +++ b/test/Protocol/ProtocolTraitTest.php @@ -16,10 +16,7 @@ */ class ProtocolTraitTest extends TestCase { - /** - * @requires PHP 5.6.7 - */ - public function testTls12Version() + public function testTls12Version(): void { $mock = $this->getMockForTrait(ProtocolTrait::class); diff --git a/test/Protocol/Smtp/Auth/Crammd5Test.php b/test/Protocol/Smtp/Auth/Crammd5Test.php index 22d34d52..c3f43918 100644 --- a/test/Protocol/Smtp/Auth/Crammd5Test.php +++ b/test/Protocol/Smtp/Auth/Crammd5Test.php @@ -23,12 +23,12 @@ class Crammd5Test extends TestCase */ protected $auth; - public function setUp() + public function setUp(): void { $this->auth = new Crammd5(); } - public function testHmacMd5ReturnsExpectedHash() + public function testHmacMd5ReturnsExpectedHash(): void { $class = new ReflectionClass(Crammd5::class); $method = $class->getMethod('hmacMd5'); @@ -42,13 +42,13 @@ public function testHmacMd5ReturnsExpectedHash() $this->assertEquals('be56fa81a5671e0c62e00134180aae2c', $result); } - public function testUsernameAccessors() + public function testUsernameAccessors(): void { $this->auth->setUsername('test'); $this->assertEquals('test', $this->auth->getUsername()); } - public function testPasswordAccessors() + public function testPasswordAccessors(): void { $this->auth->setPassword('test'); $this->assertEquals('test', $this->auth->getPassword()); diff --git a/test/Protocol/SmtpPluginManagerCompatibilityTest.php b/test/Protocol/SmtpPluginManagerCompatibilityTest.php index f2e566c3..4fff92b9 100644 --- a/test/Protocol/SmtpPluginManagerCompatibilityTest.php +++ b/test/Protocol/SmtpPluginManagerCompatibilityTest.php @@ -19,17 +19,17 @@ class SmtpPluginManagerCompatibilityTest extends TestCase { use CommonPluginManagerTrait; - protected function getPluginManager() + protected function getPluginManager(): SmtpPluginManager { return new SmtpPluginManager(new ServiceManager()); } - protected function getV2InvalidPluginException() + protected function getV2InvalidPluginException(): string { return InvalidArgumentException::class; } - protected function getInstanceOf() + protected function getInstanceOf(): string { return Smtp::class; } diff --git a/test/Protocol/SmtpPluginManagerFactoryTest.php b/test/Protocol/SmtpPluginManagerFactoryTest.php index 81fb8fae..2928290b 100644 --- a/test/Protocol/SmtpPluginManagerFactoryTest.php +++ b/test/Protocol/SmtpPluginManagerFactoryTest.php @@ -17,7 +17,7 @@ class SmtpPluginManagerFactoryTest extends TestCase { - public function testFactoryReturnsPluginManager() + public function testFactoryReturnsPluginManager(): void { $container = $this->prophesize(ContainerInterface::class)->reveal(); $factory = new SmtpPluginManagerFactory(); @@ -37,7 +37,7 @@ public function testFactoryReturnsPluginManager() /** * @depends testFactoryReturnsPluginManager */ - public function testFactoryConfiguresPluginManagerUnderContainerInterop() + public function testFactoryConfiguresPluginManagerUnderContainerInterop(): void { $container = $this->prophesize(ContainerInterface::class)->reveal(); $smtp = $this->prophesize(Smtp::class)->reveal(); @@ -54,7 +54,7 @@ public function testFactoryConfiguresPluginManagerUnderContainerInterop() /** * @depends testFactoryReturnsPluginManager */ - public function testFactoryConfiguresPluginManagerUnderServiceManagerV2() + public function testFactoryConfiguresPluginManagerUnderServiceManagerV2(): void { $container = $this->prophesize(ServiceLocatorInterface::class); $container->willImplement(ContainerInterface::class); diff --git a/test/Protocol/SmtpTest.php b/test/Protocol/SmtpTest.php index e81bb36b..c7be4270 100644 --- a/test/Protocol/SmtpTest.php +++ b/test/Protocol/SmtpTest.php @@ -26,14 +26,14 @@ class SmtpTest extends TestCase /** @var SmtpProtocolSpy */ public $connection; - public function setUp() + public function setUp(): void { $this->transport = new Smtp(); $this->connection = new SmtpProtocolSpy(); $this->transport->setConnection($this->connection); } - public function testSendMinimalMail() + public function testSendMinimalMail(): void { $headers = new Headers(); $headers->addHeaderLine('Date', 'Sun, 10 Jun 2012 20:07:24 +0200'); @@ -60,7 +60,7 @@ public function testSendMinimalMail() $this->assertEquals($expectedMessage, $this->connection->getLog()); } - public function testSendEscapedEmail() + public function testSendEscapedEmail(): void { $headers = new Headers(); $headers->addHeaderLine('Date', 'Sun, 10 Jun 2012 20:07:24 +0200'); @@ -88,13 +88,13 @@ public function testSendEscapedEmail() $this->assertEquals($expectedMessage, $this->connection->getLog()); } - public function testDisconnectCallsQuit() + public function testDisconnectCallsQuit(): void { $this->connection->disconnect(); $this->assertTrue($this->connection->calledQuit); } - public function testDisconnectResetsAuthFlag() + public function testDisconnectResetsAuthFlag(): void { $this->connection->connect(); $this->connection->setSessionStatus(true); @@ -104,7 +104,7 @@ public function testDisconnectResetsAuthFlag() $this->assertFalse($this->connection->getAuth()); } - public function testConnectHasVerboseErrors() + public function testConnectHasVerboseErrors(): void { $smtp = new TestAsset\ErroneousSmtp(); @@ -114,7 +114,7 @@ public function testConnectHasVerboseErrors() $smtp->connect('nonexistentremote'); } - public function testCanAvoidQuitRequest() + public function testCanAvoidQuitRequest(): void { $this->assertTrue($this->connection->useCompleteQuit(), 'Default behaviour must be BC'); @@ -141,7 +141,7 @@ public function testCanAvoidQuitRequest() $this->assertFalse($connection->useCompleteQuit()); } - public function testAuthThrowsWhenAlreadyAuthed() + public function testAuthThrowsWhenAlreadyAuthed(): void { $this->connection->setAuth(true); $this->expectException(Exception\RuntimeException::class); @@ -149,7 +149,7 @@ public function testAuthThrowsWhenAlreadyAuthed() $this->connection->auth(); } - public function testHeloThrowsWhenAlreadySession() + public function testHeloThrowsWhenAlreadySession(): void { $this->connection->helo('hostname.test'); $this->expectException(Exception\RuntimeException::class); @@ -157,28 +157,28 @@ public function testHeloThrowsWhenAlreadySession() $this->connection->helo('hostname.test'); } - public function testHeloThrowsWithInvalidHostname() + public function testHeloThrowsWithInvalidHostname(): void { $this->expectException(Exception\RuntimeException::class); $this->expectExceptionMessage('The input does not match the expected structure for a DNS hostname'); $this->connection->helo("invalid\r\nhost name"); } - public function testMailThrowsWhenNoSession() + public function testMailThrowsWhenNoSession(): void { $this->expectException(Exception\RuntimeException::class); $this->expectExceptionMessage('A valid session has not been started'); $this->connection->mail('test@example.com'); } - public function testRcptThrowsWhenNoMail() + public function testRcptThrowsWhenNoMail(): void { $this->expectException(Exception\RuntimeException::class); $this->expectExceptionMessage('No sender reverse path has been supplied'); $this->connection->rcpt('test@example.com'); } - public function testDataThrowsWhenNoRcpt() + public function testDataThrowsWhenNoRcpt(): void { $this->expectException(Exception\RuntimeException::class); $this->expectExceptionMessage('No recipient forward path has been supplied'); diff --git a/test/Protocol/TestAsset/ErroneousSmtp.php b/test/Protocol/TestAsset/ErroneousSmtp.php index 0279ed33..ec8614e5 100644 --- a/test/Protocol/TestAsset/ErroneousSmtp.php +++ b/test/Protocol/TestAsset/ErroneousSmtp.php @@ -15,7 +15,7 @@ */ final class ErroneousSmtp extends AbstractProtocol { - public function connect($customRemote = null) + public function connect($customRemote = null): bool { return $this->_connect($customRemote); } diff --git a/test/Storage/ImapTest.php b/test/Storage/ImapTest.php index 84b519ef..dc4726bc 100644 --- a/test/Storage/ImapTest.php +++ b/test/Storage/ImapTest.php @@ -21,14 +21,14 @@ class ImapTest extends TestCase { protected $params; - public function setUp() + public function setUp(): void { if (! getenv('TESTS_LAMINAS_MAIL_IMAP_ENABLED')) { $this->markTestSkipped('Laminas_Mail IMAP tests are not enabled'); } $this->params = ['host' => getenv('TESTS_LAMINAS_MAIL_IMAP_HOST'), 'user' => getenv('TESTS_LAMINAS_MAIL_IMAP_USER'), - 'password' => getenv('TESTS_LAMINAS_MAIL_IMAP_PASSWORD')]; + 'password' => getenv('TESTS_LAMINAS_MAIL_IMAP_PASSWORD'), ]; if (getenv('TESTS_LAMINAS_MAIL_SERVER_TESTDIR') && getenv('TESTS_LAMINAS_MAIL_SERVER_TESTDIR')) { if (! file_exists(getenv('TESTS_LAMINAS_MAIL_SERVER_TESTDIR') . DIRECTORY_SEPARATOR . 'inbox') && ! file_exists(getenv('TESTS_LAMINAS_MAIL_SERVER_TESTDIR') . DIRECTORY_SEPARATOR . 'INBOX') @@ -49,7 +49,7 @@ public function setUp() } } - protected function cleanDir($dir) + protected function cleanDir($dir): void { $dh = opendir($dir); while (($entry = readdir($dh)) !== false) { @@ -67,7 +67,7 @@ protected function cleanDir($dir) closedir($dh); } - protected function copyDir($dir, $dest) + protected function copyDir($dir, $dest): void { $dh = opendir($dir); while (($entry = readdir($dh)) !== false) { @@ -86,31 +86,30 @@ protected function copyDir($dir, $dest) closedir($dh); } - public function testConnectOk() + public function testConnectOk(): void { new Storage\Imap($this->params); } - public function testConnectConfig() + public function testConnectConfig(): void { new Storage\Imap(new Config\Config($this->params)); } - public function testConnectFailure() + public function testConnectFailure(): void { $this->params['host'] = 'example.example'; $this->expectException(Exception\InvalidArgumentException::class); new Storage\Imap($this->params); } - public function testNoParams() + public function testNoParams(): void { $this->expectException(Exception\InvalidArgumentException::class); new Storage\Imap([]); } - - public function testConnectSSL() + public function testConnectSSL(): void { if (! getenv('TESTS_LAMINAS_MAIL_IMAP_SSL')) { return; @@ -120,7 +119,7 @@ public function testConnectSSL() new Storage\Imap($this->params); } - public function testConnectTLS() + public function testConnectTLS(): void { if (! getenv('TESTS_LAMINAS_MAIL_IMAP_TLS')) { return; @@ -130,7 +129,7 @@ public function testConnectTLS() new Storage\Imap($this->params); } - public function testConnectSelfSignedSSL() + public function testConnectSelfSignedSSL(): void { if (! getenv('TESTS_LAMINAS_MAIL_IMAP_SSL')) { return; @@ -141,21 +140,21 @@ public function testConnectSelfSignedSSL() new Storage\Imap($this->params); } - public function testInvalidService() + public function testInvalidService(): void { $this->params['port'] = getenv('TESTS_LAMINAS_MAIL_IMAP_INVALID_PORT'); $this->expectException(Exception\InvalidArgumentException::class); new Storage\Imap($this->params); } - public function testWrongService() + public function testWrongService(): void { $this->params['port'] = getenv('TESTS_LAMINAS_MAIL_IMAP_WRONG_PORT'); $this->expectException(Exception\InvalidArgumentException::class); new Storage\Imap($this->params); } - public function testWrongUsername() + public function testWrongUsername(): void { // this also triggers ...{chars}token for coverage $this->params['user'] = "there is no\nnobody"; @@ -163,7 +162,7 @@ public function testWrongUsername() new Storage\Imap($this->params); } - public function testWithInstanceConstruction() + public function testWithInstanceConstruction(): void { $protocol = new Protocol\Imap($this->params['host']); $protocol->login($this->params['user'], $this->params['password']); @@ -171,21 +170,21 @@ public function testWithInstanceConstruction() new Storage\Imap($protocol); } - public function testWithNotConnectedInstance() + public function testWithNotConnectedInstance(): void { $protocol = new Protocol\Imap(); $this->expectException(Exception\InvalidArgumentException::class); new Storage\Imap($protocol); } - public function testWithNotLoggedInstance() + public function testWithNotLoggedInstance(): void { $protocol = new Protocol\Imap($this->params['host']); $this->expectException(Exception\InvalidArgumentException::class); new Storage\Imap($protocol); } - public function testWrongFolder() + public function testWrongFolder(): void { $this->params['folder'] = 'this folder does not exist on your server'; @@ -193,8 +192,7 @@ public function testWrongFolder() new Storage\Imap($this->params); } - - public function testClose() + public function testClose(): void { $mail = new Storage\Imap($this->params); $mail->close(); @@ -209,20 +207,20 @@ public function testHasTop() $this->assertTrue($mail->hasTop); } */ - public function testHasCreate() + public function testHasCreate(): void { $mail = new Storage\Imap($this->params); $this->assertFalse($mail->hasCreate); } - public function testNoop() + public function testNoop(): void { $mail = new Storage\Imap($this->params); $mail->noop(); } - public function testCount() + public function testCount(): void { $mail = new Storage\Imap($this->params); @@ -230,17 +228,16 @@ public function testCount() $this->assertEquals(7, $count); } - public function testSize() + public function testSize(): void { $mail = new Storage\Imap($this->params); $shouldSizes = [1 => 397, 89, 694, 452, 497, 101, 139]; - $sizes = $mail->getSize(); $this->assertEquals($shouldSizes, $sizes); } - public function testSingleSize() + public function testSingleSize(): void { $mail = new Storage\Imap($this->params); @@ -248,7 +245,7 @@ public function testSingleSize() $this->assertEquals(89, $size); } - public function testFetchHeader() + public function testFetchHeader(): void { $mail = new Storage\Imap($this->params); @@ -267,7 +264,7 @@ public function testFetchTopBody() $this->assertEquals('Fair river! in thy bright, clear flow', trim($content)); } */ - public function testFetchMessageHeader() + public function testFetchMessageHeader(): void { $mail = new Storage\Imap($this->params); @@ -275,7 +272,7 @@ public function testFetchMessageHeader() $this->assertEquals('Simple Message', $subject); } - public function testFetchMessageBody() + public function testFetchMessageBody(): void { $mail = new Storage\Imap($this->params); @@ -284,7 +281,7 @@ public function testFetchMessageBody() $this->assertEquals('Fair river! in thy bright, clear flow', trim($content)); } - public function testRemove() + public function testRemove(): void { $mail = new Storage\Imap($this->params); @@ -293,7 +290,7 @@ public function testRemove() $this->assertEquals($mail->countMessages(), $count - 1); } - public function testTooLateCount() + public function testTooLateCount(): void { $mail = new Storage\Imap($this->params); $mail->close(); @@ -303,14 +300,14 @@ public function testTooLateCount() $mail->countMessages(); } - public function testLoadUnkownFolder() + public function testLoadUnkownFolder(): void { $this->params['folder'] = 'UnknownFolder'; $this->expectException(Exception\InvalidArgumentException::class); new Storage\Imap($this->params); } - public function testChangeFolder() + public function testChangeFolder(): void { $mail = new Storage\Imap($this->params); $mail->selectFolder('subfolder/test'); @@ -318,33 +315,33 @@ public function testChangeFolder() $this->assertEquals($mail->getCurrentFolder(), 'subfolder/test'); } - public function testUnknownFolder() + public function testUnknownFolder(): void { $mail = new Storage\Imap($this->params); $this->expectException(Exception\InvalidArgumentException::class); $mail->selectFolder('/Unknown/Folder/'); } - public function testGlobalName() + public function testGlobalName(): void { $mail = new Storage\Imap($this->params); $this->assertEquals($mail->getFolders()->subfolder->__toString(), 'subfolder'); } - public function testLocalName() + public function testLocalName(): void { $mail = new Storage\Imap($this->params); $this->assertEquals($mail->getFolders()->subfolder->key(), 'test'); } - public function testKeyLocalName() + public function testKeyLocalName(): void { $mail = new Storage\Imap($this->params); $iterator = new \RecursiveIteratorIterator($mail->getFolders(), \RecursiveIteratorIterator::SELF_FIRST); // we search for this folder because we can't assume an order while iterating $search_folders = ['subfolder' => 'subfolder', 'subfolder/test' => 'test', - 'INBOX' => 'INBOX']; + 'INBOX' => 'INBOX', ]; $found_folders = []; foreach ($iterator as $localName => $folder) { @@ -359,7 +356,7 @@ public function testKeyLocalName() $this->assertEquals($search_folders, $found_folders); } - public function testSelectable() + public function testSelectable(): void { $mail = new Storage\Imap($this->params); $iterator = new \RecursiveIteratorIterator($mail->getFolders(), \RecursiveIteratorIterator::SELF_FIRST); @@ -369,8 +366,7 @@ public function testSelectable() } } - - public function testCountFolder() + public function testCountFolder(): void { $mail = new Storage\Imap($this->params); @@ -379,7 +375,7 @@ public function testCountFolder() $this->assertEquals(1, $count); } - public function testSizeFolder() + public function testSizeFolder(): void { $mail = new Storage\Imap($this->params); @@ -388,7 +384,7 @@ public function testSizeFolder() $this->assertEquals([1 => 410], $sizes); } - public function testFetchHeaderFolder() + public function testFetchHeaderFolder(): void { $mail = new Storage\Imap($this->params); @@ -397,14 +393,14 @@ public function testFetchHeaderFolder() $this->assertEquals('Message in subfolder', $subject); } - public function testHasFlag() + public function testHasFlag(): void { $mail = new Storage\Imap($this->params); $this->assertTrue($mail->getMessage(1)->hasFlag(Storage::FLAG_RECENT)); } - public function testGetFlags() + public function testGetFlags(): void { $mail = new Storage\Imap($this->params); @@ -413,14 +409,14 @@ public function testGetFlags() $this->assertContains(Storage::FLAG_RECENT, $flags); } - public function testRawHeader() + public function testRawHeader(): void { $mail = new Storage\Imap($this->params); $this->assertContains("\r\nSubject: Simple Message\r\n", $mail->getRawHeader(1)); } - public function testUniqueId() + public function testUniqueId(): void { $mail = new Storage\Imap($this->params); @@ -444,14 +440,14 @@ public function testUniqueId() } } - public function testWrongUniqueId() + public function testWrongUniqueId(): void { $mail = new Storage\Imap($this->params); $this->expectException(Exception\InvalidArgumentException::class); $mail->getNumberByUniqueId('this_is_an_invalid_id'); } - public function testCreateFolder() + public function testCreateFolder(): void { $mail = new Storage\Imap($this->params); $mail->createFolder('subfolder/test1'); @@ -463,7 +459,7 @@ public function testCreateFolder() $mail->getFolders()->subfolder->test3; } - public function testCreateExistingFolder() + public function testCreateExistingFolder(): void { $mail = new Storage\Imap($this->params); @@ -471,7 +467,7 @@ public function testCreateExistingFolder() $mail->createFolder('subfolder/test'); } - public function testRemoveFolderName() + public function testRemoveFolderName(): void { $mail = new Storage\Imap($this->params); $mail->removeFolder('subfolder/test'); @@ -480,7 +476,7 @@ public function testRemoveFolderName() $mail->getFolders()->subfolder->test; } - public function testRemoveFolderInstance() + public function testRemoveFolderInstance(): void { $mail = new Storage\Imap($this->params); $mail->removeFolder($mail->getFolders()->subfolder->test); @@ -489,7 +485,7 @@ public function testRemoveFolderInstance() $mail->getFolders()->subfolder->test; } - public function testRemoveInvalidFolder() + public function testRemoveInvalidFolder(): void { $mail = new Storage\Imap($this->params); @@ -497,7 +493,7 @@ public function testRemoveInvalidFolder() $mail->removeFolder('thisFolderDoestNotExist'); } - public function testRenameFolder() + public function testRenameFolder(): void { $mail = new Storage\Imap($this->params); @@ -508,7 +504,7 @@ public function testRenameFolder() $mail->renameFolder('subfolder/test', 'INBOX'); } - public function testAppend() + public function testAppend(): void { $mail = new Storage\Imap($this->params); $count = $mail->countMessages(); @@ -528,7 +524,7 @@ public function testAppend() $mail->appendMessage(''); } - public function testCopy() + public function testCopy(): void { $mail = new Storage\Imap($this->params); @@ -548,7 +544,7 @@ public function testCopy() $mail->copyMessage(1, 'justARandomFolder'); } - public function testSetFlags() + public function testSetFlags(): void { $mail = new Storage\Imap($this->params); @@ -580,7 +576,7 @@ public function testSetFlags() /** * @group 7353 */ - public function testCanMarkMessageUnseen() + public function testCanMarkMessageUnseen(): void { $mail = new Storage\Imap($this->params); $mail->setFlags(1, [Storage::FLAG_UNSEEN]); @@ -588,7 +584,7 @@ public function testCanMarkMessageUnseen() $this->assertTrue($message->hasFlag(Storage::FLAG_UNSEEN)); } - public function testCapability() + public function testCapability(): void { $protocol = new Protocol\Imap($this->params['host']); $protocol->login($this->params['user'], $this->params['password']); @@ -597,7 +593,7 @@ public function testCapability() $this->assertEquals($capa[0], 'CAPABILITY'); } - public function testSelect() + public function testSelect(): void { $protocol = new Protocol\Imap($this->params['host']); $protocol->login($this->params['user'], $this->params['password']); @@ -606,8 +602,7 @@ public function testSelect() $this->assertEquals($status['exists'], 7); } - - public function testExamine() + public function testExamine(): void { $protocol = new Protocol\Imap($this->params['host']); $protocol->login($this->params['user'], $this->params['password']); @@ -616,7 +611,7 @@ public function testExamine() $this->assertEquals($status['exists'], 7); } - public function testClosedSocketNewlineToken() + public function testClosedSocketNewlineToken(): void { $protocol = new Protocol\Imap($this->params['host']); $protocol->login($this->params['user'], $this->params['password']); @@ -626,7 +621,7 @@ public function testClosedSocketNewlineToken() $protocol->select("foo\nbar"); } - public function testEscaping() + public function testEscaping(): void { $protocol = new Protocol\Imap(); $this->assertEquals($protocol->escapeString('foo'), '"foo"'); @@ -639,7 +634,7 @@ public function testEscaping() $this->assertEquals($protocol->escapeList(['foo', 'bar']), '(foo bar)'); } - public function testFetch() + public function testFetch(): void { $protocol = new Protocol\Imap($this->params['host']); $protocol->login($this->params['user'], $this->params['password']); @@ -661,7 +656,7 @@ public function testFetch() $protocol->fetch('UID', 99); } - public function testFetchByUid() + public function testFetchByUid(): void { $protocol = new Protocol\Imap($this->params['host']); $protocol->login($this->params['user'], $this->params['password']); @@ -673,7 +668,7 @@ public function testFetchByUid() $this->assertEquals($uid, $message['UID']); } - public function testStore() + public function testStore(): void { $protocol = new Protocol\Imap($this->params['host']); $protocol->login($this->params['user'], $this->params['password']); @@ -691,7 +686,7 @@ public function testStore() $this->assertContains('\Flagged', $result[1]); } - public function testMove() + public function testMove(): void { $mail = new Storage\Imap($this->params); $mail->selectFolder('subfolder/test'); @@ -700,13 +695,12 @@ public function testMove() $fromCount = $mail->countMessages(); $mail->moveMessage(1, 'subfolder/test'); - $this->assertEquals($fromCount - 1, $mail->countMessages()); $mail->selectFolder('subfolder/test'); $this->assertEquals($toCount + 1, $mail->countMessages()); } - public function testCountFlags() + public function testCountFlags(): void { $mail = new Storage\Imap($this->params); foreach ($mail as $id => $message) { @@ -725,7 +719,7 @@ public function testCountFlags() $this->assertEquals($mail->countMessages(Storage::FLAG_FLAGGED), 0); } - public function testDelimiter() + public function testDelimiter(): void { $mail = new Storage\Imap($this->params); $delimiter = $mail->delimiter(); diff --git a/test/Storage/MaildirFolderTest.php b/test/Storage/MaildirFolderTest.php index af3c92d8..bbe7192a 100644 --- a/test/Storage/MaildirFolderTest.php +++ b/test/Storage/MaildirFolderTest.php @@ -23,7 +23,7 @@ class MaildirFolderTest extends TestCase protected $tmpdir; protected $subdirs = ['.', '.subfolder', '.subfolder.test']; - public function setUp() + public function setUp(): void { if (\strtoupper(\substr(PHP_OS, 0, 3)) == 'WIN') { $this->markTestSkipped('This test does not work on Windows'); @@ -95,7 +95,7 @@ public function setUp() } } - public function tearDown() + public function tearDown(): void { \chmod($this->tmpdir, 0700); foreach (array_reverse($this->subdirs) as $dir) { @@ -123,33 +123,33 @@ public function tearDown() } } - public function testLoadOk() + public function testLoadOk(): void { $mail = new Folder\Maildir($this->params); $this->assertSame(Folder\Maildir::class, \get_class($mail)); } - public function testLoadConfig() + public function testLoadConfig(): void { $mail = new Folder\Maildir(new Config\Config($this->params)); $this->assertSame(Folder\Maildir::class, \get_class($mail)); } - public function testNoParams() + public function testNoParams(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('no valid dirname given in params'); new Folder\Maildir([]); } - public function testLoadFailure() + public function testLoadFailure(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('no valid dirname given in params'); new Folder\Maildir(['dirname' => 'This/Folder/Does/Not/Exist']); } - public function testLoadUnkownFolder() + public function testLoadUnkownFolder(): void { $this->params['folder'] = 'UnknownFolder'; $this->expectException(Exception\InvalidArgumentException::class); @@ -157,7 +157,7 @@ public function testLoadUnkownFolder() new Folder\Maildir($this->params); } - public function testChangeFolder() + public function testChangeFolder(): void { $this->markTestIncomplete("Fail"); $mail = new Folder\Maildir($this->params); @@ -167,7 +167,7 @@ public function testChangeFolder() $this->assertEquals($mail->getCurrentFolder(), 'subfolder.test'); } - public function testUnknownFolder() + public function testUnknownFolder(): void { $mail = new Folder\Maildir($this->params); @@ -176,7 +176,7 @@ public function testUnknownFolder() $mail->selectFolder('/Unknown/Folder/'); } - public function testGlobalName() + public function testGlobalName(): void { $this->markTestIncomplete("Fail"); $mail = new Folder\Maildir($this->params); @@ -184,7 +184,7 @@ public function testGlobalName() $this->assertEquals($mail->getFolders()->subfolder->__toString(), 'subfolder'); } - public function testLocalName() + public function testLocalName(): void { $this->markTestIncomplete("Fail"); $mail = new Folder\Maildir($this->params); @@ -192,7 +192,7 @@ public function testLocalName() $this->assertEquals($mail->getFolders()->subfolder->key(), 'test'); } - public function testIterator() + public function testIterator(): void { $this->markTestIncomplete("Fail"); $mail = new Folder\Maildir($this->params); @@ -200,7 +200,7 @@ public function testIterator() // we search for this folder because we can't assume an order while iterating $search_folders = ['subfolder' => 'subfolder', 'subfolder.test' => 'test', - 'INBOX' => 'INBOX']; + 'INBOX' => 'INBOX', ]; $found_folders = []; foreach ($iterator as $localName => $folder) { @@ -215,7 +215,7 @@ public function testIterator() $this->assertEquals($search_folders, $found_folders); } - public function testKeyLocalName() + public function testKeyLocalName(): void { $this->markTestIncomplete("Fail"); $mail = new Folder\Maildir($this->params); @@ -223,7 +223,7 @@ public function testKeyLocalName() // we search for this folder because we can't assume an order while iterating $search_folders = ['subfolder' => 'subfolder', 'subfolder.test' => 'test', - 'INBOX' => 'INBOX']; + 'INBOX' => 'INBOX', ]; $found_folders = []; foreach ($iterator as $localName => $folder) { @@ -238,7 +238,7 @@ public function testKeyLocalName() $this->assertEquals($search_folders, $found_folders); } - public function testInboxEquals() + public function testInboxEquals(): void { $this->markTestIncomplete("Fail"); $mail = new Folder\Maildir($this->params); @@ -262,7 +262,7 @@ public function testInboxEquals() $this->assertEquals($search_folders, $found_folders); } - public function testSelectable() + public function testSelectable(): void { $mail = new Folder\Maildir($this->params); $iterator = new RecursiveIteratorIterator($mail->getFolders(), RecursiveIteratorIterator::SELF_FIRST); @@ -272,8 +272,7 @@ public function testSelectable() } } - - public function testCount() + public function testCount(): void { $this->markTestIncomplete("Fail"); $mail = new Folder\Maildir($this->params); @@ -286,7 +285,7 @@ public function testCount() $this->assertEquals(1, $count); } - public function testSize() + public function testSize(): void { $this->markTestIncomplete("Fail"); $mail = new Folder\Maildir($this->params); @@ -300,7 +299,7 @@ public function testSize() $this->assertEquals([1 => 467], $sizes); } - public function testFetchHeader() + public function testFetchHeader(): void { $this->markTestIncomplete("Fail"); $mail = new Folder\Maildir($this->params); @@ -313,7 +312,7 @@ public function testFetchHeader() $this->assertEquals('Message in subfolder', $subject); } - public function testNotReadableFolder() + public function testNotReadableFolder(): void { $this->markTestIncomplete("Fail"); $stat = stat($this->params['dirname'] . '.subfolder'); @@ -343,7 +342,7 @@ public function testNotReadableFolder() } } - public function testNotReadableMaildir() + public function testNotReadableMaildir(): void { chmod($this->params['dirname'], 0); @@ -352,7 +351,7 @@ public function testNotReadableMaildir() new Folder\Maildir($this->params); } - public function testGetInvalidFolder() + public function testGetInvalidFolder(): void { $mail = new Folder\Maildir($this->params); $root = $mail->getFolders(); @@ -363,7 +362,7 @@ public function testGetInvalidFolder() $mail->selectFolder('foobar'); } - public function testGetVanishedFolder() + public function testGetVanishedFolder(): void { $mail = new Folder\Maildir($this->params); $root = $mail->getFolders(); @@ -374,7 +373,7 @@ public function testGetVanishedFolder() $mail->selectFolder('foobar'); } - public function testGetNotSelectableFolder() + public function testGetNotSelectableFolder(): void { $mail = new Folder\Maildir($this->params); $root = $mail->getFolders(); @@ -385,7 +384,7 @@ public function testGetNotSelectableFolder() $mail->selectFolder('foobar'); } - public function testWithAdditionalFolder() + public function testWithAdditionalFolder(): void { mkdir($this->params['dirname'] . '.xyyx'); mkdir($this->params['dirname'] . '.xyyx/cur'); diff --git a/test/Storage/MaildirMessageOldTest.php b/test/Storage/MaildirMessageOldTest.php index a6781e85..02c5cf28 100644 --- a/test/Storage/MaildirMessageOldTest.php +++ b/test/Storage/MaildirMessageOldTest.php @@ -16,7 +16,7 @@ class MaildirMessageOldTest extends TestCase protected $maildir; protected $tmpdir; - public function setUp() + public function setUp(): void { if (\strtoupper(\substr(PHP_OS, 0, 3)) == 'WIN') { $this->markTestSkipped('This test does not work on Windows'); @@ -77,7 +77,7 @@ public function setUp() } } - public function tearDown() + public function tearDown(): void { foreach (['cur', 'new'] as $dir) { if (! is_dir($this->tmpdir . $dir)) { @@ -96,7 +96,7 @@ public function tearDown() } } - public function testFetchHeader() + public function testFetchHeader(): void { $mail = new TestAsset\MaildirOldMessage(['dirname' => $this->maildir]); @@ -113,7 +113,7 @@ public function testFetchTopBody() $this->assertEquals('Fair river! in thy bright, clear flow', trim($content)); } */ - public function testFetchMessageHeader() + public function testFetchMessageHeader(): void { $mail = new TestAsset\MaildirOldMessage(['dirname' => $this->maildir]); @@ -121,7 +121,7 @@ public function testFetchMessageHeader() $this->assertEquals('Simple Message', $subject); } - public function testFetchMessageBody() + public function testFetchMessageBody(): void { $mail = new TestAsset\MaildirOldMessage(['dirname' => $this->maildir]); @@ -130,7 +130,7 @@ public function testFetchMessageBody() $this->assertEquals('Fair river! in thy bright, clear flow', trim($content)); } - public function testHasFlag() + public function testHasFlag(): void { $mail = new TestAsset\MaildirOldMessage(['dirname' => $this->maildir]); @@ -140,7 +140,7 @@ public function testHasFlag() $this->assertFalse($mail->getMessage(2)->hasFlag(Storage::FLAG_ANSWERED)); } - public function testGetFlags() + public function testGetFlags(): void { $mail = new TestAsset\MaildirOldMessage(['dirname' => $this->maildir]); @@ -149,13 +149,13 @@ public function testGetFlags() $this->assertContains(Storage::FLAG_SEEN, $flags); } - public function testFetchPart() + public function testFetchPart(): void { $mail = new TestAsset\MaildirOldMessage(['dirname' => $this->maildir]); $this->assertEquals($mail->getMessage(4)->getPart(2)->contentType, 'text/x-vertical'); } - public function testPartSize() + public function testPartSize(): void { $mail = new TestAsset\MaildirOldMessage(['dirname' => $this->maildir]); $this->assertEquals($mail->getMessage(4)->getPart(2)->getSize(), 80); diff --git a/test/Storage/MaildirTest.php b/test/Storage/MaildirTest.php index f046f2fd..7a8aef0f 100644 --- a/test/Storage/MaildirTest.php +++ b/test/Storage/MaildirTest.php @@ -21,7 +21,7 @@ class MaildirTest extends TestCase protected $maildir; protected $tmpdir; - public function setUp() + public function setUp(): void { if (\strtoupper(\substr(PHP_OS, 0, 3)) == 'WIN') { $this->markTestSkipped('This test does not work on Windows'); @@ -82,7 +82,7 @@ public function setUp() } } - public function tearDown() + public function tearDown(): void { foreach (['cur', 'new'] as $dir) { if (! is_dir($this->tmpdir . $dir)) { @@ -111,67 +111,67 @@ public function tearDown() } } - public function testLoadOk() + public function testLoadOk(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); $this->assertSame(Storage\Maildir::class, \get_class($mail)); } - public function testLoadConfig() + public function testLoadConfig(): void { $mail = new Storage\Maildir(new Config\Config(['dirname' => $this->maildir])); $this->assertSame(Storage\Maildir::class, \get_class($mail)); } - public function testLoadFailure() + public function testLoadFailure(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('no valid dirname given in params'); new Storage\Maildir(['dirname' => '/This/Dir/Does/Not/Exist']); } - public function testLoadInvalid() + public function testLoadInvalid(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('invalid maildir given'); new Storage\Maildir(['dirname' => __DIR__]); } - public function testClose() + public function testClose(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); $this->assertNull($mail->close()); } - public function testHasFlags() + public function testHasFlags(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); $this->assertTrue($mail->hasFlags); } - public function testHasTop() + public function testHasTop(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); $this->assertTrue($mail->hasTop); } - public function testHasCreate() + public function testHasCreate(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); $this->assertFalse($mail->hasCreate); } - public function testNoop() + public function testNoop(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); $this->assertTrue($mail->noop()); } - public function testCount() + public function testCount(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); @@ -179,17 +179,16 @@ public function testCount() $this->assertEquals(5, $count); } - public function testSize() + public function testSize(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); $shouldSizes = [1 => 397, 89, 694, 452, 497]; - $sizes = $mail->getSize(); $this->assertEquals($shouldSizes, $sizes); } - public function testSingleSize() + public function testSingleSize(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); @@ -197,7 +196,7 @@ public function testSingleSize() $this->assertEquals(89, $size); } - public function testFetchHeader() + public function testFetchHeader(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); @@ -214,7 +213,7 @@ public function testFetchTopBody() $this->assertEquals('Fair river! in thy bright, clear flow', trim($content)); } */ - public function testFetchMessageHeader() + public function testFetchMessageHeader(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); @@ -222,7 +221,7 @@ public function testFetchMessageHeader() $this->assertEquals('Simple Message', $subject); } - public function testFetchMessageBody() + public function testFetchMessageBody(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); @@ -231,7 +230,7 @@ public function testFetchMessageBody() $this->assertEquals('Fair river! in thy bright, clear flow', trim($content)); } - public function testFetchWrongSize() + public function testFetchWrongSize(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); @@ -240,7 +239,7 @@ public function testFetchWrongSize() $mail->getSize(0); } - public function testFetchWrongMessageBody() + public function testFetchWrongMessageBody(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); @@ -249,7 +248,7 @@ public function testFetchWrongMessageBody() $mail->getMessage(0); } - public function testFailedRemove() + public function testFailedRemove(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); @@ -258,7 +257,7 @@ public function testFailedRemove() $mail->removeMessage(1); } - public function testHasFlag() + public function testHasFlag(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); @@ -268,7 +267,7 @@ public function testHasFlag() $this->assertFalse($mail->getMessage(2)->hasFlag(Storage::FLAG_ANSWERED)); } - public function testGetFlags() + public function testGetFlags(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); @@ -277,7 +276,7 @@ public function testGetFlags() $this->assertContains(Storage::FLAG_SEEN, $flags); } - public function testUniqueId() + public function testUniqueId(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); @@ -285,8 +284,12 @@ public function testUniqueId() $this->assertEquals(1, $mail->getNumberByUniqueId($mail->getUniqueId(1))); $ids = $mail->getUniqueId(); - $should_ids = [1 => '1000000000.P1.example.org', '1000000001.P1.example.org', '1000000002.P1.example.org', - '1000000003.P1.example.org', '1000000004.P1.example.org']; + $should_ids = [1 => '1000000000.P1.example.org', + '1000000001.P1.example.org', + '1000000002.P1.example.org', + '1000000003.P1.example.org', + '1000000004.P1.example.org', + ]; foreach ($ids as $num => $id) { $this->assertEquals($id, $should_ids[$num]); @@ -296,7 +299,7 @@ public function testUniqueId() } } - public function testWrongUniqueId() + public function testWrongUniqueId(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); @@ -305,7 +308,7 @@ public function testWrongUniqueId() $mail->getNumberByUniqueId('this_is_an_invalid_id'); } - public function testCurIsFile() + public function testCurIsFile(): void { \rename($this->maildir . 'cur', $this->maildir . 'cur-isFileTest'); \touch($this->maildir . 'cur'); @@ -315,7 +318,7 @@ public function testCurIsFile() new Storage\Maildir(['dirname' => $this->maildir]); } - public function testNewIsFile() + public function testNewIsFile(): void { \rename($this->maildir . 'new', $this->maildir . 'new-isFileTest'); \touch($this->maildir . 'new'); @@ -325,7 +328,7 @@ public function testNewIsFile() new Storage\Maildir(['dirname' => $this->maildir]); } - public function testTmpIsFile() + public function testTmpIsFile(): void { \touch($this->maildir . 'tmp'); @@ -334,7 +337,7 @@ public function testTmpIsFile() new Storage\Maildir(['dirname' => $this->maildir]); } - public function testNotReadableCur() + public function testNotReadableCur(): void { \chmod($this->maildir . 'cur', 0); @@ -343,7 +346,7 @@ public function testNotReadableCur() new Storage\Maildir(['dirname' => $this->maildir]); } - public function testNotReadableNew() + public function testNotReadableNew(): void { \chmod($this->maildir . 'new', 0); @@ -352,7 +355,7 @@ public function testNotReadableNew() new Storage\Maildir(['dirname' => $this->maildir]); } - public function testCountFlags() + public function testCountFlags(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); $this->assertEquals($mail->countMessages(Storage::FLAG_DELETED), 0); @@ -363,19 +366,19 @@ public function testCountFlags() $this->assertEquals($mail->countMessages([Storage::FLAG_SEEN, Storage::FLAG_RECENT]), 0); } - public function testFetchPart() + public function testFetchPart(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); $this->assertEquals($mail->getMessage(4)->getPart(2)->contentType, 'text/x-vertical'); } - public function testPartSize() + public function testPartSize(): void { $mail = new Storage\Maildir(['dirname' => $this->maildir]); $this->assertEquals($mail->getMessage(4)->getPart(2)->getSize(), 88); } - public function testSizePlusPlus() + public function testSizePlusPlus(): void { rename( $this->maildir . '/cur/1000000000.P1.example.org:2,S', @@ -388,12 +391,11 @@ public function testSizePlusPlus() $mail = new Storage\Maildir(['dirname' => $this->maildir]); $shouldSizes = [1 => 123, 456, 694, 452, 497]; - $sizes = $mail->getSize(); $this->assertEquals($shouldSizes, $sizes); } - public function testSingleSizePlusPlus() + public function testSingleSizePlusPlus(): void { rename( $this->maildir . '/cur/1000000001.P1.example.org:2,FS', diff --git a/test/Storage/MaildirWritableTest.php b/test/Storage/MaildirWritableTest.php index ac84b33c..ac78fea0 100644 --- a/test/Storage/MaildirWritableTest.php +++ b/test/Storage/MaildirWritableTest.php @@ -22,7 +22,7 @@ class MaildirWritableTest extends TestCase protected $tmpdir; protected $subdirs = ['.', '.subfolder', '.subfolder.test']; - public function setUp() + public function setUp(): void { if (\strtoupper(\substr(PHP_OS, 0, 3)) == 'WIN') { $this->markTestSkipped('This test does not work on Windows'); @@ -94,7 +94,7 @@ public function setUp() } } - public function tearDown() + public function tearDown(): void { foreach (array_reverse($this->subdirs) as $dir) { if (! file_exists($this->tmpdir . $dir)) { @@ -122,7 +122,7 @@ public function tearDown() @unlink($this->tmpdir . 'maildirsize'); } - public function testCreateFolder() + public function testCreateFolder(): void { $this->markTestIncomplete("Fail"); $mail = new Writable\Maildir($this->params); @@ -144,7 +144,7 @@ public function testCreateFolder() $this->subdirs[] = '.foo.bar'; } - public function testCreateFolderEmptyPart() + public function testCreateFolderEmptyPart(): void { $mail = new Writable\Maildir($this->params); $this->expectException(Exception\RuntimeException::class); @@ -152,7 +152,7 @@ public function testCreateFolderEmptyPart() $mail->createFolder('foo..bar'); } - public function testCreateFolderSlash() + public function testCreateFolderSlash(): void { $mail = new Writable\Maildir($this->params); $this->expectException(Exception\RuntimeException::class); @@ -160,7 +160,7 @@ public function testCreateFolderSlash() $mail->createFolder('foo/bar'); } - public function testCreateFolderDirectorySeparator() + public function testCreateFolderDirectorySeparator(): void { $mail = new Writable\Maildir($this->params); $this->expectException(Exception\RuntimeException::class); @@ -168,7 +168,7 @@ public function testCreateFolderDirectorySeparator() $mail->createFolder('foo' . DIRECTORY_SEPARATOR . 'bar'); } - public function testCreateFolderExistingDir() + public function testCreateFolderExistingDir(): void { $mail = new Writable\Maildir($this->params); unset($mail->getFolders()->subfolder->test); @@ -178,7 +178,7 @@ public function testCreateFolderExistingDir() $mail->createFolder('subfolder.test'); } - public function testCreateExistingFolder() + public function testCreateExistingFolder(): void { $mail = new Writable\Maildir($this->params); @@ -187,7 +187,7 @@ public function testCreateExistingFolder() $mail->createFolder('subfolder.test'); } - public function testRemoveFolderName() + public function testRemoveFolderName(): void { $mail = new Writable\Maildir($this->params); $mail->removeFolder('INBOX.subfolder.test'); @@ -197,7 +197,7 @@ public function testRemoveFolderName() $mail->selectFolder($mail->getFolders()->subfolder->test); } - public function testRemoveFolderInstance() + public function testRemoveFolderInstance(): void { $mail = new Writable\Maildir($this->params); $mail->removeFolder($mail->getFolders()->subfolder->test); @@ -207,7 +207,7 @@ public function testRemoveFolderInstance() $mail->selectFolder($mail->getFolders()->subfolder->test); } - public function testRemoveFolderWithChildren() + public function testRemoveFolderWithChildren(): void { $mail = new Writable\Maildir($this->params); @@ -216,7 +216,7 @@ public function testRemoveFolderWithChildren() $mail->removeFolder($mail->getFolders()->subfolder); } - public function testRemoveSelectedFolder() + public function testRemoveSelectedFolder(): void { $this->markTestIncomplete("Fail"); $mail = new Writable\Maildir($this->params); @@ -226,7 +226,7 @@ public function testRemoveSelectedFolder() $mail->removeFolder('subfolder.test'); } - public function testRemoveInvalidFolder() + public function testRemoveInvalidFolder(): void { $mail = new Writable\Maildir($this->params); @@ -235,7 +235,7 @@ public function testRemoveInvalidFolder() $mail->removeFolder('thisFolderDoestNotExist'); } - public function testRenameFolder() + public function testRenameFolder(): void { $mail = new Writable\Maildir($this->params); @@ -247,7 +247,7 @@ public function testRenameFolder() $mail->renameFolder('INBOX', 'foo'); } - public function testRenameSelectedFolder() + public function testRenameSelectedFolder(): void { $this->markTestIncomplete("Fail"); $mail = new Writable\Maildir($this->params); @@ -257,7 +257,7 @@ public function testRenameSelectedFolder() $mail->renameFolder('subfolder.test', 'foo'); } - public function testRenameToChild() + public function testRenameToChild(): void { $mail = new Writable\Maildir($this->params); @@ -266,7 +266,7 @@ public function testRenameToChild() $mail->renameFolder('subfolder.test', 'subfolder.test.foo'); } - public function testAppend() + public function testAppend(): void { $mail = new Writable\Maildir($this->params); $count = $mail->countMessages(); @@ -283,7 +283,7 @@ public function testAppend() $this->assertEquals($mail->getMessage($count + 1)->subject, 'append test'); } - public function testCopy() + public function testCopy(): void { $this->markTestIncomplete("Fail"); $mail = new Writable\Maildir($this->params); @@ -304,7 +304,7 @@ public function testCopy() $mail->copyMessage(1, 'justARandomFolder'); } - public function testSetFlags() + public function testSetFlags(): void { $mail = new Writable\Maildir($this->params); @@ -328,7 +328,7 @@ public function testSetFlags() $mail->setFlags(1, [Storage::FLAG_RECENT]); } - public function testSetFlagsRemovedFile() + public function testSetFlagsRemovedFile(): void { $this->markTestIncomplete("Fail"); $mail = new Writable\Maildir($this->params); @@ -337,7 +337,7 @@ public function testSetFlagsRemovedFile() $this->expectException(Exception\InvalidArgumentException::class); } - public function testRemove() + public function testRemove(): void { $mail = new Writable\Maildir($this->params); $count = $mail->countMessages(); @@ -349,7 +349,7 @@ public function testRemove() $this->assertEquals($mail->countMessages(), --$count); } - public function testRemoveRemovedFile() + public function testRemoveRemovedFile(): void { $mail = new Writable\Maildir($this->params); unlink($this->params['dirname'] . 'cur/1000000000.P1.example.org:2,S'); @@ -359,13 +359,13 @@ public function testRemoveRemovedFile() $mail->removeMessage(1); } - public function testCheckQuota() + public function testCheckQuota(): void { $mail = new Writable\Maildir($this->params); $this->assertFalse($mail->checkQuota()); } - public function testCheckQuotaDetailed() + public function testCheckQuotaDetailed(): void { $this->markTestIncomplete("Fail"); $mail = new Writable\Maildir($this->params); @@ -375,14 +375,14 @@ public function testCheckQuotaDetailed() 'quota' => [ 'count' => 10, 'L' => 1, - 'size' => 3000 + 'size' => 3000, ], - 'over_quota' => false + 'over_quota' => false, ]; $this->assertEquals($quotaResult, $mail->checkQuota(true)); } - public function testSetQuota() + public function testSetQuota(): void { $this->markTestIncomplete("Fail"); $mail = new Writable\Maildir($this->params); @@ -404,15 +404,15 @@ public function testSetQuota() 'quota' => [ 'size' => 100, 'count' => 2, - 'X' => 0 + 'X' => 0, ], - 'over_quota' => true + 'over_quota' => true, ]; $this->assertEquals($quotaResult, $mail->checkQuota(true, true)); $this->assertEquals(['size' => 100, 'count' => 2, 'X' => 0], $mail->getQuota(true)); } - public function testMissingMaildirsize() + public function testMissingMaildirsize(): void { $mail = new Writable\Maildir($this->params); $this->assertEquals($mail->getQuota(true), ['size' => 3000, 'L' => 1, 'count' => 10]); @@ -426,7 +426,7 @@ public function testMissingMaildirsize() $mail->getQuota(true); } - public function testMissingMaildirsizeWithFixedQuota() + public function testMissingMaildirsizeWithFixedQuota(): void { $this->markTestIncomplete("Fail"); $mail = new Writable\Maildir($this->params); @@ -439,16 +439,16 @@ public function testMissingMaildirsizeWithFixedQuota() 'quota' => [ 'size' => 100, 'count' => 2, - 'X' => 0 + 'X' => 0, ], - 'over_quota' => true + 'over_quota' => true, ]; $this->assertEquals($mail->checkQuota(true), $quotaResult); $this->assertEquals($mail->getQuota(true), $quotaResult['quota']); } - public function testAppendMessage() + public function testAppendMessage(): void { $this->markTestIncomplete("Fail"); $mail = new Writable\Maildir($this->params); @@ -461,9 +461,9 @@ public function testAppendMessage() 'quota' => [ 'size' => 3000, 'count' => 6, - 'X' => 0 + 'X' => 0, ], - 'over_quota' => true + 'over_quota' => true, ]; $this->assertEquals($mail->checkQuota(true), $quotaResult); @@ -479,7 +479,7 @@ public function testAppendMessage() $mail->appendMessage("Subject: test\r\n\r\n"); } - public function testRemoveMessage() + public function testRemoveMessage(): void { $this->markTestIncomplete("Fail"); $mail = new Writable\Maildir($this->params); @@ -490,7 +490,7 @@ public function testRemoveMessage() $this->assertFalse($mail->checkQuota()); } - public function testCopyMessage() + public function testCopyMessage(): void { $this->markTestIncomplete("Fail"); $mail = new Writable\Maildir($this->params); @@ -503,18 +503,18 @@ public function testCopyMessage() 'quota' => [ 'size' => 3000, 'count' => 6, - 'X' => 0 + 'X' => 0, ], - 'over_quota' => true + 'over_quota' => true, ]; $this->assertEquals($mail->checkQuota(true), $quotaResult); } - public function testAppendStream() + public function testAppendStream(): void { $mail = new Writable\Maildir($this->params); $fh = fopen('php://memory', 'rw'); - fputs($fh, "Subject: test\r\n\r\n"); + fwrite($fh, "Subject: test\r\n\r\n"); fseek($fh, 0); $mail->appendMessage($fh); fclose($fh); @@ -522,7 +522,7 @@ public function testAppendStream() $this->assertEquals($mail->getMessage($mail->countMessages())->subject, 'test'); } - public function testMove() + public function testMove(): void { $this->markTestIncomplete("Fail"); $mail = new Writable\Maildir($this->params); @@ -533,13 +533,12 @@ public function testMove() $fromCount = $mail->countMessages(); $mail->moveMessage(1, $target); - $this->assertEquals($fromCount - 1, $mail->countMessages()); $mail->selectFolder($target); $this->assertEquals($toCount + 1, $mail->countMessages()); } - public function testInitExisting() + public function testInitExisting(): void { // this should be a noop Writable\Maildir::initMaildir($this->params['dirname']); @@ -547,7 +546,7 @@ public function testInitExisting() $this->assertEquals($mail->countMessages(), 5); } - public function testInit() + public function testInit(): void { $this->tearDown(); @@ -564,7 +563,7 @@ public function testInit() $this->assertEquals($mail->countMessages(), 0); } - public function testCreate() + public function testCreate(): void { $this->tearDown(); diff --git a/test/Storage/MboxFolderTest.php b/test/Storage/MboxFolderTest.php index 75d61946..223a664e 100644 --- a/test/Storage/MboxFolderTest.php +++ b/test/Storage/MboxFolderTest.php @@ -24,7 +24,7 @@ class MboxFolderTest extends TestCase protected $tmpdir; protected $subdirs = ['.', 'subfolder']; - public function setUp() + public function setUp(): void { $this->originalDir = __DIR__ . '/../_files/test.mbox/'; @@ -69,7 +69,7 @@ public function setUp() } } - public function tearDown() + public function tearDown(): void { foreach (array_reverse($this->subdirs) as $dir) { $dh = opendir($this->tmpdir . $dir); @@ -87,38 +87,38 @@ public function tearDown() } } - public function testLoadOk() + public function testLoadOk(): void { new Folder\Mbox($this->params); $this->addToAssertionCount(1); } - public function testLoadConfig() + public function testLoadConfig(): void { new Folder\Mbox(new Config\Config($this->params)); $this->addToAssertionCount(1); } - public function testNoParams() + public function testNoParams(): void { $this->expectException(Exception\InvalidArgumentException::class); new Folder\Mbox([]); } - public function testFilenameParam() + public function testFilenameParam(): void { $this->expectException(Exception\InvalidArgumentException::class); // filename is not allowed in this subclass new Folder\Mbox(['filename' => 'foobar']); } - public function testLoadFailure() + public function testLoadFailure(): void { $this->expectException(Exception\InvalidArgumentException::class); new Folder\Mbox(['dirname' => 'This/Folder/Does/Not/Exist']); } - public function testLoadUnkownFolder() + public function testLoadUnknownFolder(): void { $this->params['folder'] = 'UnknownFolder'; @@ -126,7 +126,7 @@ public function testLoadUnkownFolder() new Folder\Mbox($this->params); } - public function testChangeFolder() + public function testChangeFolder(): void { $mail = new Folder\Mbox($this->params); @@ -138,35 +138,35 @@ public function testChangeFolder() ); } - public function testChangeFolderUnselectable() + public function testChangeFolderUnselectable(): void { $mail = new Folder\Mbox($this->params); $this->expectException(Exception\RuntimeException::class); $mail->selectFolder(DIRECTORY_SEPARATOR . 'subfolder'); } - public function testUnknownFolder() + public function testUnknownFolder(): void { $mail = new Folder\Mbox($this->params); $this->expectException(Exception\InvalidArgumentException::class); $mail->selectFolder('/Unknown/Folder/'); } - public function testGlobalName() + public function testGlobalName(): void { $mail = new Folder\Mbox($this->params); $this->assertEquals($mail->getFolders()->subfolder->__toString(), DIRECTORY_SEPARATOR . 'subfolder'); } - public function testLocalName() + public function testLocalName(): void { $mail = new Folder\Mbox($this->params); $this->assertEquals($mail->getFolders()->subfolder->key(), 'test'); } - public function testIterator() + public function testIterator(): void { $mail = new Folder\Mbox($this->params); $iterator = new RecursiveIteratorIterator($mail->getFolders(), RecursiveIteratorIterator::SELF_FIRST); @@ -175,7 +175,7 @@ public function testIterator() $search_folders = [ DIRECTORY_SEPARATOR . 'subfolder' => 'subfolder', DIRECTORY_SEPARATOR . 'subfolder' . DIRECTORY_SEPARATOR . 'test' => 'test', - DIRECTORY_SEPARATOR . 'INBOX' => 'INBOX' + DIRECTORY_SEPARATOR . 'INBOX' => 'INBOX', ]; $found_folders = []; @@ -191,7 +191,7 @@ public function testIterator() $this->assertEquals($search_folders, $found_folders); } - public function testKeyLocalName() + public function testKeyLocalName(): void { $mail = new Folder\Mbox($this->params); $iterator = new RecursiveIteratorIterator($mail->getFolders(), RecursiveIteratorIterator::SELF_FIRST); @@ -199,7 +199,7 @@ public function testKeyLocalName() $search_folders = [ DIRECTORY_SEPARATOR . 'subfolder' => 'subfolder', DIRECTORY_SEPARATOR . 'subfolder' . DIRECTORY_SEPARATOR . 'test' => 'test', - DIRECTORY_SEPARATOR . 'INBOX' => 'INBOX' + DIRECTORY_SEPARATOR . 'INBOX' => 'INBOX', ]; $found_folders = []; @@ -215,7 +215,7 @@ public function testKeyLocalName() $this->assertEquals($search_folders, $found_folders); } - public function testSelectable() + public function testSelectable(): void { $mail = new Folder\Mbox($this->params); $iterator = new RecursiveIteratorIterator($mail->getFolders(), RecursiveIteratorIterator::SELF_FIRST); @@ -225,8 +225,7 @@ public function testSelectable() } } - - public function testCount() + public function testCount(): void { $mail = new Folder\Mbox($this->params); @@ -238,7 +237,7 @@ public function testCount() $this->assertEquals(1, $count); } - public function testSize() + public function testSize(): void { $mail = new Folder\Mbox($this->params); $shouldSizes = [1 => 397, 89, 694, 452, 497, 101, 139]; @@ -251,7 +250,7 @@ public function testSize() $this->assertEquals([1 => 410], $sizes); } - public function testFetchHeader() + public function testFetchHeader(): void { $mail = new Folder\Mbox($this->params); @@ -263,7 +262,7 @@ public function testFetchHeader() $this->assertEquals('Message in subfolder', $subject); } - public function testSleepWake() + public function testSleepWake(): void { $mail = new Folder\Mbox($this->params); @@ -272,7 +271,6 @@ public function testSleepWake() $content = $mail->getMessage(1)->getContent(); $serialzed = serialize($mail); - $mail = null; $mail = unserialize($serialzed); $this->assertEquals($mail->countMessages(), $count); @@ -283,7 +281,7 @@ public function testSleepWake() $this->assertEquals($mail->getMessage(1)->getContent(), $content); } - public function testNotMboxFile() + public function testNotMboxFile(): void { touch($this->params['dirname'] . 'foobar'); $mail = new Folder\Mbox($this->params); @@ -292,7 +290,7 @@ public function testNotMboxFile() $mail->getFolders()->foobar; } - public function testNotReadableFolder() + public function testNotReadableFolder(): void { $stat = stat($this->params['dirname'] . 'subfolder'); chmod($this->params['dirname'] . 'subfolder', 0); @@ -326,7 +324,7 @@ public function testNotReadableFolder() } } - public function testGetInvalidFolder() + public function testGetInvalidFolder(): void { $mail = new Folder\Mbox($this->params); $root = $mail->getFolders(); @@ -335,7 +333,7 @@ public function testGetInvalidFolder() $mail->getFolders('foobar'); } - public function testGetVanishedFolder() + public function testGetVanishedFolder(): void { $mail = new Folder\Mbox($this->params); $root = $mail->getFolders(); diff --git a/test/Storage/MboxInterfaceTest.php b/test/Storage/MboxInterfaceTest.php index 0f53b0ef..041cc2c3 100644 --- a/test/Storage/MboxInterfaceTest.php +++ b/test/Storage/MboxInterfaceTest.php @@ -21,12 +21,12 @@ class MboxInterfaceTest extends TestCase { protected $mboxFile; - public function setUp() + public function setUp(): void { $this->mboxFile = __DIR__ . '/../_files/test.mbox/INBOX'; } - public function testCount() + public function testCount(): void { $list = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -34,21 +34,21 @@ public function testCount() $this->assertEquals(7, $count); } - public function testIsset() + public function testIsset(): void { $list = new Storage\Mbox(['filename' => $this->mboxFile]); $this->assertTrue(isset($list[1])); } - public function testNotIsset() + public function testNotIsset(): void { $list = new Storage\Mbox(['filename' => $this->mboxFile]); $this->assertFalse(isset($list[10])); } - public function testArrayGet() + public function testArrayGet(): void { $list = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -56,7 +56,7 @@ public function testArrayGet() $this->assertEquals('Simple Message', $subject); } - public function testArraySetFail() + public function testArraySetFail(): void { $list = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -64,7 +64,7 @@ public function testArraySetFail() $list[1] = 'test'; } - public function testIterationKey() + public function testIterationKey(): void { $list = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -75,7 +75,7 @@ public function testIterationKey() } } - public function testIterationIsMessage() + public function testIterationIsMessage(): void { $list = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -88,7 +88,7 @@ public function testIterationIsMessage() } } - public function testIterationRounds() + public function testIterationRounds(): void { $list = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -100,7 +100,7 @@ public function testIterationRounds() $this->assertEquals(7, $count); } - public function testIterationWithSeek() + public function testIterationWithSeek(): void { $list = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -112,7 +112,7 @@ public function testIterationWithSeek() $this->assertEquals(3, $count); } - public function testIterationWithSeekCapped() + public function testIterationWithSeekCapped(): void { $list = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -124,7 +124,7 @@ public function testIterationWithSeekCapped() $this->assertEquals(5, $count); } - public function testFallback() + public function testFallback(): void { $list = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -132,7 +132,7 @@ public function testFallback() $this->assertTrue($result); } - public function testWrongVariable() + public function testWrongVariable(): void { $list = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -140,14 +140,14 @@ public function testWrongVariable() $list->thisdoesnotexist; } - public function testGetHeaders() + public function testGetHeaders(): void { $list = new Storage\Mbox(['filename' => $this->mboxFile]); $headers = $list[1]->getHeaders(); $this->assertNotEmpty($headers); } - public function testWrongHeader() + public function testWrongHeader(): void { $list = new Storage\Mbox(['filename' => $this->mboxFile]); diff --git a/test/Storage/MboxMessageOldTest.php b/test/Storage/MboxMessageOldTest.php index 6b0a95dd..1cd6355c 100644 --- a/test/Storage/MboxMessageOldTest.php +++ b/test/Storage/MboxMessageOldTest.php @@ -16,7 +16,7 @@ class MboxMessageOldTest extends TestCase protected $mboxFile; protected $tmpdir; - public function setUp() + public function setUp(): void { if ($this->tmpdir == null) { if (getenv('TESTS_LAMINAS_MAIL_TEMPDIR') != null) { @@ -45,12 +45,12 @@ public function setUp() copy($this->mboxOriginalFile, $this->mboxFile); } - public function tearDown() + public function tearDown(): void { unlink($this->mboxFile); } - public function testFetchHeader() + public function testFetchHeader(): void { $mail = new TestAsset\MboxOldMessage(['filename' => $this->mboxFile]); @@ -68,7 +68,7 @@ public function testFetchTopBody() } */ - public function testFetchMessageHeader() + public function testFetchMessageHeader(): void { $mail = new TestAsset\MboxOldMessage(['filename' => $this->mboxFile]); @@ -76,7 +76,7 @@ public function testFetchMessageHeader() $this->assertEquals('Simple Message', $subject); } - public function testFetchMessageBody() + public function testFetchMessageBody(): void { $mail = new TestAsset\MboxOldMessage(['filename' => $this->mboxFile]); @@ -85,11 +85,10 @@ public function testFetchMessageBody() $this->assertEquals('Fair river! in thy bright, clear flow', trim($content)); } - - public function testShortMbox() + public function testShortMbox(): void { $fh = fopen($this->mboxFile, 'w'); - fputs($fh, "From \r\nSubject: test\r\nFrom \r\nSubject: test2\r\n"); + fwrite($fh, "From \r\nSubject: test\r\nFrom \r\nSubject: test2\r\n"); fclose($fh); $mail = new TestAsset\MboxOldMessage(['filename' => $this->mboxFile]); $this->assertEquals($mail->countMessages(), 2); diff --git a/test/Storage/MboxTest.php b/test/Storage/MboxTest.php index df37e3a0..d5eaf5be 100644 --- a/test/Storage/MboxTest.php +++ b/test/Storage/MboxTest.php @@ -23,7 +23,7 @@ class MboxTest extends TestCase protected $mboxFileUnix; protected $tmpdir; - public function setUp() + public function setUp(): void { if ($this->tmpdir == null) { if (getenv('TESTS_LAMINAS_MAIL_TEMPDIR') != null) { @@ -52,7 +52,7 @@ public function setUp() copy($this->mboxOriginalFile, $this->mboxFile); } - public function tearDown() + public function tearDown(): void { unlink($this->mboxFile); @@ -61,37 +61,37 @@ public function tearDown() } } - public function testLoadOk() + public function testLoadOk(): void { new Storage\Mbox(['filename' => $this->mboxFile]); $this->addToAssertionCount(1); } - public function testLoadConfig() + public function testLoadConfig(): void { new Storage\Mbox(new Config\Config(['filename' => $this->mboxFile])); $this->addToAssertionCount(1); } - public function testNoParams() + public function testNoParams(): void { $this->expectException(Exception\InvalidArgumentException::class); new Storage\Mbox([]); } - public function testLoadFailure() + public function testLoadFailure(): void { $this->expectException(Exception\RuntimeException::class); new Storage\Mbox(['filename' => 'ThisFileDoesNotExist']); } - public function testLoadInvalid() + public function testLoadInvalid(): void { $this->expectException(Exception\InvalidArgumentException::class); new Storage\Mbox(['filename' => __FILE__]); } - public function testClose() + public function testClose(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -99,28 +99,28 @@ public function testClose() $this->addToAssertionCount(1); } - public function testHasTop() + public function testHasTop(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); $this->assertTrue($mail->hasTop); } - public function testHasCreate() + public function testHasCreate(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); $this->assertFalse($mail->hasCreate); } - public function testNoop() + public function testNoop(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); $this->assertTrue($mail->noop()); } - public function testCount() + public function testCount(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -128,17 +128,16 @@ public function testCount() $this->assertEquals(7, $count); } - public function testSize() + public function testSize(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); $shouldSizes = [1 => 397, 89, 694, 452, 497, 101, 139]; - $sizes = $mail->getSize(); $this->assertEquals($shouldSizes, $sizes); } - public function testSingleSize() + public function testSingleSize(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -146,7 +145,7 @@ public function testSingleSize() $this->assertEquals(89, $size); } - public function testFetchHeader() + public function testFetchHeader(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -167,7 +166,7 @@ public function testFetchTopBody() /** * @group 6775 */ - public function testFetchMessageHeaderUnix() + public function testFetchMessageHeaderUnix(): void { $mail = new Storage\Mbox(['filename' => $this->getUnixMboxFile(), 'messageEOL' => "\n"]); @@ -175,7 +174,7 @@ public function testFetchMessageHeaderUnix() $this->assertEquals('Simple Message', $subject); } - public function testFetchMessageHeader() + public function testFetchMessageHeader(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -183,7 +182,7 @@ public function testFetchMessageHeader() $this->assertEquals('Simple Message', $subject); } - public function testFetchMessageBody() + public function testFetchMessageBody(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -195,7 +194,7 @@ public function testFetchMessageBody() /** * @group 6775 */ - public function testFetchMessageBodyUnix() + public function testFetchMessageBodyUnix(): void { $mail = new Storage\Mbox(['filename' => $this->getUnixMboxFile(), 'messageEOL' => "\n"]); @@ -204,7 +203,7 @@ public function testFetchMessageBodyUnix() $this->assertEquals('Fair river! in thy bright, clear flow', trim($content)); } - public function testFailedRemove() + public function testFailedRemove(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -212,14 +211,14 @@ public function testFailedRemove() $mail->removeMessage(1); } - public function testCapa() + public function testCapabilities(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); $capa = $mail->getCapabilities(); $this->assertTrue(isset($capa['uniqueid'])); } - public function testValid() + public function testValid(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -228,8 +227,7 @@ public function testValid() $this->assertTrue($mail->valid()); } - - public function testOutOfBounds() + public function testOutOfBounds(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -237,7 +235,7 @@ public function testOutOfBounds() $mail->seek(INF); } - public function testSleepWake() + public function testSleepWake(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -256,7 +254,7 @@ public function testSleepWake() $this->assertEquals($mail->getMessage(1)->getContent(), $content); } - public function testSleepWakeRemoved() + public function testSleepWakeRemoved(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -278,8 +276,6 @@ public function testSleepWakeRemoved() return; } - - $check = false; try { $mail = unserialize($serialzed); @@ -300,7 +296,7 @@ public function testSleepWakeRemoved() } } - public function testUniqueId() + public function testUniqueId(): void { $mail = new Storage\Mbox(['filename' => $this->mboxFile]); @@ -317,10 +313,10 @@ public function testUniqueId() } } - public function testShortMbox() + public function testShortMbox(): void { $fh = fopen($this->mboxFile, 'w'); - fputs($fh, "From \r\nSubject: test\r\nFrom \r\nSubject: test2\r\n"); + fwrite($fh, "From \r\nSubject: test\r\nFrom \r\nSubject: test2\r\n"); fclose($fh); $mail = new Storage\Mbox(['filename' => $this->mboxFile]); $this->assertEquals($mail->countMessages(), 2); @@ -333,7 +329,7 @@ public function testShortMbox() /** * @return string */ - private function getUnixMboxFile() + private function getUnixMboxFile(): string { $this->mboxFileUnix = $this->tmpdir . 'INBOX.unix'; diff --git a/test/Storage/MessageTest.php b/test/Storage/MessageTest.php index 03bf75f2..73aa3be5 100644 --- a/test/Storage/MessageTest.php +++ b/test/Storage/MessageTest.php @@ -28,13 +28,13 @@ class MessageTest extends TestCase protected $file; protected $file2; - public function setUp() + public function setUp(): void { $this->file = __DIR__ . '/../_files/mail.txt'; $this->file2 = __DIR__ . '/../_files/mail_multi_to.txt'; } - public function testInvalidFile() + public function testInvalidFile(): void { $this->expectException(GeneralException::class); new Message(['file' => '/this/file/does/not/exists']); @@ -43,7 +43,7 @@ public function testInvalidFile() /** * @dataProvider filesProvider */ - public function testIsMultipart($params) + public function testIsMultipart($params): void { $message = new Message($params); $this->assertTrue($message->isMultipart()); @@ -52,7 +52,7 @@ public function testIsMultipart($params) /** * @dataProvider filesProvider */ - public function testGetHeader($params) + public function testGetHeader($params): void { $message = new Message($params); $this->assertEquals($message->subject, 'multipart'); @@ -61,7 +61,7 @@ public function testGetHeader($params) /** * @dataProvider filesProvider */ - public function testGetDecodedHeader($params) + public function testGetDecodedHeader($params): void { $message = new Message($params); $this->assertEquals('Peter Müller ', $message->from); @@ -70,20 +70,20 @@ public function testGetDecodedHeader($params) /** * @dataProvider filesProvider */ - public function testGetHeaderAsArray($params) + public function testGetHeaderAsArray($params): void { $message = new Message($params); $this->assertEquals(['multipart'], $message->getHeader('subject', 'array'), 'getHeader() value not match'); } - public function testGetFirstPart() + public function testGetFirstPart(): void { $message = new Message(['file' => $this->file]); $this->assertEquals(substr($message->getPart(1)->getContent(), 0, 14), 'The first part'); } - public function testGetFirstPartTwice() + public function testGetFirstPartTwice(): void { $message = new Message(['file' => $this->file]); @@ -91,15 +91,14 @@ public function testGetFirstPartTwice() $this->assertEquals(substr($message->getPart(1)->getContent(), 0, 14), 'The first part'); } - - public function testGetWrongPart() + public function testGetWrongPart(): void { $this->expectException(GeneralException::class); $message = new Message(['file' => $this->file]); $message->getPart(-1); } - public function testNoHeaderMessage() + public function testNoHeaderMessage(): void { $message = new Message(['file' => __FILE__]); @@ -118,14 +117,14 @@ public function testNoHeaderMessage() * @see https://github.com/zendframework/zend-mail/pull/86 * @see https://github.com/zendframework/zend-mail/pull/156 */ - public function testMessageIdHeader() + public function testMessageIdHeader(): void { $message = new Message(['file' => $this->file]); $messageId = $message->messageId; $this->assertEquals('', $messageId); } - public function testMultipleHeader() + public function testMultipleHeader(): void { $raw = file_get_contents($this->file); $raw = "sUBject: test\r\nSubJect: test2\r\n" . $raw; @@ -142,7 +141,7 @@ public function testMultipleHeader() ); } - public function testAllowWhitespaceInEmptySingleLineHeader() + public function testAllowWhitespaceInEmptySingleLineHeader(): void { $src = "From: user@example.com\n" . "To: userpal@example.net\n" @@ -157,7 +156,7 @@ public function testAllowWhitespaceInEmptySingleLineHeader() ); } - public function testNotAllowWhitespaceInEmptyMultiLineHeader() + public function testNotAllowWhitespaceInEmptyMultiLineHeader(): void { $src = "From: user@example.com\nTo: userpal@example.net\n" . "Subject: This is your reminder\n \n \n" @@ -169,7 +168,7 @@ public function testNotAllowWhitespaceInEmptyMultiLineHeader() $message = new Message(['raw' => $src]); } - public function testContentTypeDecode() + public function testContentTypeDecode(): void { $message = new Message(['file' => $this->file]); @@ -179,31 +178,31 @@ public function testContentTypeDecode() ); } - public function testSplitEmptyMessage() + public function testSplitEmptyMessage(): void { $this->assertEquals(Mime\Decode::splitMessageStruct('', 'xxx'), null); } - public function testSplitInvalidMessage() + public function testSplitInvalidMessage(): void { $this->expectException(MimeException\ExceptionInterface::class); Mime\Decode::splitMessageStruct("--xxx\n", 'xxx'); } - public function testInvalidMailHandler() + public function testInvalidMailHandler(): void { $this->expectException(Exception\InvalidArgumentException::class); new Message(['handler' => 1]); } - public function testMissingId() + public function testMissingId(): void { $this->expectException(Exception\InvalidArgumentException::class); $mail = new Storage\Mbox(['filename' => __DIR__ . '/../_files/test.mbox/INBOX']); new Message(['handler' => $mail]); } - public function testIterator() + public function testIterator(): void { $message = new Message(['file' => $this->file]); foreach (new \RecursiveIteratorIterator($message) as $num => $part) { @@ -215,13 +214,13 @@ public function testIterator() $this->assertEquals($part->contentType, 'text/x-vertical'); } - public function testDecodeString() + public function testDecodeString(): void { $is = Mime\Decode::decodeQuotedPrintable('=?UTF-8?Q?"Peter M=C3=BCller"?= '); $this->assertEquals('"Peter Müller" ', $is); } - public function testSplitHeader() + public function testSplitHeader(): void { $header = 'foo; x=y; y="x"'; $this->assertEquals(Mime\Decode::splitHeaderField($header), ['foo', 'x' => 'y', 'y' => 'x']); @@ -231,14 +230,14 @@ public function testSplitHeader() $this->assertEquals(Mime\Decode::splitHeaderField($header, 'foo'), null); } - public function testSplitInvalidHeader() + public function testSplitInvalidHeader(): void { $this->expectException(MimeException\ExceptionInterface::class); $header = ''; Mime\Decode::splitHeaderField($header); } - public function testSplitMessage() + public function testSplitMessage(): void { $header = 'Test: test'; $body = 'body'; @@ -257,20 +256,20 @@ public function testSplitMessage() } } - public function testToplines() + public function testTopLines(): void { $message = new Message(['headers' => file_get_contents($this->file)]); $this->assertStringStartsWith('multipart message', $message->getToplines()); } - public function testNoContent() + public function testNoContent(): void { $this->expectException(Exception\RuntimeException::class); $message = new Message(['raw' => 'Subject: test']); $message->getContent(); } - public function testEmptyHeader() + public function testEmptyHeader(): void { $message = new Message([]); $this->assertEquals([], $message->getHeaders()->toArray()); @@ -282,7 +281,7 @@ public function testEmptyHeader() $message->subject; } - public function testWrongHeaderType() + public function testWrongHeaderType(): void { // @codingStandardsIgnoreStart $badMessage = unserialize( @@ -294,7 +293,7 @@ public function testWrongHeaderType() $badMessage->getHeaders(); } - public function testEmptyBody() + public function testEmptyBody(): void { $message = new Message([]); $part = null; @@ -314,7 +313,7 @@ public function testEmptyBody() /** * @group Laminas-5209 */ - public function testCheckingHasHeaderFunctionality() + public function testCheckingHasHeaderFunctionality(): void { $message = new Message(['headers' => ['subject' => 'foo']]); @@ -325,14 +324,14 @@ public function testCheckingHasHeaderFunctionality() $this->assertFalse($message->getHeaders()->has('From')); } - public function testWrongMultipart() + public function testWrongMultipart(): void { $this->expectException(Exception\RuntimeException::class); $message = new Message(['raw' => "Content-Type: multipart/mixed\r\n\r\ncontent"]); $message->getPart(1); } - public function testLateFetch() + public function testLateFetch(): void { $mail = new Storage\Mbox(['filename' => __DIR__ . '/../_files/test.mbox/INBOX']); @@ -347,7 +346,7 @@ public function testLateFetch() $this->assertStringStartsWith('multipart message', $message->getContent()); } - public function testManualIterator() + public function testManualIterator(): void { $message = new Message(['file' => $this->file]); @@ -369,11 +368,11 @@ public function testManualIterator() $this->assertEquals($message->key(), 1); } - public function testMessageFlagsAreSet() + public function testMessageFlagsAreSet(): void { $origFlags = [ 'foo' => 'bar', - 'baz' => 'bat' + 'baz' => 'bat', ]; $message = new Message(['flags' => $origFlags]); @@ -383,51 +382,51 @@ public function testMessageFlagsAreSet() $this->assertEquals(['bar' => 'bar', 'bat' => 'bat'], $messageFlags); } - public function testGetHeaderFieldSingle() + public function testGetHeaderFieldSingle(): void { $message = new Message(['file' => $this->file]); $this->assertEquals($message->getHeaderField('subject'), 'multipart'); } - public function testGetHeaderFieldDefault() + public function testGetHeaderFieldDefault(): void { $message = new Message(['file' => $this->file]); $this->assertEquals($message->getHeaderField('content-type'), 'multipart/alternative'); } - public function testGetHeaderFieldNamed() + public function testGetHeaderFieldNamed(): void { $message = new Message(['file' => $this->file]); $this->assertEquals($message->getHeaderField('content-type', 'boundary'), 'crazy-multipart'); } - public function testGetHeaderFieldMissing() + public function testGetHeaderFieldMissing(): void { $message = new Message(['file' => $this->file]); $this->assertNull($message->getHeaderField('content-type', 'foo')); } - public function testGetHeaderFieldInvalid() + public function testGetHeaderFieldInvalid(): void { $this->expectException(MailException\ExceptionInterface::class); $message = new Message(['file' => $this->file]); $message->getHeaderField('fake-header-name', 'foo'); } - public function testCaseInsensitiveMultipart() + public function testCaseInsensitiveMultipart(): void { $message = new Message(['raw' => "coNTent-TYpe: muLTIpaRT/x-empty\r\n\r\n"]); $this->assertTrue($message->isMultipart()); } - public function testCaseInsensitiveField() + public function testCaseInsensitiveField(): void { $header = 'test; fOO="this is a test"'; $this->assertEquals(Mime\Decode::splitHeaderField($header, 'Foo'), 'this is a test'); $this->assertEquals(Mime\Decode::splitHeaderField($header, 'bar'), null); } - public function testSpaceInFieldName() + public function testSpaceInFieldName(): void { $header = 'test; foo =bar; baz =42'; $this->assertEquals(Mime\Decode::splitHeaderField($header, 'foo'), 'bar'); @@ -439,7 +438,7 @@ public function testSpaceInFieldName() * * @see https://github.com/laminas/laminas-mail/pull/93 */ - public function testHeadersLosesNameQuoting() + public function testHeadersLosesNameQuoting(): void { $headerList = [ 'From: "Famous bearings |;" ', @@ -462,7 +461,7 @@ public function testHeadersLosesNameQuoting() /** * @group Laminas-372 */ - public function testStrictParseMessage() + public function testStrictParseMessage(): void { $this->expectException(MailException\RuntimeException::class); @@ -471,7 +470,7 @@ public function testStrictParseMessage() $message = new Message(['raw' => $raw, 'strict' => true]); } - public function testMultivalueToHeader() + public function testMultivaluedToHeader(): void { $message = new Message(['file' => $this->file2]); /** @var \Laminas\Mail\Header\To $header */ @@ -481,7 +480,7 @@ public function testMultivalueToHeader() $this->assertEquals('nicpoń', $addressList->get('bar@example.pl')->getName()); } - public function filesProvider() + public function filesProvider(): array { $filePath = __DIR__ . '/../_files/mail.txt'; $fileBlankLineOnTop = __DIR__ . '/../_files/mail_blank_top_line.txt'; diff --git a/test/Storage/Pop3Test.php b/test/Storage/Pop3Test.php index 07e75075..ab82e7d5 100644 --- a/test/Storage/Pop3Test.php +++ b/test/Storage/Pop3Test.php @@ -22,7 +22,7 @@ class Pop3Test extends TestCase { protected $params; - public function setUp() + public function setUp(): void { if (! getenv('TESTS_LAMINAS_MAIL_POP3_ENABLED')) { $this->markTestSkipped('Laminas_Mail POP3 tests are not enabled'); @@ -31,7 +31,7 @@ public function setUp() $this->params = [ 'host' => getenv('TESTS_LAMINAS_MAIL_POP3_HOST'), 'user' => getenv('TESTS_LAMINAS_MAIL_POP3_USER'), - 'password' => getenv('TESTS_LAMINAS_MAIL_POP3_PASSWORD') + 'password' => getenv('TESTS_LAMINAS_MAIL_POP3_PASSWORD'), ]; if (getenv('TESTS_LAMINAS_MAIL_SERVER_TESTDIR') && getenv('TESTS_LAMINAS_MAIL_SERVER_TESTDIR')) { @@ -54,7 +54,7 @@ public function setUp() } } - protected function cleanDir($dir) + protected function cleanDir($dir): void { $dh = opendir($dir); while (($entry = readdir($dh)) !== false) { @@ -72,7 +72,7 @@ protected function cleanDir($dir) closedir($dh); } - protected function copyDir($dir, $dest) + protected function copyDir($dir, $dest): void { $dh = opendir($dir); while (($entry = readdir($dh)) !== false) { @@ -91,18 +91,17 @@ protected function copyDir($dir, $dest) closedir($dh); } - public function testConnectOk() + public function testConnectOk(): void { new Storage\Pop3($this->params); } - public function testConnectConfig() + public function testConnectConfig(): void { new Storage\Pop3(new Config\Config($this->params)); } - - public function testConnectFailure() + public function testConnectFailure(): void { $this->params['host'] = 'example.example'; @@ -110,13 +109,13 @@ public function testConnectFailure() new Storage\Pop3($this->params); } - public function testNoParams() + public function testNoParams(): void { $this->expectException(Exception\InvalidArgumentException::class); new Storage\Pop3([]); } - public function testConnectSSL() + public function testConnectSSL(): void { if (! getenv('TESTS_LAMINAS_MAIL_POP3_SSL')) { return; @@ -127,7 +126,7 @@ public function testConnectSSL() new Storage\Pop3($this->params); } - public function testConnectTLS() + public function testConnectTLS(): void { if (! getenv('TESTS_LAMINAS_MAIL_POP3_TLS')) { return; @@ -138,7 +137,7 @@ public function testConnectTLS() new Storage\Pop3($this->params); } - public function testConnectSelfSignedSSL() + public function testConnectSelfSignedSSL(): void { if (! getenv('TESTS_LAMINAS_MAIL_POP3_SSL')) { return; @@ -150,7 +149,7 @@ public function testConnectSelfSignedSSL() new Storage\Pop3($this->params); } - public function testInvalidService() + public function testInvalidService(): void { $this->params['port'] = getenv('TESTS_LAMINAS_MAIL_POP3_INVALID_PORT'); @@ -158,7 +157,7 @@ public function testInvalidService() new Storage\Pop3($this->params); } - public function testWrongService() + public function testWrongService(): void { $this->params['port'] = getenv('TESTS_LAMINAS_MAIL_POP3_WRONG_PORT'); @@ -166,35 +165,35 @@ public function testWrongService() new Storage\Pop3($this->params); } - public function testClose() + public function testClose(): void { $mail = new Storage\Pop3($this->params); $mail->close(); } - public function testHasTop() + public function testHasTop(): void { $mail = new Storage\Pop3($this->params); $this->assertTrue($mail->hasTop); } - public function testHasCreate() + public function testHasCreate(): void { $mail = new Storage\Pop3($this->params); $this->assertFalse($mail->hasCreate); } - public function testNoop() + public function testNoop(): void { $mail = new Storage\Pop3($this->params); $mail->noop(); } - public function testCount() + public function testCount(): void { $mail = new Storage\Pop3($this->params); @@ -202,17 +201,16 @@ public function testCount() $this->assertEquals(7, $count); } - public function testSize() + public function testSize(): void { $mail = new Storage\Pop3($this->params); $shouldSizes = [1 => 397, 89, 694, 452, 497, 101, 139]; - $sizes = $mail->getSize(); $this->assertEquals($shouldSizes, $sizes); } - public function testSingleSize() + public function testSingleSize(): void { $mail = new Storage\Pop3($this->params); @@ -220,7 +218,7 @@ public function testSingleSize() $this->assertEquals(89, $size); } - public function testFetchHeader() + public function testFetchHeader(): void { $mail = new Storage\Pop3($this->params); @@ -238,7 +236,7 @@ public function testFetchTopBody() } */ - public function testFetchMessageHeader() + public function testFetchMessageHeader(): void { $mail = new Storage\Pop3($this->params); @@ -246,7 +244,7 @@ public function testFetchMessageHeader() $this->assertEquals('Simple Message', $subject); } - public function testFetchMessageBody() + public function testFetchMessageBody(): void { $mail = new Storage\Pop3($this->params); @@ -270,7 +268,7 @@ public function testFailedRemove() } */ - public function testWithInstanceConstruction() + public function testWithInstanceConstruction(): void { $protocol = new Protocol\Pop3($this->params['host']); $mail = new Storage\Pop3($protocol); @@ -280,7 +278,7 @@ public function testWithInstanceConstruction() $mail->getMessage(1); } - public function testRequestAfterClose() + public function testRequestAfterClose(): void { $mail = new Storage\Pop3($this->params); $mail->close(); @@ -289,13 +287,13 @@ public function testRequestAfterClose() $mail->getMessage(1); } - public function testServerCapa() + public function testServerCapa(): void { $mail = new Protocol\Pop3($this->params['host']); $this->assertInternalType('array', $mail->capa()); } - public function testServerUidl() + public function testServerUidl(): void { $mail = new Protocol\Pop3($this->params['host']); $mail->login($this->params['user'], $this->params['password']); @@ -306,14 +304,14 @@ public function testServerUidl() $this->assertEquals($uids[1], $mail->uniqueid(1)); } - public function testRawHeader() + public function testRawHeader(): void { $mail = new Storage\Pop3($this->params); $this->assertContains("\r\nSubject: Simple Message\r\n", $mail->getRawHeader(1)); } - public function testUniqueId() + public function testUniqueId(): void { $mail = new Storage\Pop3($this->params); @@ -337,7 +335,7 @@ public function testUniqueId() } } - public function testWrongUniqueId() + public function testWrongUniqueId(): void { $mail = new Storage\Pop3($this->params); @@ -345,7 +343,7 @@ public function testWrongUniqueId() $mail->getNumberByUniqueId('this_is_an_invalid_id'); } - public function testReadAfterClose() + public function testReadAfterClose(): void { $protocol = new Protocol\Pop3($this->params['host']); $protocol->logout(); @@ -354,7 +352,7 @@ public function testReadAfterClose() $protocol->readResponse(); } - public function testRemove() + public function testRemove(): void { $mail = new Storage\Pop3($this->params); $count = $mail->countMessages(); @@ -366,7 +364,7 @@ public function testRemove() $this->assertEquals($mail->countMessages(), --$count); } - public function testDotMessage() + public function testDotMessage(): void { $mail = new Storage\Pop3($this->params); $content = ''; diff --git a/test/TestAsset/SmtpProtocolSpy.php b/test/TestAsset/SmtpProtocolSpy.php index b9645600..79379ea1 100644 --- a/test/TestAsset/SmtpProtocolSpy.php +++ b/test/TestAsset/SmtpProtocolSpy.php @@ -20,42 +20,32 @@ class SmtpProtocolSpy extends Smtp protected $mail; protected $rcptTest = []; - public function connect() + public function connect(): bool { $this->connect = true; return true; } - public function disconnect() + public function disconnect(): void { $this->connect = false; parent::disconnect(); } - public function helo($serverName = '127.0.0.1') - { - parent::helo($serverName); - } - - public function quit() + public function quit(): void { $this->calledQuit = true; parent::quit(); } - public function rset() + public function rset(): void { parent::rset(); $this->rcptTest = []; } - public function mail($from) - { - parent::mail($from); - } - - public function rcpt($to) + public function rcpt($to): void { parent::rcpt($to); $this->rcpt = true; @@ -63,7 +53,7 @@ public function rcpt($to) } // @codingStandardsIgnoreStart - protected function _send($request) + protected function _send($request): void { // Save request to internal log $this->_addLog($request . self::EOL); @@ -71,7 +61,7 @@ protected function _send($request) // @codingStandardsIgnoreEnd // @codingStandardsIgnoreStart - protected function _expect($code, $timeout = null) + protected function _expect($code, $timeout = null): string { return ''; } @@ -82,27 +72,17 @@ protected function _expect($code, $timeout = null) * * @return bool */ - public function isConnected() + public function isConnected(): bool { return $this->connect; } - /** - * Get value of mail property - * - * @return null|string - */ - public function getMail() - { - return $this->mail; - } - /** * Get recipients * * @return array */ - public function getRecipients() + public function getRecipients(): array { return $this->rcptTest; } @@ -112,7 +92,7 @@ public function getRecipients() * * @return bool */ - public function getAuth() + public function getAuth(): bool { return $this->auth; } @@ -123,30 +103,20 @@ public function getAuth() * @param bool $status * @return self */ - public function setAuth($status) + public function setAuth($status): self { $this->auth = (bool) $status; return $this; } - /** - * Get Session Status - * - * @return bool - */ - public function getSessionStatus() - { - return $this->sess; - } - /** * Set Session Status * * @param bool $status * @return self */ - public function setSessionStatus($status) + public function setSessionStatus($status): self { $this->sess = (bool) $status; diff --git a/test/Transport/FactoryTest.php b/test/Transport/FactoryTest.php index 83d788df..c5768a60 100644 --- a/test/Transport/FactoryTest.php +++ b/test/Transport/FactoryTest.php @@ -26,12 +26,12 @@ class FactoryTest extends TestCase * @expectedException \Laminas\Mail\Transport\Exception\InvalidArgumentException * @param $spec */ - public function testInvalidSpecThrowsInvalidArgumentException($spec) + public function testInvalidSpecThrowsInvalidArgumentException($spec): void { Factory::create($spec); } - public function invalidSpecTypeProvider() + public function invalidSpecTypeProvider(): array { return [ ['spec'], @@ -42,7 +42,7 @@ public function invalidSpecTypeProvider() /** * */ - public function testDefaultTypeIsSendmail() + public function testDefaultTypeIsSendmail(): void { $transport = Factory::create(); @@ -53,11 +53,10 @@ public function testDefaultTypeIsSendmail() * @dataProvider typeProvider * @param $type */ - public function testCanCreateClassUsingTypeKey($type) + public function testCanCreateClassUsingTypeKey($type): void { - set_error_handler(function ($code, $message) { + set_error_handler(function ($code, $message): void { // skip deprecation notices - return; }, E_USER_DEPRECATED); $transport = Factory::create([ 'type' => $type, @@ -67,7 +66,7 @@ public function testCanCreateClassUsingTypeKey($type) $this->assertInstanceOf($type, $transport); } - public function typeProvider() + public function typeProvider(): array { $types = [ [File::class], @@ -84,7 +83,7 @@ public function typeProvider() * @param $type * @param $expectedClass */ - public function testCanCreateClassFromTypeAlias($type, $expectedClass) + public function testCanCreateClassFromTypeAlias($type, $expectedClass): void { $transport = Factory::create([ 'type' => $type, @@ -93,7 +92,7 @@ public function testCanCreateClassFromTypeAlias($type, $expectedClass) $this->assertInstanceOf($expectedClass, $transport); } - public function typeAliasProvider() + public function typeAliasProvider(): array { return [ ['file', File::class], @@ -116,7 +115,7 @@ public function typeAliasProvider() /** * */ - public function testCanUseTraversableAsSpec() + public function testCanUseTraversableAsSpec(): void { $spec = new ArrayObject([ 'type' => 'inMemory', @@ -132,14 +131,14 @@ public function testCanUseTraversableAsSpec() * @expectedException \Laminas\Mail\Transport\Exception\DomainException * @param $class */ - public function testInvalidClassThrowsDomainException($class) + public function testInvalidClassThrowsDomainException($class): void { Factory::create([ - 'type' => $class + 'type' => $class, ]); } - public function invalidClassProvider() + public function invalidClassProvider(): array { return [ ['stdClass'], @@ -150,13 +149,13 @@ public function invalidClassProvider() /** * */ - public function testCanCreateSmtpTransportWithOptions() + public function testCanCreateSmtpTransportWithOptions(): void { $transport = Factory::create([ 'type' => 'smtp', 'options' => [ 'host' => 'somehost', - ] + ], ]); $this->assertEquals($transport->getOptions()->getHost(), 'somehost'); @@ -165,13 +164,13 @@ public function testCanCreateSmtpTransportWithOptions() /** * */ - public function testCanCreateFileTransportWithOptions() + public function testCanCreateFileTransportWithOptions(): void { $transport = Factory::create([ 'type' => 'file', 'options' => [ 'path' => __DIR__, - ] + ], ]); $this->assertEquals($transport->getOptions()->getPath(), __DIR__); diff --git a/test/Transport/FileOptionsTest.php b/test/Transport/FileOptionsTest.php index b7ecff33..b6fb7774 100644 --- a/test/Transport/FileOptionsTest.php +++ b/test/Transport/FileOptionsTest.php @@ -21,17 +21,17 @@ class FileOptionsTest extends TestCase /** @var FileOptions */ private $options; - public function setUp() + public function setUp(): void { $this->options = new FileOptions(); } - public function testPathIsSysTempDirByDefault() + public function testPathIsSysTempDirByDefault(): void { $this->assertEquals(sys_get_temp_dir(), $this->options->getPath()); } - public function testDefaultCallbackIsSetByDefault() + public function testDefaultCallbackIsSetByDefault(): void { $callback = $this->options->getCallback(); $this->assertInternalType('callable', $callback); @@ -39,7 +39,7 @@ public function testDefaultCallbackIsSetByDefault() $this->assertRegExp('#^LaminasMail_\d+_\d+\.eml$#', $test); } - public function testPathIsMutable() + public function testPathIsMutable(): void { $original = $this->options->getPath(); $this->options->setPath(__DIR__); @@ -48,10 +48,10 @@ public function testPathIsMutable() $this->assertEquals(__DIR__, $test); } - public function testCallbackIsMutable() + public function testCallbackIsMutable(): void { $original = $this->options->getCallback(); - $new = function ($transport) { + $new = function ($transport): void { }; $this->options->setCallback($new); @@ -60,14 +60,14 @@ public function testCallbackIsMutable() $this->assertSame($new, $test); } - public function testSetCallbackThrowsWhenNotCallable() + public function testSetCallbackThrowsWhenNotCallable(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('expects a valid callback'); $this->options->setCallback(null); } - public function testSetPathThrowsWhenPathNotWritable() + public function testSetPathThrowsWhenPathNotWritable(): void { $this->expectException(Exception\InvalidArgumentException::class); $this->expectExceptionMessage('expects a valid path in which to write mail files'); diff --git a/test/Transport/FileTest.php b/test/Transport/FileTest.php index 58ea3716..e5ff3c3f 100644 --- a/test/Transport/FileTest.php +++ b/test/Transport/FileTest.php @@ -19,7 +19,10 @@ */ class FileTest extends TestCase { - public function setUp() + /** @var string */ + private $tempDir; + + public function setUp(): void { $this->tempDir = sys_get_temp_dir() . '/mail_file_transport'; if (! is_dir($this->tempDir)) { @@ -34,20 +37,20 @@ public function setUp() $this->transport = new File($fileOptions); } - public function tearDown() + public function tearDown(): void { $this->cleanup($this->tempDir); rmdir($this->tempDir); } - protected function cleanup($dir) + protected function cleanup($dir): void { foreach (glob($dir . '/*.*') as $file) { unlink($file); } } - public function getMessage() + public function getMessage(): Message { $message = new Message(); $message->addTo('test@example.com', 'Example Test') @@ -66,7 +69,7 @@ public function getMessage() return $message; } - public function testReceivesMailArtifacts() + public function testReceivesMailArtifacts(): void { $message = $this->getMessage(); $this->transport->send($message); @@ -78,7 +81,7 @@ public function testReceivesMailArtifacts() $this->assertEquals($message->toString(), $test); } - public function testConstructorNoOptions() + public function testConstructorNoOptions(): void { $transport = new File(); $this->assertSame(FileOptions::class, \get_class($transport->getOptions())); diff --git a/test/Transport/InMemoryTest.php b/test/Transport/InMemoryTest.php index 98592747..04da6e29 100644 --- a/test/Transport/InMemoryTest.php +++ b/test/Transport/InMemoryTest.php @@ -18,7 +18,7 @@ */ class InMemoryTest extends TestCase { - public function getMessage() + public function getMessage(): Message { $message = new Message(); $message->addTo('test@example.com', 'Example Test') @@ -37,7 +37,7 @@ public function getMessage() return $message; } - public function testReceivesMailArtifacts() + public function testReceivesMailArtifacts(): void { $message = $this->getMessage(); $transport = new InMemory(); @@ -47,7 +47,7 @@ public function testReceivesMailArtifacts() $this->assertSame($message, $transport->getLastMessage()); } - public function testNullMessage() + public function testNullMessage(): void { $transport = new InMemory(); $this->assertNull($transport->getLastMessage()); diff --git a/test/Transport/SendmailTest.php b/test/Transport/SendmailTest.php index f9524256..e95bc520 100644 --- a/test/Transport/SendmailTest.php +++ b/test/Transport/SendmailTest.php @@ -30,11 +30,11 @@ class SendmailTest extends TestCase public $additional_parameters; public $operating_system; - public function setUp() + public function setUp(): void { $this->transport = new Sendmail(); $this->transport->setCallable( - function ($to, $subject, $message, $additional_headers, $additional_parameters = null) { + function ($to, $subject, $message, $additional_headers, $additional_parameters = null): void { $this->to = $to; $this->subject = $subject; $this->message = $message; @@ -45,7 +45,7 @@ function ($to, $subject, $message, $additional_headers, $additional_parameters = $this->operating_system = strtoupper(substr(PHP_OS, 0, 3)); } - public function tearDown() + public function tearDown(): void { $this->to = null; $this->subject = null; @@ -54,7 +54,7 @@ public function tearDown() $this->additional_parameters = null; } - public function getMessage() + public function getMessage(): Message { $message = new Message(); $message->addTo('test@example.com', 'Example Test') @@ -73,12 +73,12 @@ public function getMessage() return $message; } - private function isWindows() + private function isWindows(): bool { return $this->operating_system === 'WIN'; } - public function testReceivesMailArtifactsOnUnixSystems() + public function testReceivesMailArtifactsOnUnixSystems(): void { if ($this->isWindows()) { $this->markTestSkipped('This test is *nix-specific'); @@ -100,7 +100,7 @@ public function testReceivesMailArtifactsOnUnixSystems() $this->assertEquals('-R hdrs -f\'ralph@example.com\'', $this->additional_parameters); } - public function testReceivesMailArtifactsOnWindowsSystems() + public function testReceivesMailArtifactsOnWindowsSystems(): void { if (! $this->isWindows()) { $this->markTestSkipped('This test is Windows-specific'); @@ -124,7 +124,7 @@ public function testReceivesMailArtifactsOnWindowsSystems() $this->assertNull($this->additional_parameters); } - public function testLinesStartingWithFullStopsArePreparedProperlyForWindows() + public function testLinesStartingWithFullStopsArePreparedProperlyForWindows(): void { if (! $this->isWindows()) { $this->markTestSkipped('This test is Windows-specific'); @@ -136,7 +136,7 @@ public function testLinesStartingWithFullStopsArePreparedProperlyForWindows() $this->assertContains("line.\n.. This", trim($this->message)); } - public function testAssertSubjectEncoded() + public function testAssertSubjectEncoded(): void { $message = $this->getMessage(); $message->setEncoding('UTF-8'); @@ -144,7 +144,7 @@ public function testAssertSubjectEncoded() $this->assertEquals('=?UTF-8?Q?Testing=20Laminas\Mail\Transport\Sendmail?=', $this->subject); } - public function testCodeInjectionInFromHeader() + public function testCodeInjectionInFromHeader(): void { $this->expectException(RuntimeException::class); $message = $this->getMessage(); @@ -156,7 +156,7 @@ public function testCodeInjectionInFromHeader() $this->transport->send($message); } - public function testValidEmailLocaDomainInFromHeader() + public function testValidEmailLocaDomainInFromHeader(): void { $message = $this->getMessage(); $message->setBody('This is the text of the email.'); @@ -171,7 +171,7 @@ public function testValidEmailLocaDomainInFromHeader() /** * @ref CVE-2016-10033 which targeted WordPress */ - public function testPrepareParametersEscapesSenderUsingEscapeShellArg() + public function testPrepareParametersEscapesSenderUsingEscapeShellArg(): void { // @codingStandardsIgnoreStart $injectedEmail = 'user@xenial(tmp1 -be ${run{${substr{0}{1}{$spool_directory}}usr${substr{0}{1}{$spool_directory}}bin${substr{0}{1}{$spool_directory}}touch${substr{10}{1}{$tod_log}}${substr{0}{1}{$spool_directory}}tmp${substr{0}{1}{$spool_directory}}test}} tmp2)'; @@ -194,7 +194,7 @@ public function testPrepareParametersEscapesSenderUsingEscapeShellArg() /** * @ref CVE-2016-10033 which targeted WordPress */ - public function testPrepareParametersEscapesFromAddressUsingEscapeShellArg() + public function testPrepareParametersEscapesFromAddressUsingEscapeShellArg(): void { // @codingStandardsIgnoreStart $injectedEmail = 'user@xenial(tmp1 -be ${run{${substr{0}{1}{$spool_directory}}usr${substr{0}{1}{$spool_directory}}bin${substr{0}{1}{$spool_directory}}touch${substr{10}{1}{$tod_log}}${substr{0}{1}{$spool_directory}}tmp${substr{0}{1}{$spool_directory}}test}} tmp2)'; @@ -217,7 +217,7 @@ public function testPrepareParametersEscapesFromAddressUsingEscapeShellArg() $this->assertEquals(' -f' . escapeshellarg($injectedEmail), $parameters); } - public function testTrimmedParameters() + public function testTrimmedParameters(): void { $this->transport->setParameters([' -R', 'hdrs ']); @@ -227,7 +227,7 @@ public function testTrimmedParameters() $this->assertSame('-R hdrs', $r->getValue($this->transport)); } - public function testAllowMessageWithEmptyToHeaderButHasCcHeader() + public function testAllowMessageWithEmptyToHeaderButHasCcHeader(): void { $message = new Message(); $message->addCc('matthew@example.com') @@ -239,7 +239,7 @@ public function testAllowMessageWithEmptyToHeaderButHasCcHeader() $this->assertContains('Sender: Ralph Schindler ', $this->additional_headers); } - public function testAllowMessageWithEmptyToHeaderButHasBccHeader() + public function testAllowMessageWithEmptyToHeaderButHasBccHeader(): void { $message = new Message(); $message->addBcc('list@example.com', 'Example, List') @@ -251,7 +251,7 @@ public function testAllowMessageWithEmptyToHeaderButHasBccHeader() $this->assertContains('Sender: Ralph Schindler ', $this->additional_headers); } - public function testDoNotAllowMessageWithoutToAndCcAndBccHeaders() + public function testDoNotAllowMessageWithoutToAndCcAndBccHeaders(): void { $message = new Message(); $message->setSender('ralph@example.com', 'Ralph Schindler') @@ -265,7 +265,7 @@ public function testDoNotAllowMessageWithoutToAndCcAndBccHeaders() /** * @see https://github.com/laminas/laminas-mail/issues/19 */ - public function testHeadersToAndSubjectAreNotDuplicated() + public function testHeadersToAndSubjectAreNotDuplicated(): void { $message = new Message(); $message diff --git a/test/Transport/SmtpTest.php b/test/Transport/SmtpTest.php index 4ccd1147..b2183360 100644 --- a/test/Transport/SmtpTest.php +++ b/test/Transport/SmtpTest.php @@ -31,14 +31,14 @@ class SmtpTest extends TestCase /** @var SmtpProtocolSpy */ public $connection; - public function setUp() + public function setUp(): void { $this->transport = new Smtp(); $this->connection = new SmtpProtocolSpy(); $this->transport->setConnection($this->connection); } - public function getMessage() + public function getMessage(): Message { $message = new Message(); $message->addTo('test@example.com', 'Example Test'); @@ -62,7 +62,7 @@ public function getMessage() /** * Per RFC 2822 3.6 */ - public function testSendMailWithoutMinimalHeaders() + public function testSendMailWithoutMinimalHeaders(): void { $this->expectException(Exception\RuntimeException::class); $this->expectExceptionMessage( @@ -76,7 +76,7 @@ public function testSendMailWithoutMinimalHeaders() * Per RFC 2821 3.3 (page 18) * - RCPT (recipient) must be called before DATA (headers or body) */ - public function testSendMailWithoutRecipient() + public function testSendMailWithoutRecipient(): void { $this->expectException(Exception\RuntimeException::class); $this->expectExceptionMessage('at least one recipient if the message has at least one header or body'); @@ -85,7 +85,7 @@ public function testSendMailWithoutRecipient() $this->transport->send($message); } - public function testSendMailWithEnvelopeFrom() + public function testSendMailWithEnvelopeFrom(): void { $message = $this->getMessage(); $envelope = new Envelope([ @@ -101,7 +101,7 @@ public function testSendMailWithEnvelopeFrom() $this->assertContains("From: test@example.com,\r\n Matthew \r\n", $data); } - public function testSendMailWithEnvelopeTo() + public function testSendMailWithEnvelopeTo(): void { $message = $this->getMessage(); $envelope = new Envelope([ @@ -116,7 +116,7 @@ public function testSendMailWithEnvelopeTo() $this->assertContains('To: Example Test ', $data); } - public function testSendMailWithEnvelope() + public function testSendMailWithEnvelope(): void { $message = $this->getMessage(); $to = ['users@example.com', 'dev@example.com']; @@ -135,7 +135,7 @@ public function testSendMailWithEnvelope() $this->assertContains('RCPT TO:', $data); } - public function testSendMinimalMail() + public function testSendMinimalMail(): void { $headers = new Headers(); $headers->addHeaderLine('Date', 'Sun, 10 Jun 2012 20:07:24 +0200'); @@ -157,7 +157,7 @@ public function testSendMinimalMail() $this->assertContains($expectedMessage, $this->connection->getLog()); } - public function testSendMinimalMailWithoutSender() + public function testSendMinimalMailWithoutSender(): void { $headers = new Headers(); $headers->addHeaderLine('Date', 'Sun, 10 Jun 2012 20:07:24 +0200'); @@ -179,7 +179,7 @@ public function testSendMinimalMailWithoutSender() $this->assertContains($expectedMessage, $this->connection->getLog()); } - public function testReceivesMailArtifacts() + public function testReceivesMailArtifacts(): void { $message = $this->getMessage(); $this->transport->send($message); @@ -199,7 +199,7 @@ public function testReceivesMailArtifacts() $this->assertContains("\r\n\r\nThis is only a test.", $data, $data); } - public function testCanUseAuthenticationExtensionsViaPluginManager() + public function testCanUseAuthenticationExtensionsViaPluginManager(): void { $options = new SmtpOptions([ 'connection_class' => 'login', @@ -215,25 +215,25 @@ public function testCanUseAuthenticationExtensionsViaPluginManager() $this->assertEquals('password', $connection->getPassword()); } - public function testSetAutoDisconnect() + public function testSetAutoDisconnect(): void { $this->transport->setAutoDisconnect(false); $this->assertFalse($this->transport->getAutoDisconnect()); } - public function testGetDefaultAutoDisconnectValue() + public function testGetDefaultAutoDisconnectValue(): void { $this->assertTrue($this->transport->getAutoDisconnect()); } - public function testAutoDisconnectTrue() + public function testAutoDisconnectTrue(): void { $this->connection->connect(); unset($this->transport); $this->assertFalse($this->connection->hasSession()); } - public function testAutoDisconnectFalse() + public function testAutoDisconnectFalse(): void { $this->connection->connect(); $this->transport->setAutoDisconnect(false); @@ -241,7 +241,7 @@ public function testAutoDisconnectFalse() $this->assertTrue($this->connection->isConnected()); } - public function testDisconnect() + public function testDisconnect(): void { $this->connection->connect(); $this->assertTrue($this->connection->isConnected()); @@ -249,7 +249,7 @@ public function testDisconnect() $this->assertFalse($this->connection->isConnected()); } - public function testDisconnectSendReconnects() + public function testDisconnectSendReconnects(): void { $this->assertFalse($this->connection->hasSession()); $this->transport->send($this->getMessage()); @@ -261,7 +261,7 @@ public function testDisconnectSendReconnects() $this->assertTrue($this->connection->hasSession()); } - public function testAutoReconnect() + public function testAutoReconnect(): void { $options = new SmtpOptions(); $options->setConnectionTimeLimit(5 * 3600); @@ -321,7 +321,6 @@ public function testAutoReconnect() $this->transport->setPluginManager($pluginManagerMock); - // Send the first email - first connect() $this->transport->send($this->getMessage()); @@ -334,14 +333,12 @@ public function testAutoReconnect() $connectedTimeAfterFirstMail = $connectedTimeProperty->getValue($this->transport); $this->assertNotNull($connectedTimeAfterFirstMail); - // Send the second email - no new connect() $this->transport->send($this->getMessage()); // Make sure that there was no new connect() (and no new timestamp was written) $this->assertEquals($connectedTimeAfterFirstMail, $connectedTimeProperty->getValue($this->transport)); - // Manipulate the timestamp to trigger the auto-reconnect $connectedTimeProperty->setValue($this->transport, time() - 10 * 3600);