diff options
Diffstat (limited to 'tests/lib/AppFramework')
26 files changed, 118 insertions, 111 deletions
diff --git a/tests/lib/AppFramework/AppTest.php b/tests/lib/AppFramework/AppTest.php index 87c96fdb9a8..b44ddd6082b 100644 --- a/tests/lib/AppFramework/AppTest.php +++ b/tests/lib/AppFramework/AppTest.php @@ -9,9 +9,10 @@ namespace Test\AppFramework; use OC\AppFramework\App; +use OC\AppFramework\DependencyInjection\DIContainer; use OC\AppFramework\Http\Dispatcher; use OCP\AppFramework\Controller; -use OCP\AppFramework\Http; +use OCP\AppFramework\Http\IOutput; use OCP\AppFramework\Http\Response; function rrmdir($directory) { @@ -43,10 +44,10 @@ class AppTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->container = new \OC\AppFramework\DependencyInjection\DIContainer('test', []); + $this->container = new DIContainer('test', []); $this->controller = $this->createMock(Controller::class); $this->dispatcher = $this->createMock(Dispatcher::class); - $this->io = $this->createMock(Http\IOutput::class); + $this->io = $this->createMock(IOutput::class); $this->headers = ['key' => 'value']; $this->output = 'hi'; diff --git a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php index 05e7a1b71c7..0eeddb2173a 100644 --- a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php +++ b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php @@ -11,6 +11,7 @@ namespace lib\AppFramework\Bootstrap; use OC\AppFramework\Bootstrap\Coordinator; use OC\Support\CrashReport\Registry; +use OCA\Settings\AppInfo\Application; use OCP\App\IAppManager; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; @@ -76,7 +77,7 @@ class CoordinatorTest extends TestCase { $appId = 'settings'; $this->serverContainer->expects($this->once()) ->method('query') - ->with(\OCA\Settings\AppInfo\Application::class) + ->with(Application::class) ->willThrowException(new QueryException('')); $this->logger->expects($this->once()) ->method('error'); @@ -86,10 +87,10 @@ class CoordinatorTest extends TestCase { public function testBootAppNotBootable(): void { $appId = 'settings'; - $mockApp = $this->createMock(\OCA\Settings\AppInfo\Application::class); + $mockApp = $this->createMock(Application::class); $this->serverContainer->expects($this->once()) ->method('query') - ->with(\OCA\Settings\AppInfo\Application::class) + ->with(Application::class) ->willReturn($mockApp); $this->coordinator->bootApp($appId); @@ -110,7 +111,7 @@ class CoordinatorTest extends TestCase { }; $this->serverContainer->expects($this->once()) ->method('query') - ->with(\OCA\Settings\AppInfo\Application::class) + ->with(Application::class) ->willReturn($mockApp); $this->coordinator->bootApp($appId); diff --git a/tests/lib/AppFramework/Bootstrap/FunctionInjectorTest.php b/tests/lib/AppFramework/Bootstrap/FunctionInjectorTest.php index c32331e8ba1..8f6944ce34f 100644 --- a/tests/lib/AppFramework/Bootstrap/FunctionInjectorTest.php +++ b/tests/lib/AppFramework/Bootstrap/FunctionInjectorTest.php @@ -11,6 +11,7 @@ namespace lib\AppFramework\Bootstrap; use OC\AppFramework\Bootstrap\FunctionInjector; use OC\AppFramework\Utility\SimpleContainer; +use OCP\AppFramework\QueryException; use Test\TestCase; interface Foo { @@ -27,7 +28,7 @@ class FunctionInjectorTest extends TestCase { } public function testInjectFnNotRegistered(): void { - $this->expectException(\OCP\AppFramework\QueryException::class); + $this->expectException(QueryException::class); (new FunctionInjector($this->container))->injectFn(static function (Foo $p1): void { }); diff --git a/tests/lib/AppFramework/Controller/PublicShareControllerTest.php b/tests/lib/AppFramework/Controller/PublicShareControllerTest.php index 6f0e433f2fb..97216845617 100644 --- a/tests/lib/AppFramework/Controller/PublicShareControllerTest.php +++ b/tests/lib/AppFramework/Controller/PublicShareControllerTest.php @@ -11,17 +11,14 @@ use OCP\IRequest; use OCP\ISession; class TestController extends PublicShareController { - /** @var string */ - private $hash; - - /** @var bool */ - private $isProtected; - - public function __construct(string $appName, IRequest $request, ISession $session, string $hash, bool $isProtected) { + public function __construct( + string $appName, + IRequest $request, + ISession $session, + private string $hash, + private bool $isProtected, + ) { parent::__construct($appName, $request, $session); - - $this->hash = $hash; - $this->isProtected = $isProtected; } protected function getPasswordHash(): string { diff --git a/tests/lib/AppFramework/Db/EntityTest.php b/tests/lib/AppFramework/Db/EntityTest.php index ccd0ae4bbaf..4fcf126e3b1 100644 --- a/tests/lib/AppFramework/Db/EntityTest.php +++ b/tests/lib/AppFramework/Db/EntityTest.php @@ -36,7 +36,6 @@ use PHPUnit\Framework\Constraint\IsType; * @method void setDatetime(\DateTimeImmutable $datetime) */ class TestEntity extends Entity { - protected $name; protected $email; protected $testId; protected $smallInt; @@ -49,7 +48,9 @@ class TestEntity extends Entity { protected $time; protected $datetime; - public function __construct($name = null) { + public function __construct( + protected $name = null, + ) { $this->addType('testId', Types::INTEGER); $this->addType('smallInt', Types::SMALLINT); $this->addType('bigInt', Types::BIGINT); @@ -63,8 +64,6 @@ class TestEntity extends Entity { $this->addType('trueOrFalse', 'bool'); $this->addType('legacyInt', 'int'); $this->addType('doubleNowFloat', 'double'); - - $this->name = $name; } public function setAnotherBool(bool $anotherBool): void { diff --git a/tests/lib/AppFramework/Db/QBMapperDBTest.php b/tests/lib/AppFramework/Db/QBMapperDBTest.php index 72bc2d956d6..a61240fcb82 100644 --- a/tests/lib/AppFramework/Db/QBMapperDBTest.php +++ b/tests/lib/AppFramework/Db/QBMapperDBTest.php @@ -70,7 +70,7 @@ class QBMapperDBTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OCP\Server::get(IDBConnection::class); + $this->connection = Server::get(IDBConnection::class); $this->prepareTestingTable(); } diff --git a/tests/lib/AppFramework/Db/QBMapperTest.php b/tests/lib/AppFramework/Db/QBMapperTest.php index c1d8bf07234..1fac6632b30 100644 --- a/tests/lib/AppFramework/Db/QBMapperTest.php +++ b/tests/lib/AppFramework/Db/QBMapperTest.php @@ -127,7 +127,7 @@ class QBMapperTest extends \Test\TestCase { ]; $this->qb->expects($this->exactly(6)) ->method('createNamedParameter') - ->willReturnCallback(function () use (&$createNamedParameterCalls) { + ->willReturnCallback(function () use (&$createNamedParameterCalls): void { $expected = array_shift($createNamedParameterCalls); $this->assertEquals($expected, func_get_args()); }); @@ -142,7 +142,7 @@ class QBMapperTest extends \Test\TestCase { ]; $this->qb->expects($this->exactly(6)) ->method('setValue') - ->willReturnCallback(function () use (&$setValueCalls) { + ->willReturnCallback(function () use (&$setValueCalls): void { $expected = array_shift($setValueCalls); $this->assertEquals($expected, func_get_args()); }); @@ -184,7 +184,7 @@ class QBMapperTest extends \Test\TestCase { ]; $this->qb->expects($this->exactly(8)) ->method('createNamedParameter') - ->willReturnCallback(function () use (&$createNamedParameterCalls) { + ->willReturnCallback(function () use (&$createNamedParameterCalls): void { $expected = array_shift($createNamedParameterCalls); $this->assertEquals($expected, func_get_args()); }); @@ -200,7 +200,7 @@ class QBMapperTest extends \Test\TestCase { ]; $this->qb->expects($this->exactly(7)) ->method('set') - ->willReturnCallback(function () use (&$setCalls) { + ->willReturnCallback(function () use (&$setCalls): void { $expected = array_shift($setCalls); $this->assertEquals($expected, func_get_args()); }); diff --git a/tests/lib/AppFramework/Db/TransactionalTest.php b/tests/lib/AppFramework/Db/TransactionalTest.php index a60c4386fea..bf8abcd7aa2 100644 --- a/tests/lib/AppFramework/Db/TransactionalTest.php +++ b/tests/lib/AppFramework/Db/TransactionalTest.php @@ -35,7 +35,7 @@ class TransactionalTest extends TestCase { } public function fail(): void { - $this->atomic(function () { + $this->atomic(function (): void { throw new RuntimeException('nope'); }, $this->db); } diff --git a/tests/lib/AppFramework/DependencyInjection/DIIntergrationTests.php b/tests/lib/AppFramework/DependencyInjection/DIIntergrationTests.php index 54c691d2392..8f0e60c5b3b 100644 --- a/tests/lib/AppFramework/DependencyInjection/DIIntergrationTests.php +++ b/tests/lib/AppFramework/DependencyInjection/DIIntergrationTests.php @@ -21,16 +21,14 @@ class ClassA2 implements Interface1 { } class ClassB { - /** @var Interface1 */ - public $interface1; - /** * ClassB constructor. * * @param Interface1 $interface1 */ - public function __construct(Interface1 $interface1) { - $this->interface1 = $interface1; + public function __construct( + public Interface1 $interface1, + ) { } } diff --git a/tests/lib/AppFramework/Http/DataResponseTest.php b/tests/lib/AppFramework/Http/DataResponseTest.php index 7ae19e7d5d8..e9a2c511140 100644 --- a/tests/lib/AppFramework/Http/DataResponseTest.php +++ b/tests/lib/AppFramework/Http/DataResponseTest.php @@ -11,6 +11,7 @@ namespace Test\AppFramework\Http; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; +use OCP\Server; class DataResponseTest extends \Test\TestCase { /** @@ -53,7 +54,7 @@ class DataResponseTest extends \Test\TestCase { 'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'", 'Feature-Policy' => "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'", 'X-Robots-Tag' => 'noindex, nofollow', - 'X-Request-Id' => \OC::$server->get(IRequest::class)->getId(), + 'X-Request-Id' => Server::get(IRequest::class)->getId(), ]; $expectedHeaders = array_merge($expectedHeaders, $headers); diff --git a/tests/lib/AppFramework/Http/DispatcherTest.php b/tests/lib/AppFramework/Http/DispatcherTest.php index 404d3f4c90b..4ed6627891c 100644 --- a/tests/lib/AppFramework/Http/DispatcherTest.php +++ b/tests/lib/AppFramework/Http/DispatcherTest.php @@ -24,6 +24,7 @@ use OCP\IConfig; use OCP\IDBConnection; use OCP\IRequest; use OCP\IRequestId; +use OCP\Server; use PHPUnit\Framework\MockObject\MockObject; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -130,7 +131,7 @@ class DispatcherTest extends \Test\TestCase { $this->reflector, $this->request, $this->config, - \OCP\Server::get(IDBConnection::class), + Server::get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container, @@ -156,7 +157,7 @@ class DispatcherTest extends \Test\TestCase { ->method('beforeController') ->with($this->equalTo($this->controller), $this->equalTo($this->controllerMethod)) - ->will($this->throwException($exception)); + ->willThrowException($exception); if ($catchEx) { $this->middlewareDispatcher->expects($this->once()) ->method('afterException') @@ -307,7 +308,7 @@ class DispatcherTest extends \Test\TestCase { $this->http, $this->middlewareDispatcher, $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container @@ -340,7 +341,7 @@ class DispatcherTest extends \Test\TestCase { $this->http, $this->middlewareDispatcher, $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container @@ -376,7 +377,7 @@ class DispatcherTest extends \Test\TestCase { $this->http, $this->middlewareDispatcher, $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container @@ -411,7 +412,7 @@ class DispatcherTest extends \Test\TestCase { $this->http, $this->middlewareDispatcher, $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container @@ -447,7 +448,7 @@ class DispatcherTest extends \Test\TestCase { $this->http, $this->middlewareDispatcher, $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container @@ -482,7 +483,7 @@ class DispatcherTest extends \Test\TestCase { $this->http, $this->middlewareDispatcher, $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container @@ -520,7 +521,7 @@ class DispatcherTest extends \Test\TestCase { $this->http, $this->middlewareDispatcher, $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container @@ -564,7 +565,7 @@ class DispatcherTest extends \Test\TestCase { $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container, diff --git a/tests/lib/AppFramework/Http/PublicTemplateResponseTest.php b/tests/lib/AppFramework/Http/PublicTemplateResponseTest.php index d963705bc24..cb7bd97f5da 100644 --- a/tests/lib/AppFramework/Http/PublicTemplateResponseTest.php +++ b/tests/lib/AppFramework/Http/PublicTemplateResponseTest.php @@ -7,8 +7,8 @@ namespace Test\AppFramework\Http; -use OCP\AppFramework\Http; use OCP\AppFramework\Http\Template\PublicTemplateResponse; +use OCP\AppFramework\Http\Template\SimpleMenuAction; use Test\TestCase; class PublicTemplateResponseTest extends TestCase { @@ -28,7 +28,7 @@ class PublicTemplateResponseTest extends TestCase { public function testActionSingle(): void { $actions = [ - new Http\Template\SimpleMenuAction('link', 'Download', 'download', 'downloadLink', 0) + new SimpleMenuAction('link', 'Download', 'download', 'downloadLink', 0) ]; $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']); $template->setHeaderActions($actions); @@ -41,9 +41,9 @@ class PublicTemplateResponseTest extends TestCase { public function testActionMultiple(): void { $actions = [ - new Http\Template\SimpleMenuAction('link1', 'Download1', 'download1', 'downloadLink1', 100), - new Http\Template\SimpleMenuAction('link2', 'Download2', 'download2', 'downloadLink2', 20), - new Http\Template\SimpleMenuAction('link3', 'Download3', 'download3', 'downloadLink3', 0) + new SimpleMenuAction('link1', 'Download1', 'download1', 'downloadLink1', 100), + new SimpleMenuAction('link2', 'Download2', 'download2', 'downloadLink2', 20), + new SimpleMenuAction('link3', 'Download3', 'download3', 'downloadLink3', 0) ]; $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']); $template->setHeaderActions($actions); diff --git a/tests/lib/AppFramework/Http/ResponseTest.php b/tests/lib/AppFramework/Http/ResponseTest.php index c129b5637c5..7750db921c6 100644 --- a/tests/lib/AppFramework/Http/ResponseTest.php +++ b/tests/lib/AppFramework/Http/ResponseTest.php @@ -9,6 +9,8 @@ namespace Test\AppFramework\Http; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\ContentSecurityPolicy; +use OCP\AppFramework\Http\EmptyContentSecurityPolicy; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Utility\ITimeFactory; @@ -54,7 +56,7 @@ class ResponseTest extends \Test\TestCase { $expected = [ 'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-inline';style-src 'self' 'unsafe-inline';img-src 'self';font-src 'self' data:;connect-src 'self';media-src 'self'", ]; - $policy = new Http\ContentSecurityPolicy(); + $policy = new ContentSecurityPolicy(); $this->childResponse->setContentSecurityPolicy($policy); $headers = $this->childResponse->getHeaders(); @@ -63,14 +65,14 @@ class ResponseTest extends \Test\TestCase { } public function testGetCsp(): void { - $policy = new Http\ContentSecurityPolicy(); + $policy = new ContentSecurityPolicy(); $this->childResponse->setContentSecurityPolicy($policy); $this->assertEquals($policy, $this->childResponse->getContentSecurityPolicy()); } public function testGetCspEmpty(): void { - $this->assertEquals(new Http\EmptyContentSecurityPolicy(), $this->childResponse->getContentSecurityPolicy()); + $this->assertEquals(new EmptyContentSecurityPolicy(), $this->childResponse->getContentSecurityPolicy()); } public function testAddHeaderValueNullDeletesIt(): void { diff --git a/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php b/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php index 22b1b13aaee..4fa5de62b0b 100644 --- a/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php @@ -67,7 +67,7 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase { ->method($this->anything()); $this->dispatcher->expects($this->once()) ->method('dispatchTyped') - ->willReturnCallback(function ($event) { + ->willReturnCallback(function ($event): void { if ($event instanceof BeforeTemplateRenderedEvent && $event->isLoggedIn() === false) { return; } @@ -83,7 +83,7 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase { ->willReturn(false); $this->dispatcher->expects($this->once()) ->method('dispatchTyped') - ->willReturnCallback(function ($event) { + ->willReturnCallback(function ($event): void { if ($event instanceof BeforeTemplateRenderedEvent && $event->isLoggedIn() === false) { return; } @@ -101,7 +101,7 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase { ->willReturn(true); $this->dispatcher->expects($this->once()) ->method('dispatchTyped') - ->willReturnCallback(function ($event) { + ->willReturnCallback(function ($event): void { if ($event instanceof BeforeTemplateRenderedEvent && $event->isLoggedIn() === true) { return; } diff --git a/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php b/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php index a8273be362b..aae1c53456b 100644 --- a/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php +++ b/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php @@ -34,17 +34,16 @@ class TestMiddleware extends Middleware { public $response; public $output; - private $beforeControllerThrowsEx; - /** * @param boolean $beforeControllerThrowsEx */ - public function __construct($beforeControllerThrowsEx) { + public function __construct( + private $beforeControllerThrowsEx, + ) { self::$beforeControllerCalled = 0; self::$afterControllerCalled = 0; self::$afterExceptionCalled = 0; self::$beforeOutputCalled = 0; - $this->beforeControllerThrowsEx = $beforeControllerThrowsEx; } public function beforeController($controller, $methodName) { @@ -136,13 +135,13 @@ class MiddlewareDispatcherTest extends \Test\TestCase { public function testAfterExceptionShouldReturnResponseOfMiddleware(): void { $response = new Response(); - $m1 = $this->getMockBuilder(\OCP\AppFramework\Middleware::class) + $m1 = $this->getMockBuilder(Middleware::class) ->onlyMethods(['afterException', 'beforeController']) ->getMock(); $m1->expects($this->never()) ->method('afterException'); - $m2 = $this->getMockBuilder(\OCP\AppFramework\Middleware::class) + $m2 = $this->getMockBuilder(Middleware::class) ->onlyMethods(['afterException', 'beforeController']) ->getMock(); $m2->expects($this->once()) diff --git a/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php b/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php index d80df1841c8..0abbd9c614c 100644 --- a/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php @@ -11,6 +11,7 @@ namespace Test\AppFramework\Middleware; use OC\AppFramework\Middleware\NotModifiedMiddleware; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Response; use OCP\IRequest; class NotModifiedMiddlewareTest extends \Test\TestCase { @@ -68,7 +69,7 @@ class NotModifiedMiddlewareTest extends \Test\TestCase { return ''; }); - $response = new Http\Response(); + $response = new Response(); if ($etag !== null) { $response->setETag($etag); } diff --git a/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php b/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php index 62e20a2dcd0..b22646b8891 100644 --- a/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php @@ -12,6 +12,7 @@ use OC\AppFramework\OCS\V1Response; use OC\AppFramework\OCS\V2Response; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\Response; use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSException; @@ -82,7 +83,7 @@ class OCSMiddlewareTest extends \Test\TestCase { $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); if ($exception->getCode() === 0) { - $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); + $this->assertSame(OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); } else { $this->assertSame($code, $result->getOCSStatus()); } @@ -112,7 +113,7 @@ class OCSMiddlewareTest extends \Test\TestCase { $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); if ($exception->getCode() === 0) { - $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); + $this->assertSame(OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); } else { $this->assertSame($code, $result->getOCSStatus()); } @@ -141,7 +142,7 @@ class OCSMiddlewareTest extends \Test\TestCase { $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); if ($exception->getCode() === 0) { - $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); + $this->assertSame(OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); } else { $this->assertSame($code, $result->getOCSStatus()); } @@ -151,16 +152,16 @@ class OCSMiddlewareTest extends \Test\TestCase { public static function dataAfterController(): array { return [ [OCSController::class, new Response(), false], - [OCSController::class, new Http\JSONResponse(), false], - [OCSController::class, new Http\JSONResponse(['message' => 'foo']), false], - [OCSController::class, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_UNAUTHORIZED), true, OCSController::RESPOND_UNAUTHORISED], - [OCSController::class, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_FORBIDDEN), true], + [OCSController::class, new JSONResponse(), false], + [OCSController::class, new JSONResponse(['message' => 'foo']), false], + [OCSController::class, new JSONResponse(['message' => 'foo'], Http::STATUS_UNAUTHORIZED), true, OCSController::RESPOND_UNAUTHORISED], + [OCSController::class, new JSONResponse(['message' => 'foo'], Http::STATUS_FORBIDDEN), true], [Controller::class, new Response(), false], - [Controller::class, new Http\JSONResponse(), false], - [Controller::class, new Http\JSONResponse(['message' => 'foo']), false], - [Controller::class, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_UNAUTHORIZED), false], - [Controller::class, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_FORBIDDEN), false], + [Controller::class, new JSONResponse(), false], + [Controller::class, new JSONResponse(['message' => 'foo']), false], + [Controller::class, new JSONResponse(['message' => 'foo'], Http::STATUS_UNAUTHORIZED), false], + [Controller::class, new JSONResponse(['message' => 'foo'], Http::STATUS_FORBIDDEN), false], ]; } diff --git a/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php index c516c1e6c89..ae575fa947f 100644 --- a/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php @@ -248,7 +248,7 @@ class BruteForceMiddlewareTest extends TestCase { $this->throttler ->expects($this->exactly(2)) ->method('registerAttempt') - ->willReturnCallback(function () use (&$attemptCalls) { + ->willReturnCallback(function () use (&$attemptCalls): void { $expected = array_shift($attemptCalls); $this->assertEquals($expected, func_get_args()); }); diff --git a/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php index f22933a5884..2132a4d511f 100644 --- a/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php @@ -10,6 +10,7 @@ use OC\AppFramework\Http\Request; use OC\AppFramework\Middleware\Security\CORSMiddleware; use OC\AppFramework\Middleware\Security\Exceptions\SecurityException; use OC\AppFramework\Utility\ControllerMethodReflector; +use OC\Authentication\Exceptions\PasswordLoginForbiddenException; use OC\User\Session; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\Response; @@ -124,7 +125,7 @@ class CORSMiddlewareTest extends \Test\TestCase { * @dataProvider dataCorsIgnoredIfWithCredentialsHeaderPresent */ public function testCorsIgnoredIfWithCredentialsHeaderPresent(string $method): void { - $this->expectException(\OC\AppFramework\Middleware\Security\Exceptions\SecurityException::class); + $this->expectException(SecurityException::class); $request = new Request( [ @@ -253,7 +254,7 @@ class CORSMiddlewareTest extends \Test\TestCase { * @dataProvider dataCORSShouldFailIfPasswordLoginIsForbidden */ public function testCORSShouldFailIfPasswordLoginIsForbidden(string $method): void { - $this->expectException(\OC\AppFramework\Middleware\Security\Exceptions\SecurityException::class); + $this->expectException(SecurityException::class); $request = new Request( ['server' => [ @@ -268,7 +269,7 @@ class CORSMiddlewareTest extends \Test\TestCase { $this->session->expects($this->once()) ->method('logClientIn') ->with($this->equalTo('user'), $this->equalTo('pass')) - ->will($this->throwException(new \OC\Authentication\Exceptions\PasswordLoginForbiddenException)); + ->willThrowException(new PasswordLoginForbiddenException); $this->reflector->reflect($this->controller, $method); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler, $this->logger); @@ -286,7 +287,7 @@ class CORSMiddlewareTest extends \Test\TestCase { * @dataProvider dataCORSShouldNotAllowCookieAuth */ public function testCORSShouldNotAllowCookieAuth(string $method): void { - $this->expectException(\OC\AppFramework\Middleware\Security\Exceptions\SecurityException::class); + $this->expectException(SecurityException::class); $request = new Request( ['server' => [ diff --git a/tests/lib/AppFramework/Middleware/Security/Mock/CORSMiddlewareController.php b/tests/lib/AppFramework/Middleware/Security/Mock/CORSMiddlewareController.php index 769cba87207..8ab3a48b62e 100644 --- a/tests/lib/AppFramework/Middleware/Security/Mock/CORSMiddlewareController.php +++ b/tests/lib/AppFramework/Middleware/Security/Mock/CORSMiddlewareController.php @@ -9,10 +9,11 @@ declare(strict_types=1); namespace Test\AppFramework\Middleware\Security\Mock; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Attribute\CORS; use OCP\AppFramework\Http\Attribute\PublicPage; -class CORSMiddlewareController extends \OCP\AppFramework\Controller { +class CORSMiddlewareController extends Controller { /** * @CORS */ diff --git a/tests/lib/AppFramework/Middleware/Security/Mock/NormalController.php b/tests/lib/AppFramework/Middleware/Security/Mock/NormalController.php index 99f33be1cc9..4d6778e98b9 100644 --- a/tests/lib/AppFramework/Middleware/Security/Mock/NormalController.php +++ b/tests/lib/AppFramework/Middleware/Security/Mock/NormalController.php @@ -9,7 +9,9 @@ declare(strict_types=1); namespace Test\AppFramework\Middleware\Security\Mock; -class NormalController extends \OCP\AppFramework\Controller { +use OCP\AppFramework\Controller; + +class NormalController extends Controller { public function foo() { } } diff --git a/tests/lib/AppFramework/Middleware/Security/Mock/PasswordConfirmationMiddlewareController.php b/tests/lib/AppFramework/Middleware/Security/Mock/PasswordConfirmationMiddlewareController.php index 02159661ff6..cd1cdaa49ca 100644 --- a/tests/lib/AppFramework/Middleware/Security/Mock/PasswordConfirmationMiddlewareController.php +++ b/tests/lib/AppFramework/Middleware/Security/Mock/PasswordConfirmationMiddlewareController.php @@ -9,9 +9,10 @@ declare(strict_types=1); namespace Test\AppFramework\Middleware\Security\Mock; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired; -class PasswordConfirmationMiddlewareController extends \OCP\AppFramework\Controller { +class PasswordConfirmationMiddlewareController extends Controller { public function testNoAnnotationNorAttribute() { } diff --git a/tests/lib/AppFramework/Middleware/Security/Mock/SecurityMiddlewareController.php b/tests/lib/AppFramework/Middleware/Security/Mock/SecurityMiddlewareController.php index 7d40d587c8e..c8f9878b0c1 100644 --- a/tests/lib/AppFramework/Middleware/Security/Mock/SecurityMiddlewareController.php +++ b/tests/lib/AppFramework/Middleware/Security/Mock/SecurityMiddlewareController.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace Test\AppFramework\Middleware\Security\Mock; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Attribute\ExAppRequired; use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\NoCSRFRequired; @@ -16,7 +17,7 @@ use OCP\AppFramework\Http\Attribute\PublicPage; use OCP\AppFramework\Http\Attribute\StrictCookiesRequired; use OCP\AppFramework\Http\Attribute\SubAdminRequired; -class SecurityMiddlewareController extends \OCP\AppFramework\Controller { +class SecurityMiddlewareController extends Controller { /** * @PublicPage * @NoCSRFRequired diff --git a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php index 3b5861cbba9..183f1aa7477 100644 --- a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php @@ -332,7 +332,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { * @dataProvider dataPublicPage */ public function testCsrfCheck(string $method): void { - $this->expectException(\OC\AppFramework\Middleware\Security\Exceptions\CrossSiteRequestForgeryException::class); + $this->expectException(CrossSiteRequestForgeryException::class); $this->request->expects($this->once()) ->method('passesCSRFCheck') @@ -375,7 +375,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { * @dataProvider dataPublicPage */ public function testFailCsrfCheck(string $method): void { - $this->expectException(\OC\AppFramework\Middleware\Security\Exceptions\CrossSiteRequestForgeryException::class); + $this->expectException(CrossSiteRequestForgeryException::class); $this->request->expects($this->once()) ->method('passesCSRFCheck') diff --git a/tests/lib/AppFramework/OCS/BaseResponseTest.php b/tests/lib/AppFramework/OCS/BaseResponseTest.php index 159459a4aec..a04f517db0b 100644 --- a/tests/lib/AppFramework/OCS/BaseResponseTest.php +++ b/tests/lib/AppFramework/OCS/BaseResponseTest.php @@ -12,9 +12,9 @@ namespace Test\AppFramework\OCS; use OC\AppFramework\OCS\BaseResponse; class ArrayValue implements \JsonSerializable { - private $array; - public function __construct(array $array) { - $this->array = $array; + public function __construct( + private array $array, + ) { } public function jsonSerialize(): mixed { diff --git a/tests/lib/AppFramework/Utility/SimpleContainerTest.php b/tests/lib/AppFramework/Utility/SimpleContainerTest.php index a1cc1e76aeb..93db01d3bc8 100644 --- a/tests/lib/AppFramework/Utility/SimpleContainerTest.php +++ b/tests/lib/AppFramework/Utility/SimpleContainerTest.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Test\AppFramework\Utility; use OC\AppFramework\Utility\SimpleContainer; +use OCP\AppFramework\QueryException; use Psr\Container\NotFoundExceptionInterface; interface TestInterface { @@ -20,42 +21,40 @@ class ClassEmptyConstructor implements IInterfaceConstructor { } class ClassSimpleConstructor implements IInterfaceConstructor { - public $test; - public function __construct($test) { - $this->test = $test; + public function __construct( + public $test, + ) { } } class ClassComplexConstructor { - public $class; - public $test; - public function __construct(ClassSimpleConstructor $class, $test) { - $this->class = $class; - $this->test = $test; + public function __construct( + public ClassSimpleConstructor $class, + public $test, + ) { } } class ClassNullableUntypedConstructorArg { - public $class; - public function __construct($class) { - $this->class = $class; + public function __construct( + public $class, + ) { } } class ClassNullableTypedConstructorArg { - public $class; - public function __construct(?\Some\Class $class) { - $this->class = $class; + public function __construct( + public ?\Some\Class $class, + ) { } } interface IInterfaceConstructor { } class ClassInterfaceConstructor { - public $class; - public $test; - public function __construct(IInterfaceConstructor $class, $test) { - $this->class = $class; - $this->test = $test; + public function __construct( + public IInterfaceConstructor $class, + public $test, + ) { } } @@ -83,7 +82,7 @@ class SimpleContainerTest extends \Test\TestCase { $this->container->query('something really hard', false); $this->fail('Expected `QueryException` exception was not thrown'); } catch (\Throwable $exception) { - $this->assertInstanceOf(\OCP\AppFramework\QueryException::class, $exception); + $this->assertInstanceOf(QueryException::class, $exception); $this->assertInstanceOf(NotFoundExceptionInterface::class, $exception); } } @@ -97,7 +96,7 @@ class SimpleContainerTest extends \Test\TestCase { $this->container->query('something really hard'); $this->fail('Expected `QueryException` exception was not thrown'); } catch (\Throwable $exception) { - $this->assertInstanceOf(\OCP\AppFramework\QueryException::class, $exception); + $this->assertInstanceOf(QueryException::class, $exception); $this->assertInstanceOf(NotFoundExceptionInterface::class, $exception); } } @@ -105,7 +104,7 @@ class SimpleContainerTest extends \Test\TestCase { public function testNotAClass(): void { - $this->expectException(\OCP\AppFramework\QueryException::class); + $this->expectException(QueryException::class); $this->container->query('Test\AppFramework\Utility\TestInterface'); } @@ -214,7 +213,7 @@ class SimpleContainerTest extends \Test\TestCase { public function testConstructorComplexNoTestParameterFound(): void { - $this->expectException(\OCP\AppFramework\QueryException::class); + $this->expectException(QueryException::class); $object = $this->container->query( 'Test\AppFramework\Utility\ClassComplexConstructor' @@ -245,7 +244,7 @@ class SimpleContainerTest extends \Test\TestCase { } public function testQueryUntypedNullable(): void { - $this->expectException(\OCP\AppFramework\QueryException::class); + $this->expectException(QueryException::class); $object = $this->container->query( ClassNullableUntypedConstructorArg::class |