Skip to content

Commit

Permalink
chore(tests): Fix Router test by mocking AppManager methods correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Sep 13, 2024
1 parent 76f2bc0 commit 7a16d01
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/lib/Route/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCP\Diagnostics\IEventLogger;
use OCP\IConfig;
use OCP\IRequest;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Test\TestCase;
Expand All @@ -26,6 +27,8 @@
*/
class RouterTest extends TestCase {
private Router $router;
private IAppManager&MockObject $appManager;

protected function setUp(): void {
parent::setUp();
/** @var LoggerInterface $logger */
Expand All @@ -36,13 +39,16 @@ function (string $message, array $data) {
$this->fail('Unexpected info log: '.(string)($data['exception'] ?? $message));
}
);

$this->appManager = $this->createMock(IAppManager::class);

$this->router = new Router(
$logger,
$this->createMock(IRequest::class),
$this->createMock(IConfig::class),
$this->createMock(IEventLogger::class),
$this->createMock(ContainerInterface::class),
$this->createMock(IAppManager::class),
$this->appManager,
);
}

Expand All @@ -51,6 +57,12 @@ public function testHeartbeat(): void {
}

public function testGenerateConsecutively(): void {
$this->appManager->expects(self::atLeastOnce())
->method('cleanAppId')
->willReturnArgument(0);
$this->appManager->expects(self::atLeastOnce())
->method('getAppPath')
->willReturnCallback(fn (string $appid): string => \OC::$SERVERROOT . '/apps/' . $appid);

$this->assertEquals('/index.php/apps/files/', $this->router->generate('files.view.index'));

Expand Down

0 comments on commit 7a16d01

Please sign in to comment.