shareManager = $this->createMock(IManager::class); $this->l = $this->createMock(IL10N::class); $this->l->method('t')->willReturnArgument(0); $this->middleware = new OCSShareAPIMiddleware($this->shareManager, $this->l); } public static function dataBeforeController() { return [ [ Controller::class, false, false ], [ Controller::class, true, false ], [ OCSController::class, false, false ], [ OCSController::class, true, false ], [ ShareAPIController::class, false, true ], [ ShareAPIController::class, true, false ], ]; } #[\PHPUnit\Framework\Attributes\DataProvider('dataBeforeController')] public function testBeforeController(string $controllerClass, bool $enabled, bool $exception): void { $controller = $this->createMock($controllerClass); $this->shareManager->method('shareApiEnabled')->willReturn($enabled); try { $this->middleware->beforeController($controller, 'foo'); $this->assertFalse($exception); } catch (OCSNotFoundException $e) { $this->assertTrue($exception); } } public function dataAfterController() { return [ [ Controller::class, ], [ OCSController::class, ], [ ShareAPIController::class, ], ]; } #[\PHPUnit\Framework\Attributes\DataProvider('dataAfterController')] public function testAfterController(string $controllerClass): void { $controller = $this->createMock($controllerClass); if ($controller instanceof ShareAPIController) { $controller->expects($this->once())->method('cleanup'); } $response = $this->getMockBuilder('OCP\AppFramework\Http\Response') ->disableOriginalConstructor() ->getMock(); $this->middleware->afterController($controller, 'foo', $response); $this->addToAssertionCount(1); } }