8000 Use createMock() and use import instead of FQCN · symfony/debug@af4987a · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Dec 9, 2023. It is now read-only.

Commit af4987a

Browse files
OskarStarknicolas-grekas
authored andcommitted
Use createMock() and use import instead of FQCN
1 parent edfa86f commit af4987a

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

Tests/DebugClassLoaderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Debug\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent;
1516
use Symfony\Component\Debug\DebugClassLoader;
1617

1718
/**
@@ -179,7 +180,7 @@ public function testDeprecatedSuperInSameNamespace()
179180
$e = error_reporting(0);
180181
trigger_error('', E_USER_NOTICE);
181182

182-
class_exists(\Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent::class, true);
183+
class_exists(ExtendsDeprecatedParent::class, true);
183184

184185
error_reporting($e);
185186
restore_error_handler();

Tests/ErrorHandlerTest.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
namespace Symfony\Component\Debug\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Psr\Log\LoggerInterface;
1516
use Psr\Log\LogLevel;
1617
use Psr\Log\NullLogger;
1718
use Symfony\Component\Debug\BufferingLogger;
1819
use Symfony\Component\Debug\ErrorHandler;
20+
use Symfony\Component\Debug\Exception\ClassNotFoundException;
1921
use Symfony\Component\Debug\Exception\SilencedErrorContext;
2022
use Symfony\Component\Debug\Tests\Fixtures\ErrorHandlerThatUsesThePreviousOne;
2123
use Symfony\Component\Debug\Tests\Fixtures\LoggerThatSetAnErrorHandler;
@@ -72,7 +74,7 @@ public function testRegister()
7274

7375
public function testErrorGetLast()
7476
{
75-
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
77+
$logger = $this->createMock(LoggerInterface::class);
7678
$handler = ErrorHandler::register();
7779
$handler->setDefaultLogger($logger);
7880
$handler->screamAt(\E_ALL);
@@ -150,7 +152,7 @@ public function testConstruct()
150152
public function testDefaultLogger()
151153
{
152154
try {
153-
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
155+
$logger = $this->createMock(LoggerInterface::class);
154156
$handler = ErrorHandler::register();
155157

156158
$handler->setDefaultLogger($logger, \E_NOTICE);
@@ -225,7 +227,7 @@ public function testHandleError()
225227
restore_error_handler();
226228
restore_exception_handler();
227229

228-
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
230+
$logger = $this->createMock(LoggerInterface::class);
229231

230232
$warnArgCheck = function ($logLevel, $message, $context) {
231233
$this->assertEquals('info', $logLevel);
@@ -250,7 +252,7 @@ public function testHandleError()
250252
restore_error_handler();
251253
restore_exception_handler();
252254

253-
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
255+
$logger = $this->createMock(LoggerInterface::class);
254256

255257
$line = null;
256258
$logArgCheck = function ($level, $message, $context) use (&$line) {
@@ -355,7 +357,7 @@ public function testHandleDeprecation()
355357
$this->assertSame('User Deprecated: Foo deprecation', $exception->getMessage());
356358
};
357359

358-
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
360+
$logger = $this->createMock(LoggerInterface::class);
359361
$logger
360362
->expects($this->once())
361363
->method('log')
@@ -370,7 +372,7 @@ public function testHandleDeprecation()
370372
public function testHandleException()
371373
{
372374
try {
373-
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
375+
$logger = $this->createMock(LoggerInterface::class);
374376
$handler = ErrorHandler::register();
375377

376378
$exception = new \Exception('foo');
@@ -450,7 +452,7 @@ public function testBootstrappingLogger()
450452

451453
$bootLogger->log(LogLevel::WARNING, 'Foo message', ['exception' => $exception]);
452454

453-
$mockLogger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
455+
$mockLogger = $this->createMock(LoggerInterface::class);
454456
$mockLogger->expects($this->once())
455457
->method('log')
456458
->with(LogLevel::WARNING, 'Foo message', ['exception' => $exception]);
@@ -465,7 +467,7 @@ public function testSettingLoggerWhenExceptionIsBuffered()
465467

466468
$exception = new \Exception('Foo message');
467469

468-
$mockLogger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
470+
$mockLogger = $this->createMock(LoggerInterface::class);
469471
$mockLogger->expects($this->once())
470472
->method('log')
471473
->with(LogLevel::CRITICAL, 'Uncaught Exception: Foo message', ['exception' => $exception]);
@@ -480,7 +482,7 @@ public function testSettingLoggerWhenExceptionIsBuffered()
480482
public function testHandleFatalError()
481483
{
482484
try {
483-
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
485+
$logger = $this->createMock(LoggerInterface::class);
484486
$handler = ErrorHandler::register();
485487

486488
$error = [
@@ -527,7 +529,7 @@ public function testHandleErrorException()
527529

528530
$handler->handleException($exception);
529531

530-
$this->assertInstanceOf(\Symfony\Component\Debug\Exception\ClassNotFoundException::class, $args[0]);
532+
$this->assertInstanceOf(ClassNotFoundException::class, $args[0]);
531533
$this->assertStringStartsWith("Attempted to load class \"IReallyReallyDoNotExistAnywhereInTheRepositoryISwear\" from the global namespace.\nDid you forget a \"use\" statement", $args[0]->getMessage());
532534
}
533535

Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Composer\Autoload\ClassLoader as ComposerClassLoader;
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\Debug\DebugClassLoader;
17+
use Symfony\Component\Debug\Exception\ClassNotFoundException;
1718
use Symfony\Component\Debug\Exception\FatalErrorException;
1819
use Symfony\Component\Debug\FatalErrorHandler\ClassNotFoundFatalErrorHandler;
1920

@@ -67,7 +68,7 @@ public function testHandleClassNotFound($error, $translatedMessage, $autoloader
6768
array_map('spl_autoload_register', $autoloaders);
6869
}
6970

70-
$this->assertInstanceOf(\Symfony\Component\Debug\Exception\ClassNotFoundException::class, $exception);
71+
$this->assertInstanceOf(ClassNotFoundException::class, $exception);
7172
$this->assertMatchesRegularExpression($translatedMessage, $exception->getMessage());
7273
$this->assertSame($error['type'], $exception->getSeverity());
7374
$this->assertSame($error['file'], $exception->getFile());
@@ -218,6 +219,6 @@ public function testCannotRedeclareClass()
218219
$handler = new ClassNotFoundFatalErrorHandler();
219220
$exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));
220221

221-
$this->assertInstanceOf(\Symfony\Component\Debug\Exception\ClassNotFoundException::class, $exception);
222+
$this->assertInstanceOf(ClassNotFoundException::class, $exception);
222223
}
223224
}

Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Debug\Exception\FatalErrorException;
16+
use Symfony\Component\Debug\Exception\UndefinedFunctionException;
1617
use Symfony\Component\Debug\FatalErrorHandler\UndefinedFunctionFatalErrorHandler;
1718

1819
/**
@@ -28,7 +29,7 @@ public function testUndefinedFunction($error, $translatedMessage)
2829
$handler = new UndefinedFunctionFatalErrorHandler();
2930
$exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));
3031

31-
$this->assertInstanceOf(\Symfony\Component\Debug\Exception\UndefinedFunctionException::class, $exception);
32+
$this->assertInstanceOf(UndefinedFunctionException::class, $exception);
3233
// class names are case insensitive and PHP do not return the same
3334
$this->assertSame(strtolower($translatedMessage), strtolower($exception->getMessage()));
3435
$this->assertSame($error['type'], $exception->getSeverity());

Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Debug\Exception\FatalErrorException;
16+
use Symfony\Component\Debug\Exception\UndefinedMethodException;
1617
use Symfony\Component\Debug\FatalErrorHandler\UndefinedMethodFatalErrorHandler;
1718

1819
/**
@@ -28,7 +29,7 @@ public function testUndefinedMethod($error, $translatedMessage)
2829
$handler = new UndefinedMethodFatalErrorHandler();
2930
$exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));
3031

31-
$this->assertInstanceOf(\Symfony\Component\Debug\Exception\UndefinedMethodException::class, $exception);
32+
$this->assertInstanceOf(UndefinedMethodException::class, $exception);
3233
$this->assertSame($translatedMessage, $exception->getMessage());
3334
$this->assertSame($error['type'], $exception->getSeverity());
3435
$this->assertSame($error['file'], $exception->getFile());

0 commit comments

Comments
 (0)
1 0