aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/ErrorHandlerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/ErrorHandlerTest.php')
-rw-r--r--tests/lib/ErrorHandlerTest.php81
1 files changed, 44 insertions, 37 deletions
diff --git a/tests/lib/ErrorHandlerTest.php b/tests/lib/ErrorHandlerTest.php
index ea53e67005c..0bec3445d34 100644
--- a/tests/lib/ErrorHandlerTest.php
+++ b/tests/lib/ErrorHandlerTest.php
@@ -1,34 +1,46 @@
<?php
+
+declare(strict_types=1);
+
/**
- * ownCloud
- *
- * @author Bjoern Schiessle
- * @copyright 2014 Bjoern Schiessle <schiessle@owncloud.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
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 {
+ private LoggerInterface&MockObject $logger;
+ private ErrorHandler $errorHandler;
+ private int $errorReporting;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->logger = $this->createMock(LoggerInterface::class);
+ $this->errorHandler = new ErrorHandler(
+ $this->logger
+ );
+
+ $this->errorReporting = error_reporting(E_ALL);
+ }
+
+ protected function tearDown(): void {
+ error_reporting($this->errorReporting);
+ parent::tearDown();
+ }
/**
* provide username, password combinations for testRemovePassword
* @return array
*/
- public function passwordProvider() {
+ public static function passwordProvider(): array {
return [
['us:er', 'pass@word'],
['us:er', 'password'],
@@ -43,28 +55,23 @@ class ErrorHandlerTest extends \Test\TestCase {
}
/**
- * @dataProvider passwordProvider
* @param string $username
* @param string $password
*/
- public function testRemovePassword($username, $password) {
- $url = 'http://'.$username.':'.$password.'@owncloud.org';
+ #[\PHPUnit\Framework\Attributes\DataProvider('passwordProvider')]
+ public function testRemovePasswordFromError($username, $password): void {
+ $url = 'http://' . $username . ':' . $password . '@owncloud.org';
$expectedResult = 'http://xxx:xxx@owncloud.org';
- $result = TestableErrorHandler::testRemovePassword($url);
-
- $this->assertEquals($expectedResult, $result);
- }
-}
+ $this->logger->expects(self::once())
+ ->method('log')
+ ->with(
+ ILogger::ERROR,
+ 'Could not reach ' . $expectedResult . ' at file#4',
+ ['app' => 'PHP'],
+ );
-/**
- * dummy class to access protected methods of \OC\Log\ErrorHandler
- */
-class TestableErrorHandler extends \OC\Log\ErrorHandler {
+ $result = $this->errorHandler->onError(E_USER_ERROR, 'Could not reach ' . $url, 'file', 4);
- /**
- * @param string $msg
- */
- public static function testRemovePassword($msg) {
- return self::removePassword($msg);
+ self::assertTrue($result);
}
}