From af4987aa4a5630e9615be9d9c3ed1b0f24ca449c Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Jan 2021 13:09:22 +0100 Subject: [PATCH] Use createMock() and use import instead of FQCN --- Tests/DebugClassLoaderTest.php | 3 ++- Tests/ErrorHandlerTest.php | 22 ++++++++++--------- .../ClassNotFoundFatalErrorHandlerTest.php | 5 +++-- ...UndefinedFunctionFatalErrorHandlerTest.php | 3 ++- .../UndefinedMethodFatalErrorHandlerTest.php | 3 ++- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Tests/DebugClassLoaderTest.php b/Tests/DebugClassLoaderTest.php index dc9617d..0e91ef0 100644 --- a/Tests/DebugClassLoaderTest.php +++ b/Tests/DebugClassLoaderTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Debug\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent; use Symfony\Component\Debug\DebugClassLoader; /** @@ -179,7 +180,7 @@ public function testDeprecatedSuperInSameNamespace() $e = error_reporting(0); trigger_error('', E_USER_NOTICE); - class_exists(\Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent::class, true); + class_exists(ExtendsDeprecatedParent::class, true); error_reporting($e); restore_error_handler(); diff --git a/Tests/ErrorHandlerTest.php b/Tests/ErrorHandlerTest.php index 6c2b31a..1fa2ca1 100644 --- a/Tests/ErrorHandlerTest.php +++ b/Tests/ErrorHandlerTest.php @@ -12,10 +12,12 @@ namespace Symfony\Component\Debug\Tests; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; use Psr\Log\NullLogger; use Symfony\Component\Debug\BufferingLogger; use Symfony\Component\Debug\ErrorHandler; +use Symfony\Component\Debug\Exception\ClassNotFoundException; use Symfony\Component\Debug\Exception\SilencedErrorContext; use Symfony\Component\Debug\Tests\Fixtures\ErrorHandlerThatUsesThePreviousOne; use Symfony\Component\Debug\Tests\Fixtures\LoggerThatSetAnErrorHandler; @@ -72,7 +74,7 @@ public function testRegister() public function testErrorGetLast() { - $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); + $logger = $this->createMock(LoggerInterface::class); $handler = ErrorHandler::register(); $handler->setDefaultLogger($logger); $handler->screamAt(\E_ALL); @@ -150,7 +152,7 @@ public function testConstruct() public function testDefaultLogger() { try { - $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); + $logger = $this->createMock(LoggerInterface::class); $handler = ErrorHandler::register(); $handler->setDefaultLogger($logger, \E_NOTICE); @@ -225,7 +227,7 @@ public function testHandleError() restore_error_handler(); restore_exception_handler(); - $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); + $logger = $this->createMock(LoggerInterface::class); $warnArgCheck = function ($logLevel, $message, $context) { $this->assertEquals('info', $logLevel); @@ -250,7 +252,7 @@ public function testHandleError() restore_error_handler(); restore_exception_handler(); - $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); + $logger = $this->createMock(LoggerInterface::class); $line = null; $logArgCheck = function ($level, $message, $context) use (&$line) { @@ -355,7 +357,7 @@ public function testHandleDeprecation() $this->assertSame('User Deprecated: Foo deprecation', $exception->getMessage()); }; - $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); + $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) ->method('log') @@ -370,7 +372,7 @@ public function testHandleDeprecation() public function testHandleException() { try { - $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); + $logger = $this->createMock(LoggerInterface::class); $handler = ErrorHandler::register(); $exception = new \Exception('foo'); @@ -450,7 +452,7 @@ public function testBootstrappingLogger() $bootLogger->log(LogLevel::WARNING, 'Foo message', ['exception' => $exception]); - $mockLogger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); + $mockLogger = $this->createMock(LoggerInterface::class); $mockLogger->expects($this->once()) ->method('log') ->with(LogLevel::WARNING, 'Foo message', ['exception' => $exception]); @@ -465,7 +467,7 @@ public function testSettingLoggerWhenExceptionIsBuffered() $exception = new \Exception('Foo message'); - $mockLogger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); + $mockLogger = $this->createMock(LoggerInterface::class); $mockLogger->expects($this->once()) ->method('log') ->with(LogLevel::CRITICAL, 'Uncaught Exception: Foo message', ['exception' => $exception]); @@ -480,7 +482,7 @@ public function testSettingLoggerWhenExceptionIsBuffered() public function testHandleFatalError() { try { - $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); + $logger = $this->createMock(LoggerInterface::class); $handler = ErrorHandler::register(); $error = [ @@ -527,7 +529,7 @@ public function testHandleErrorException() $handler->handleException($exception); - $this->assertInstanceOf(\Symfony\Component\Debug\Exception\ClassNotFoundException::class, $args[0]); + $this->assertInstanceOf(ClassNotFoundException::class, $args[0]); $this->assertStringStartsWith("Attempted to load class \"IReallyReallyDoNotExistAnywhereInTheRepositoryISwear\" from the global namespace.\nDid you forget a \"use\" statement", $args[0]->getMessage()); } diff --git a/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php b/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php index 592a1eb..7e2406d 100644 --- a/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php +++ b/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php @@ -14,6 +14,7 @@ use Composer\Autoload\ClassLoader as ComposerClassLoader; use PHPUnit\Framework\TestCase; use Symfony\Component\Debug\DebugClassLoader; +use Symfony\Component\Debug\Exception\ClassNotFoundException; use Symfony\Component\Debug\Exception\FatalErrorException; use Symfony\Component\Debug\FatalErrorHandler\ClassNotFoundFatalErrorHandler; @@ -67,7 +68,7 @@ public function testHandleClassNotFound($error, $translatedMessage, $autoloader array_map('spl_autoload_register', $autoloaders); } - $this->assertInstanceOf(\Symfony\Component\Debug\Exception\ClassNotFoundException::class, $exception); + $this->assertInstanceOf(ClassNotFoundException::class, $exception); $this->assertMatchesRegularExpression($translatedMessage, $exception->getMessage()); $this->assertSame($error['type'], $exception->getSeverity()); $this->assertSame($error['file'], $exception->getFile()); @@ -218,6 +219,6 @@ public function testCannotRedeclareClass() $handler = new ClassNotFoundFatalErrorHandler(); $exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line'])); - $this->assertInstanceOf(\Symfony\Component\Debug\Exception\ClassNotFoundException::class, $exception); + $this->assertInstanceOf(ClassNotFoundException::class, $exception); } } diff --git a/Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php b/Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php index e46b429..7406d7f 100644 --- a/Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php +++ b/Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Debug\Exception\FatalErrorException; +use Symfony\Component\Debug\Exception\UndefinedFunctionException; use Symfony\Component\Debug\FatalErrorHandler\UndefinedFunctionFatalErrorHandler; /** @@ -28,7 +29,7 @@ public function testUndefinedFunction($error, $translatedMessage) $handler = new UndefinedFunctionFatalErrorHandler(); $exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line'])); - $this->assertInstanceOf(\Symfony\Component\Debug\Exception\UndefinedFunctionException::class, $exception); + $this->assertInstanceOf(UndefinedFunctionException::class, $exception); // class names are case insensitive and PHP do not return the same $this->assertSame(strtolower($translatedMessage), strtolower($exception->getMessage())); $this->assertSame($error['type'], $exception->getSeverity()); diff --git a/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php b/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php index d1b8018..55f2f62 100644 --- a/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php +++ b/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Debug\Exception\FatalErrorException; +use Symfony\Component\Debug\Exception\UndefinedMethodException; use Symfony\Component\Debug\FatalErrorHandler\UndefinedMethodFatalErrorHandler; /** @@ -28,7 +29,7 @@ public function testUndefinedMethod($error, $translatedMessage) $handler = new UndefinedMethodFatalErrorHandler(); $exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line'])); - $this->assertInstanceOf(\Symfony\Component\Debug\Exception\UndefinedMethodException::class, $exception); + $this->assertInstanceOf(UndefinedMethodException::class, $exception); $this->assertSame($translatedMessage, $exception->getMessage()); $this->assertSame($error['type'], $exception->getSeverity()); $this->assertSame($error['file'], $exception->getFile());