diff --git a/.gitignore b/.gitignore index 4c51f4d0..6d6b9316 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.phpunit.result.cache /clover.xml /composer.lock /coveralls-upload.json diff --git a/.travis.yml b/.travis.yml index 8509c812..311d3039 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,26 +12,28 @@ env: matrix: fast_finish: true include: - - php: 7.1 + - php: 7.3 env: - DEPS=lowest - - php: 7.1 + - php: 7.3 env: - DEPS=latest - - CS_CHECK=true - - TEST_COVERAGE=true - - php: 7.2 + - php: 7.4 env: - DEPS=lowest - - php: 7.2 + - php: 7.4 env: - DEPS=latest - - php: 7.3 + - CS_CHECK=true + - TEST_COVERAGE=true + - php: 8.0 env: - - DEPS=latest - - php: 7.4 + - DEPS=lowest + - COMPOSER_ARGS="--no-interaction --ignore-platform-reqs" + - php: 8.0 env: - DEPS=latest + - COMPOSER_ARGS="--no-interaction --ignore-platform-reqs" before_install: - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi diff --git a/composer.json b/composer.json index d43eba1e..aa5ded6f 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ } }, "require": { - "php": "^7.1", + "php": "^7.3 || ~8.0.0", "ext-iconv": "*", "laminas/laminas-loader": "^2.5", "laminas/laminas-mime": "^2.5", @@ -36,10 +36,10 @@ }, "require-dev": { "laminas/laminas-coding-standard": "~1.0.0", - "laminas/laminas-config": "^2.6", + "laminas/laminas-config": "^3.4", "laminas/laminas-crypt": "^2.6 || ^3.0", "laminas/laminas-servicemanager": "^3.2.1", - "phpunit/phpunit": "^7.5.20" + "phpunit/phpunit": "^9.3" }, "suggest": { "laminas/laminas-crypt": "Crammd5 support in SMTP Auth", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4d03446c..7bf32933 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,6 @@ @@ -15,11 +15,11 @@ - - + + ./src - - + + diff --git a/test/Header/ContentTransferEncodingTest.php b/test/Header/ContentTransferEncodingTest.php index 913e0306..ed4aabef 100644 --- a/test/Header/ContentTransferEncodingTest.php +++ b/test/Header/ContentTransferEncodingTest.php @@ -99,7 +99,7 @@ public function testProvidingParametersIntroducesHeaderFolding(): void $header->setTransferEncoding('quoted-printable'); $string = $header->toString(); - $this->assertContains("Content-Transfer-Encoding: quoted-printable", $string); + $this->assertStringContainsString("Content-Transfer-Encoding: quoted-printable", $string); } /** diff --git a/test/Header/GenericHeaderTest.php b/test/Header/GenericHeaderTest.php index eca46fe6..8e3a373b 100644 --- a/test/Header/GenericHeaderTest.php +++ b/test/Header/GenericHeaderTest.php @@ -92,8 +92,8 @@ public function testCRLFsequencesAreEncodedOnToString($fieldValue): void $header->setFieldValue($fieldValue); $serialized = $header->toString(); - $this->assertNotContains("\n", $serialized); - $this->assertNotContains("\r", $serialized); + $this->assertStringNotContainsString("\n", $serialized); + $this->assertStringNotContainsString("\r", $serialized); } /** @@ -196,10 +196,10 @@ public function testChangeEncodingToAsciiNotAllowedWhenHeaderValueContainsUtf8Ch $subject = new GenericHeader(); $subject->setFieldValue('Accents òàùèéì'); - self::assertSame('UTF-8', $subject->getEncoding()); + $this->assertSame('UTF-8', $subject->getEncoding()); $subject->setEncoding('ASCII'); - self::assertSame('UTF-8', $subject->getEncoding()); + $this->assertSame('UTF-8', $subject->getEncoding()); } public function testChangeEncodingBackToAscii(): void @@ -207,39 +207,39 @@ public function testChangeEncodingBackToAscii(): void $subject = new GenericHeader('X-Test'); $subject->setFieldValue('test'); - self::assertSame('ASCII', $subject->getEncoding()); + $this->assertSame('ASCII', $subject->getEncoding()); $subject->setEncoding('UTF-8'); - self::assertSame('UTF-8', $subject->getEncoding()); + $this->assertSame('UTF-8', $subject->getEncoding()); $subject->setEncoding('ASCII'); - self::assertSame('ASCII', $subject->getEncoding()); + $this->assertSame('ASCII', $subject->getEncoding()); } public function testSetNullEncoding(): void { $subject = GenericHeader::fromString('X-Test: test'); - self::assertSame('ASCII', $subject->getEncoding()); + $this->assertSame('ASCII', $subject->getEncoding()); $subject->setEncoding(null); - self::assertSame('ASCII', $subject->getEncoding()); + $this->assertSame('ASCII', $subject->getEncoding()); } public function testSettingFieldValueCanChangeEncoding(): void { $subject = GenericHeader::fromString('X-Test: test'); - self::assertSame('ASCII', $subject->getEncoding()); + $this->assertSame('ASCII', $subject->getEncoding()); $subject->setFieldValue('Accents òàùèéì'); - self::assertSame('UTF-8', $subject->getEncoding()); + $this->assertSame('UTF-8', $subject->getEncoding()); } public function testSettingTheSameEncoding(): void { $subject = GenericHeader::fromString('X-Test: test'); - self::assertSame('ASCII', $subject->getEncoding()); + $this->assertSame('ASCII', $subject->getEncoding()); $subject->setEncoding('ASCII'); - self::assertSame('ASCII', $subject->getEncoding()); + $this->assertSame('ASCII', $subject->getEncoding()); } } diff --git a/test/Header/MessageIdTest.php b/test/Header/MessageIdTest.php index 9c4705fc..4808eb1f 100644 --- a/test/Header/MessageIdTest.php +++ b/test/Header/MessageIdTest.php @@ -35,7 +35,7 @@ public function testAutoGeneration(): void $messageid = new Header\MessageId(); $messageid->setId(); - $this->assertContains('@', $messageid->getFieldValue()); + $this->assertStringContainsString('@', $messageid->getFieldValue()); } public function testAutoGenerationWithServerVars(): void @@ -46,7 +46,7 @@ public function testAutoGenerationWithServerVars(): void $messageid = new Header\MessageId(); $messageid->setId(); - $this->assertContains('@server-name.test', $messageid->getFieldValue()); + $this->assertStringContainsString('@server-name.test', $messageid->getFieldValue()); $_SERVER = $serverBeforeTest; } diff --git a/test/Header/SubjectTest.php b/test/Header/SubjectTest.php index b2c34504..c83f55d4 100644 --- a/test/Header/SubjectTest.php +++ b/test/Header/SubjectTest.php @@ -135,10 +135,10 @@ public function testChangeEncodingToAsciiNotAllowedWhenSubjectContainsUtf8Charac $subject = new Header\Subject(); $subject->setSubject('Accents òàùèéì'); - self::assertSame('UTF-8', $subject->getEncoding()); + $this->assertSame('UTF-8', $subject->getEncoding()); $subject->setEncoding('ASCII'); - self::assertSame('UTF-8', $subject->getEncoding()); + $this->assertSame('UTF-8', $subject->getEncoding()); } public function testChangeEncodingBackToAscii(): void @@ -146,39 +146,39 @@ public function testChangeEncodingBackToAscii(): void $subject = new Header\Subject(); $subject->setSubject('test'); - self::assertSame('ASCII', $subject->getEncoding()); + $this->assertSame('ASCII', $subject->getEncoding()); $subject->setEncoding('UTF-8'); - self::assertSame('UTF-8', $subject->getEncoding()); + $this->assertSame('UTF-8', $subject->getEncoding()); $subject->setEncoding('ASCII'); - self::assertSame('ASCII', $subject->getEncoding()); + $this->assertSame('ASCII', $subject->getEncoding()); } public function testSetNullEncoding(): void { $subject = Header\Subject::fromString('Subject: test'); - self::assertSame('ASCII', $subject->getEncoding()); + $this->assertSame('ASCII', $subject->getEncoding()); $subject->setEncoding(null); - self::assertSame('ASCII', $subject->getEncoding()); + $this->assertSame('ASCII', $subject->getEncoding()); } public function testSettingSubjectCanChangeEncoding(): void { $subject = Header\Subject::fromString('Subject: test'); - self::assertSame('ASCII', $subject->getEncoding()); + $this->assertSame('ASCII', $subject->getEncoding()); $subject->setSubject('Accents òàùèéì'); - self::assertSame('UTF-8', $subject->getEncoding()); + $this->assertSame('UTF-8', $subject->getEncoding()); } public function testSettingTheSameEncoding(): void { $subject = Header\Subject::fromString('Subject: test'); - self::assertSame('ASCII', $subject->getEncoding()); + $this->assertSame('ASCII', $subject->getEncoding()); $subject->setEncoding('ASCII'); - self::assertSame('ASCII', $subject->getEncoding()); + $this->assertSame('ASCII', $subject->getEncoding()); } } diff --git a/test/HeadersTest.php b/test/HeadersTest.php index d9b40005..41bcd68c 100644 --- a/test/HeadersTest.php +++ b/test/HeadersTest.php @@ -606,7 +606,7 @@ public function testGetPluginClassLoaderEmitsDeprecationNotice(): void $this->setDeprecationErrorHandler(); $headers = new Mail\Headers(); - $this->expectException(Deprecated::class); + $this->expectDeprecation(); $this->expectExceptionMessage('getPluginClassLoader is deprecated'); $headers->getPluginClassLoader(); } @@ -618,9 +618,9 @@ public function testSetPluginClassLoaderEmitsDeprecationNotice(): void { $this->setDeprecationErrorHandler(); $headers = new Mail\Headers(); - $loader = $this->prophesize(PluginClassLocator::class)->reveal(); + $loader = $this->createMock(PluginClassLocator::class); - $this->expectException(Deprecated::class); + $this->expectDeprecation(); $this->expectExceptionMessage('deprecated'); $headers->setPluginClassLoader($loader); } @@ -635,7 +635,7 @@ public function testGetHeaderLocatorReturnsHeaderLocatorInstanceByDefault(): voi public function testCanInjectAlternateHeaderLocatorInstance(): void { $headers = new Mail\Headers(); - $locator = $this->prophesize(Mail\Header\HeaderLocatorInterface::class)->reveal(); + $locator = $this->createMock(Mail\Header\HeaderLocatorInterface::class); $headers->setHeaderLocator($locator); $this->assertSame($locator, $headers->getHeaderLocator()); diff --git a/test/MessageTest.php b/test/MessageTest.php index c3920070..3fb98d6f 100644 --- a/test/MessageTest.php +++ b/test/MessageTest.php @@ -582,7 +582,7 @@ public function testSettingUtf8MailBodyFromSinglePartMimeUtf8MessageSetsAppropri $this->message->setEncoding('UTF-8'); $this->message->setBody($body); - $this->assertContains( + $this->assertStringContainsString( 'Content-Type: text/plain;' . Headers::FOLDING . 'charset="utf-8"' . Headers::EOL . 'Content-Transfer-Encoding: quoted-printable' . Headers::EOL, $this->message->getHeaders()->toString() @@ -630,10 +630,10 @@ public function testRetrievingBodyTextFromMessageWithMultiPartMimeBodyReturnsMim $text = $this->message->getBodyText(); $this->assertEquals($body->generateMessage(Headers::EOL), $text); - $this->assertContains('--foo-bar', $text); - $this->assertContains('--foo-bar--', $text); - $this->assertContains('Content-Type: text/plain', $text); - $this->assertContains('Content-Type: text/html', $text); + $this->assertStringContainsString('--foo-bar', $text); + $this->assertStringContainsString('--foo-bar--', $text); + $this->assertStringContainsString('Content-Type: text/plain', $text); + $this->assertStringContainsString('Content-Type: text/html', $text); } public function testEncodingIsAsciiByDefault(): void @@ -666,23 +666,23 @@ public function testSettingNonAsciiEncodingForcesMimeEncodingOfSomeHeaders(): vo $test = $this->message->getHeaders()->toString(); $expected = '=?UTF-8?Q?Laminas=20DevTeam?='; - $this->assertContains($expected, $test); - $this->assertContains('', $test); + $this->assertStringContainsString($expected, $test); + $this->assertStringContainsString('', $test); $expected = "=?UTF-8?Q?Matthew=20Weier=20O'Phinney?="; - $this->assertContains($expected, $test, $test); - $this->assertContains('', $test); + $this->assertStringContainsString($expected, $test, $test); + $this->assertStringContainsString('', $test); $expected = '=?UTF-8?Q?Laminas=20Contributors=20List?='; - $this->assertContains($expected, $test); - $this->assertContains('', $test); + $this->assertStringContainsString($expected, $test); + $this->assertStringContainsString('', $test); $expected = '=?UTF-8?Q?Laminas=20CR=20Team?='; - $this->assertContains($expected, $test); - $this->assertContains('', $test); + $this->assertStringContainsString($expected, $test); + $this->assertStringContainsString('', $test); $expected = 'Subject: =?UTF-8?Q?This=20is=20a=20subject?='; - $this->assertContains($expected, $test); + $this->assertStringContainsString($expected, $test); } /** @@ -785,8 +785,8 @@ public function testDetectsCRLFInjectionViaSubject(): void $this->message->setSubject(implode(Headers::EOL, $subject)); $serializedHeaders = $this->message->getHeaders()->toString(); - $this->assertContains('example', $serializedHeaders); - $this->assertNotContains("\r\n", $serializedHeaders); + $this->assertStringContainsString('example', $serializedHeaders); + $this->assertStringNotContainsString("\r\n", $serializedHeaders); } public function testHeaderUnfoldingWorksAsExpectedForMultipartMessages(): void @@ -820,8 +820,8 @@ public function testHeaderUnfoldingWorksAsExpectedForMultipartMessages(): void $contentType = $this->message->getHeaders()->get('Content-Type'); $this->assertInstanceOf(ContentType::class, $contentType); - $this->assertContains('multipart/alternative', $contentType->getFieldValue()); - $this->assertContains($multipartContent->getMime()->boundary(), $contentType->getFieldValue()); + $this->assertStringContainsString('multipart/alternative', $contentType->getFieldValue()); + $this->assertStringContainsString($multipartContent->getMime()->boundary(), $contentType->getFieldValue()); } /** @@ -832,7 +832,7 @@ public function testCanParseMultipartReport(): void $raw = file_get_contents(__DIR__ . '/_files/laminas-mail-19.txt'); $message = Message::fromString($raw); $this->assertInstanceOf(Message::class, $message); - $this->assertInternalType('string', $message->getBody()); + $this->assertIsString($message->getBody()); $headers = $message->getHeaders(); $this->assertCount(8, $headers); @@ -861,7 +861,7 @@ public function testMailHeaderContainsZeroValue(): void ."I am a test message\r\n"; $msg = Message::fromString($message); - $this->assertContains('X-Spam-Score: 0', $msg->toString()); + $this->assertStringContainsString('X-Spam-Score: 0', $msg->toString()); } /** @@ -882,7 +882,7 @@ public function testMessageSubjectFromString(): void . ' =?UTF-8?Q?vowels=20=C3=B2=C3=A0=C3=B9=C3=A8=C3=A9=C3=AC?='; $mail = Message::fromString($rawMessage); - self::assertContains( + $this->assertStringContainsString( '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?=' . "\r\n", $mail->toString() @@ -894,7 +894,7 @@ public function testMessageSubjectSetSubject(): void $mail = new Message(); $mail->setSubject('Non “ascii” characters like accented vowels òàùèéì'); - self::assertContains( + $this->assertStringContainsString( '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?=' . "\r\n", $mail->toString() @@ -907,7 +907,7 @@ public function testCorrectHeaderEncodingAddHeader(): void $header = new GenericHeader('X-Test', 'Non “ascii” characters like accented vowels òàùèéì'); $mail->getHeaders()->addHeader($header); - self::assertContains( + $this->assertStringContainsString( 'X-Test: =?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?=' . "\r\n", $mail->toString() @@ -922,7 +922,7 @@ public function testCorrectHeaderEncodingSetHeaders(): void $headers->addHeader($header); $mail->setHeaders($headers); - self::assertContains( + $this->assertStringContainsString( 'X-Test: =?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?=' . "\r\n", $mail->toString() @@ -937,7 +937,7 @@ public function testCorrectHeaderEncodingFromString(): void $header = GenericHeader::fromString($str); $mail->getHeaders()->addHeader($header); - self::assertContains( + $this->assertStringContainsString( 'X-Test: =?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?=' . "\r\n", $mail->toString() @@ -955,7 +955,7 @@ public function testCorrectHeaderEncodingFromStringAndSetHeaders(): void $headers->addHeader($header); $mail->setHeaders($headers); - self::assertContains( + $this->assertStringContainsString( 'X-Test: =?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?=' . "\r\n", $mail->toString() @@ -968,8 +968,8 @@ public function testMessageSubjectEncodingWhenEncodingSetAfterTheSubject(): void $mail->setSubject('hello world'); $mail->setEncoding('UTF-8'); - self::assertSame('UTF-8', $mail->getHeaders()->get('subject')->getEncoding()); - self::assertSame( + $this->assertSame('UTF-8', $mail->getHeaders()->get('subject')->getEncoding()); + $this->assertSame( 'Subject: =?UTF-8?Q?hello=20world?=', $mail->getHeaders()->get('subject')->toString() ); @@ -981,8 +981,8 @@ public function testMessageSubjectEncodingWhenEcodingSetBeforeTheSubject(): void $mail->setEncoding('UTF-8'); $mail->setSubject('hello world'); - self::assertSame('UTF-8', $mail->getHeaders()->get('subject')->getEncoding()); - self::assertSame( + $this->assertSame('UTF-8', $mail->getHeaders()->get('subject')->getEncoding()); + $this->assertSame( 'Subject: =?UTF-8?Q?hello=20world?=', $mail->getHeaders()->get('subject')->toString() ); diff --git a/test/Protocol/SmtpPluginManagerFactoryTest.php b/test/Protocol/SmtpPluginManagerFactoryTest.php index 2928290b..3e68e5c0 100644 --- a/test/Protocol/SmtpPluginManagerFactoryTest.php +++ b/test/Protocol/SmtpPluginManagerFactoryTest.php @@ -14,20 +14,25 @@ use Laminas\Mail\Protocol\SmtpPluginManagerFactory; use Laminas\ServiceManager\ServiceLocatorInterface; use PHPUnit\Framework\TestCase; +use ReflectionClass; class SmtpPluginManagerFactoryTest extends TestCase { public function testFactoryReturnsPluginManager(): void { - $container = $this->prophesize(ContainerInterface::class)->reveal(); + $container = $this->createMock(ContainerInterface::class); $factory = new SmtpPluginManagerFactory(); $plugins = $factory($container, SmtpPluginManager::class); $this->assertInstanceOf(SmtpPluginManager::class, $plugins); if (method_exists($plugins, 'configure')) { + $reflectionClass = new ReflectionClass($plugins); + $creationContextProperty = $reflectionClass->getProperty('creationContext'); + $creationContextProperty->setAccessible(true); + // laminas-servicemanager v3 - $this->assertAttributeSame($container, 'creationContext', $plugins); + $this->assertEquals($container, $creationContextProperty->getValue($plugins)); } else { // laminas-servicemanager v2 $this->assertSame($container, $plugins->getServiceLocator()); @@ -39,8 +44,8 @@ public function testFactoryReturnsPluginManager(): void */ public function testFactoryConfiguresPluginManagerUnderContainerInterop(): void { - $container = $this->prophesize(ContainerInterface::class)->reveal(); - $smtp = $this->prophesize(Smtp::class)->reveal(); + $container = $this->createMock(ContainerInterface::class); + $smtp = $this->createMock(Smtp::class); $factory = new SmtpPluginManagerFactory(); $plugins = $factory($container, SmtpPluginManager::class, [ @@ -56,10 +61,9 @@ public function testFactoryConfiguresPluginManagerUnderContainerInterop(): void */ public function testFactoryConfiguresPluginManagerUnderServiceManagerV2(): void { - $container = $this->prophesize(ServiceLocatorInterface::class); - $container->willImplement(ContainerInterface::class); + $container = $this->createMock(ServiceLocatorInterface::class); - $smtp = $this->prophesize(Smtp::class)->reveal(); + $smtp = $this->createMock(Smtp::class); $factory = new SmtpPluginManagerFactory(); $factory->setCreationOptions([ @@ -68,7 +72,7 @@ public function testFactoryConfiguresPluginManagerUnderServiceManagerV2(): void ], ]); - $plugins = $factory->createService($container->reveal()); + $plugins = $factory->createService($container); $this->assertSame($smtp, $plugins->get('test')); } } diff --git a/test/Protocol/SmtpTest.php b/test/Protocol/SmtpTest.php index c7be4270..8da08a1a 100644 --- a/test/Protocol/SmtpTest.php +++ b/test/Protocol/SmtpTest.php @@ -109,7 +109,7 @@ public function testConnectHasVerboseErrors(): void $smtp = new TestAsset\ErroneousSmtp(); $this->expectException(Exception\RuntimeException::class); - $this->expectExceptionMessageRegExp('/nonexistentremote/'); + $this->expectExceptionMessageMatches('/nonexistentremote/'); $smtp->connect('nonexistentremote'); } @@ -123,7 +123,7 @@ public function testCanAvoidQuitRequest(): void $this->connection->helo(); $this->connection->disconnect(); - $this->assertContains('QUIT', $this->connection->getLog()); + $this->assertStringContainsString('QUIT', $this->connection->getLog()); $this->connection->setUseCompleteQuit(false); $this->assertFalse($this->connection->useCompleteQuit()); @@ -133,7 +133,7 @@ public function testCanAvoidQuitRequest(): void $this->connection->helo(); $this->connection->disconnect(); - $this->assertNotContains('QUIT', $this->connection->getLog()); + $this->assertStringNotContainsString('QUIT', $this->connection->getLog()); $connection = new SmtpProtocolSpy([ 'use_complete_quit' => false, diff --git a/test/Storage/ImapTest.php b/test/Storage/ImapTest.php index dc4726bc..952bb624 100644 --- a/test/Storage/ImapTest.php +++ b/test/Storage/ImapTest.php @@ -681,7 +681,7 @@ public function testStore(): void $result = $protocol->store(['\Flagged'], 1, null, '', false); $this->assertContains('\Flagged', $result[1]); $result = $protocol->store(['\Flagged'], 1, null, '-', false); - $this->assertNotContains('\Flagged', $result[1]); + $this->assertStringNotContainsString('\Flagged', $result[1]); $result = $protocol->store(['\Flagged'], 1, null, '+', false); $this->assertContains('\Flagged', $result[1]); } diff --git a/test/Transport/FactoryTest.php b/test/Transport/FactoryTest.php index c5768a60..9e1e8909 100644 --- a/test/Transport/FactoryTest.php +++ b/test/Transport/FactoryTest.php @@ -13,6 +13,7 @@ use Laminas\Mail\Transport\Sendmail; use Laminas\Stdlib\ArrayObject; use PHPUnit\Framework\TestCase; +use Laminas\Mail\Transport\Exception; use Laminas\Mail\Transport\File; use Laminas\Mail\Transport\Smtp; @@ -23,11 +24,11 @@ class FactoryTest extends TestCase { /** * @dataProvider invalidSpecTypeProvider - * @expectedException \Laminas\Mail\Transport\Exception\InvalidArgumentException * @param $spec */ public function testInvalidSpecThrowsInvalidArgumentException($spec): void { + $this->expectException(Exception\InvalidArgumentException::class); Factory::create($spec); } @@ -128,11 +129,11 @@ public function testCanUseTraversableAsSpec(): void /** * @dataProvider invalidClassProvider - * @expectedException \Laminas\Mail\Transport\Exception\DomainException * @param $class */ public function testInvalidClassThrowsDomainException($class): void { + $this->expectException(Exception\DomainException::class); Factory::create([ 'type' => $class, ]); diff --git a/test/Transport/FileOptionsTest.php b/test/Transport/FileOptionsTest.php index b6fb7774..c0e9a906 100644 --- a/test/Transport/FileOptionsTest.php +++ b/test/Transport/FileOptionsTest.php @@ -34,9 +34,9 @@ public function testPathIsSysTempDirByDefault(): void public function testDefaultCallbackIsSetByDefault(): void { $callback = $this->options->getCallback(); - $this->assertInternalType('callable', $callback); + $this->assertIsCallable($callback); $test = $callback(''); - $this->assertRegExp('#^LaminasMail_\d+_\d+\.eml$#', $test); + $this->assertMatchesRegularExpression('#^LaminasMail_\d+_\d+\.eml$#', $test); } public function testPathIsMutable(): void diff --git a/test/Transport/SendmailTest.php b/test/Transport/SendmailTest.php index e95bc520..cc447729 100644 --- a/test/Transport/SendmailTest.php +++ b/test/Transport/SendmailTest.php @@ -91,12 +91,12 @@ public function testReceivesMailArtifactsOnUnixSystems(): void $this->assertEquals('Example Test ', $this->to); $this->assertEquals('Testing Laminas\Mail\Transport\Sendmail', $this->subject); $this->assertEquals('This is only a test.', trim($this->message)); - $this->assertNotContains("To: Example Test \n", $this->additional_headers); - $this->assertContains("Cc: matthew@example.com\n", $this->additional_headers); - $this->assertContains("Bcc: \"Example, List\" \n", $this->additional_headers); - $this->assertContains("From: test@example.com,\n Matthew \n", $this->additional_headers); - $this->assertContains("X-Foo-Bar: Matthew\n", $this->additional_headers); - $this->assertContains("Sender: Ralph Schindler \n", $this->additional_headers); + $this->assertStringNotContainsString("To: Example Test \n", $this->additional_headers); + $this->assertStringContainsString("Cc: matthew@example.com\n", $this->additional_headers); + $this->assertStringContainsString("Bcc: \"Example, List\" \n", $this->additional_headers); + $this->assertStringContainsString("From: test@example.com,\n Matthew \n", $this->additional_headers); + $this->assertStringContainsString("X-Foo-Bar: Matthew\n", $this->additional_headers); + $this->assertStringContainsString("Sender: Ralph Schindler \n", $this->additional_headers); $this->assertEquals('-R hdrs -f\'ralph@example.com\'', $this->additional_parameters); } @@ -112,15 +112,15 @@ public function testReceivesMailArtifactsOnWindowsSystems(): void $this->assertEquals('test@example.com', $this->to); $this->assertEquals('Testing Laminas\Mail\Transport\Sendmail', $this->subject); $this->assertEquals('This is only a test.', trim($this->message)); - $this->assertContains("To: Example Test \r\n", $this->additional_headers); - $this->assertContains("Cc: matthew@example.com\r\n", $this->additional_headers); - $this->assertContains("Bcc: \"Example, List\" \r\n", $this->additional_headers); - $this->assertContains( + $this->assertStringContainsString("To: Example Test \r\n", $this->additional_headers); + $this->assertStringContainsString("Cc: matthew@example.com\r\n", $this->additional_headers); + $this->assertStringContainsString("Bcc: \"Example, List\" \r\n", $this->additional_headers); + $this->assertStringContainsString( "From: test@example.com,\r\n Matthew \r\n", $this->additional_headers ); - $this->assertContains("X-Foo-Bar: Matthew\r\n", $this->additional_headers); - $this->assertContains("Sender: Ralph Schindler \r\n", $this->additional_headers); + $this->assertStringContainsString("X-Foo-Bar: Matthew\r\n", $this->additional_headers); + $this->assertStringContainsString("Sender: Ralph Schindler \r\n", $this->additional_headers); $this->assertNull($this->additional_parameters); } @@ -133,7 +133,7 @@ public function testLinesStartingWithFullStopsArePreparedProperlyForWindows(): v $message = $this->getMessage(); $message->setBody("This is the first line.\n. This is the second"); $this->transport->send($message); - $this->assertContains("line.\n.. This", trim($this->message)); + $this->assertStringContainsString("line.\n.. This", trim($this->message)); } public function testAssertSubjectEncoded(): void @@ -165,7 +165,7 @@ public function testValidEmailLocaDomainInFromHeader(): void $message->setSubject('TestSubject'); $this->transport->send($message); - $this->assertContains('From: Foo Bar <"foo-bar"@domain>', $this->additional_headers); + $this->assertStringContainsString('From: Foo Bar <"foo-bar"@domain>', $this->additional_headers); } /** @@ -177,17 +177,17 @@ public function testPrepareParametersEscapesSenderUsingEscapeShellArg(): void $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)'; // @codingStandardsIgnoreEnd - $sender = $this->prophesize(AddressInterface::class); - $sender->getEmail()->willReturn($injectedEmail); + $sender = $this->createMock(AddressInterface::class); + $sender->method('getEmail')->willReturn($injectedEmail); - $message = $this->prophesize(Message::class); - $message->getSender()->will([$sender, 'reveal']); - $message->getFrom()->shouldNotBeCalled(); + $message = $this->createMock(Message::class); + $message->method('getSender')->willReturn($sender); + $message->expects($this->never())->method('getFrom'); $r = new ReflectionMethod($this->transport, 'prepareParameters'); $r->setAccessible(true); - $parameters = $r->invoke($this->transport, $message->reveal()); + $parameters = $r->invoke($this->transport, $message); $this->assertEquals(' -f' . escapeshellarg($injectedEmail), $parameters); } @@ -200,20 +200,20 @@ public function testPrepareParametersEscapesFromAddressUsingEscapeShellArg(): vo $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)'; // @codingStandardsIgnoreEnd - $address = $this->prophesize(AddressInterface::class); - $address->getEmail()->willReturn($injectedEmail)->shouldBeCalledTimes(2); + $address = $this->createMock(AddressInterface::class); + $address->expects($this->exactly(2))->method('getEmail')->willReturn($injectedEmail); $from = new AddressList(); - $from->add($address->reveal()); + $from->add($address); - $message = $this->prophesize(Message::class); - $message->getSender()->willReturn(null); - $message->getFrom()->willReturn($from); + $message = $this->createMock(Message::class); + $message->method('getSender')->willReturn(null); + $message->method('getFrom')->willReturn($from); $r = new ReflectionMethod($this->transport, 'prepareParameters'); $r->setAccessible(true); - $parameters = $r->invoke($this->transport, $message->reveal()); + $parameters = $r->invoke($this->transport, $message); $this->assertEquals(' -f' . escapeshellarg($injectedEmail), $parameters); } @@ -236,7 +236,7 @@ public function testAllowMessageWithEmptyToHeaderButHasCcHeader(): void ->setBody('This is only a test.'); $this->transport->send($message); - $this->assertContains('Sender: Ralph Schindler ', $this->additional_headers); + $this->assertStringContainsString('Sender: Ralph Schindler ', $this->additional_headers); } public function testAllowMessageWithEmptyToHeaderButHasBccHeader(): void @@ -248,7 +248,7 @@ public function testAllowMessageWithEmptyToHeaderButHasBccHeader(): void ->setBody('This is only a test.'); $this->transport->send($message); - $this->assertContains('Sender: Ralph Schindler ', $this->additional_headers); + $this->assertStringContainsString('Sender: Ralph Schindler ', $this->additional_headers); } public function testDoNotAllowMessageWithoutToAndCcAndBccHeaders(): void @@ -279,8 +279,8 @@ public function testHeadersToAndSubjectAreNotDuplicated(): void $this->assertEquals('matthew@example.org', $this->to); $this->assertEquals('Greetings and Salutations!', $this->subject); - $this->assertNotRegExp('/^To: matthew\@example\.org$/m', $this->additional_headers); - $this->assertNotRegExp('/^Subject: Greetings and Salutations!$/m', $this->additional_headers); + $this->assertDoesNotMatchRegularExpression('/^To: matthew\@example\.org$/m', $this->additional_headers); + $this->assertDoesNotMatchRegularExpression('/^Subject: Greetings and Salutations!$/m', $this->additional_headers); } public function additionalParametersContainingFromSwitch(): iterable diff --git a/test/Transport/SmtpTest.php b/test/Transport/SmtpTest.php index b2183360..07a1f9c9 100644 --- a/test/Transport/SmtpTest.php +++ b/test/Transport/SmtpTest.php @@ -95,10 +95,10 @@ public function testSendMailWithEnvelopeFrom(): void $this->transport->send($message); $data = $this->connection->getLog(); - $this->assertContains('MAIL FROM:', $data); - $this->assertContains('RCPT TO:', $data); - $this->assertContains('RCPT TO:', $data); - $this->assertContains("From: test@example.com,\r\n Matthew \r\n", $data); + $this->assertStringContainsString('MAIL FROM:', $data); + $this->assertStringContainsString('RCPT TO:', $data); + $this->assertStringContainsString('RCPT TO:', $data); + $this->assertStringContainsString("From: test@example.com,\r\n Matthew \r\n", $data); } public function testSendMailWithEnvelopeTo(): void @@ -111,9 +111,9 @@ public function testSendMailWithEnvelopeTo(): void $this->transport->send($message); $data = $this->connection->getLog(); - $this->assertContains('MAIL FROM:', $data); - $this->assertContains('RCPT TO:', $data); - $this->assertContains('To: Example Test ', $data); + $this->assertStringContainsString('MAIL FROM:', $data); + $this->assertStringContainsString('RCPT TO:', $data); + $this->assertStringContainsString('To: Example Test ', $data); } public function testSendMailWithEnvelope(): void @@ -130,9 +130,9 @@ public function testSendMailWithEnvelope(): void $this->assertEquals($to, $this->connection->getRecipients()); $data = $this->connection->getLog(); - $this->assertContains('MAIL FROM:', $data); - $this->assertContains('RCPT TO:', $data); - $this->assertContains('RCPT TO:', $data); + $this->assertStringContainsString('MAIL FROM:', $data); + $this->assertStringContainsString('RCPT TO:', $data); + $this->assertStringContainsString('RCPT TO:', $data); } public function testSendMinimalMail(): void @@ -154,7 +154,7 @@ public function testSendMinimalMail(): void $this->transport->send($message); - $this->assertContains($expectedMessage, $this->connection->getLog()); + $this->assertStringContainsString($expectedMessage, $this->connection->getLog()); } public function testSendMinimalMailWithoutSender(): void @@ -176,7 +176,7 @@ public function testSendMinimalMailWithoutSender(): void $this->transport->send($message); - $this->assertContains($expectedMessage, $this->connection->getLog()); + $this->assertStringContainsString($expectedMessage, $this->connection->getLog()); } public function testReceivesMailArtifacts(): void @@ -188,15 +188,15 @@ public function testReceivesMailArtifacts(): void $this->assertEquals($expectedRecipients, $this->connection->getRecipients()); $data = $this->connection->getLog(); - $this->assertContains('MAIL FROM:', $data); - $this->assertContains('To: Example Test ', $data); - $this->assertContains('Subject: Testing Laminas\Mail\Transport\Sendmail', $data); - $this->assertContains("Cc: matthew@example.com\r\n", $data); - $this->assertNotContains("Bcc: \"Example List\" \r\n", $data); - $this->assertContains("From: test@example.com,\r\n Matthew \r\n", $data); - $this->assertContains("X-Foo-Bar: Matthew\r\n", $data); - $this->assertContains("Sender: Ralph Schindler \r\n", $data); - $this->assertContains("\r\n\r\nThis is only a test.", $data, $data); + $this->assertStringContainsString('MAIL FROM:', $data); + $this->assertStringContainsString('To: Example Test ', $data); + $this->assertStringContainsString('Subject: Testing Laminas\Mail\Transport\Sendmail', $data); + $this->assertStringContainsString("Cc: matthew@example.com\r\n", $data); + $this->assertStringNotContainsString("Bcc: \"Example List\" \r\n", $data); + $this->assertStringContainsString("From: test@example.com,\r\n Matthew \r\n", $data); + $this->assertStringContainsString("X-Foo-Bar: Matthew\r\n", $data); + $this->assertStringContainsString("Sender: Ralph Schindler \r\n", $data); + $this->assertStringContainsString("\r\n\r\nThis is only a test.", $data, $data); } public function testCanUseAuthenticationExtensionsViaPluginManager(): void @@ -328,7 +328,7 @@ public function testAutoReconnect(): void $reflClass = new \ReflectionClass($this->transport); $connectedTimeProperty = $reflClass->getProperty('connectedTime'); - self::assertNotNull($connectedTimeProperty); + $this->assertNotNull($connectedTimeProperty); $connectedTimeProperty->setAccessible(true); $connectedTimeAfterFirstMail = $connectedTimeProperty->getValue($this->transport); $this->assertNotNull($connectedTimeAfterFirstMail);