diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2022-11-03 14:42:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-03 14:42:51 +0100 |
commit | ac92d00da8e56281f9ccef39dfd37844e4824ff5 (patch) | |
tree | 83800006dc835616dfc97d4ec9b8b39cb8dca0db /tests | |
parent | 97f2a28cfe2d50f883f392c4750f41970f3aca58 (diff) | |
parent | 4c8ec6dc8992e13ba4dbb831ac865a41377ec86f (diff) | |
download | nextcloud-server-ac92d00da8e56281f9ccef39dfd37844e4824ff5.tar.gz nextcloud-server-ac92d00da8e56281f9ccef39dfd37844e4824ff5.zip |
Merge pull request #32565 from nextcloud/chore/modernize-error-handler
Modernize the error handler
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/ErrorHandlerTest.php | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/tests/lib/ErrorHandlerTest.php b/tests/lib/ErrorHandlerTest.php index ea53e67005c..f6bf850f0b5 100644 --- a/tests/lib/ErrorHandlerTest.php +++ b/tests/lib/ErrorHandlerTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * ownCloud * @@ -22,7 +25,26 @@ namespace Test; -class ErrorHandlerTest extends \Test\TestCase { +use OC\Log\ErrorHandler; +use OCP\ILogger; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; + +class ErrorHandlerTest extends TestCase { + + /** @var MockObject */ + private LoggerInterface $logger; + + private ErrorHandler $errorHandler; + + protected function setUp(): void { + parent::setUp(); + + $this->logger = $this->createMock(LoggerInterface::class); + $this->errorHandler = new ErrorHandler( + $this->logger + ); + } /** * provide username, password combinations for testRemovePassword @@ -47,24 +69,19 @@ class ErrorHandlerTest extends \Test\TestCase { * @param string $username * @param string $password */ - public function testRemovePassword($username, $password) { + public function testRemovePasswordFromError($username, $password) { $url = 'http://'.$username.':'.$password.'@owncloud.org'; $expectedResult = 'http://xxx:xxx@owncloud.org'; - $result = TestableErrorHandler::testRemovePassword($url); + $this->logger->expects(self::once()) + ->method('log') + ->with( + ILogger::ERROR, + 'Could not reach ' . $expectedResult . ' at file#4', + ['app' => 'PHP'], + ); - $this->assertEquals($expectedResult, $result); - } -} + $result = $this->errorHandler->onError(E_USER_ERROR, 'Could not reach ' . $url, 'file', 4); -/** - * dummy class to access protected methods of \OC\Log\ErrorHandler - */ -class TestableErrorHandler extends \OC\Log\ErrorHandler { - - /** - * @param string $msg - */ - public static function testRemovePassword($msg) { - return self::removePassword($msg); + self::assertTrue($result); } } |