From 62d0b4e9a315c474d56188607917b95cb3cc2b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 2 Oct 2025 11:24:27 +0200 Subject: [PATCH] fix: Add unit test for occ app:update command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In preparation for changes in the process, add a test for the command. Signed-off-by: Côme Chilliet --- tests/Core/Command/App/UpdateTest.php | 97 +++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 tests/Core/Command/App/UpdateTest.php diff --git a/tests/Core/Command/App/UpdateTest.php b/tests/Core/Command/App/UpdateTest.php new file mode 100644 index 00000000000..f095d2590ba --- /dev/null +++ b/tests/Core/Command/App/UpdateTest.php @@ -0,0 +1,97 @@ +appManager = $this->createMock(IAppManager::class); + $this->installer = $this->createMock(Installer::class); + $this->logger = $this->createMock(LoggerInterface::class); + $this->inputInterface = $this->createMock(InputInterface::class); + $this->outputInterface = $this->createMock(OutputInterface::class); + + $this->command = new Update( + $this->appManager, + $this->installer, + $this->logger, + ); + } + + public function testAppUpdateNoUpdatesFound(): void { + $this->inputInterface->expects(self::once()) + ->method('getArgument') + ->with('app-id') + ->willReturn('fakeid'); + + $this->outputInterface->expects(self::once()) + ->method('writeln') + ->with('fakeid is up-to-date or no updates could be found'); + + $this->assertEquals(0, self::invokePrivate($this->command, 'execute', [$this->inputInterface, $this->outputInterface])); + } + + public function testAppUpdate(): void { + $this->inputInterface->expects(self::once()) + ->method('getArgument') + ->with('app-id') + ->willReturn('fakeid'); + $this->inputInterface->expects(self::any()) + ->method('getOption') + ->willReturnMap([ + ['allow-unstable', false], + ['showonly', false], + ]); + + $this->installer->expects(self::once()) + ->method('isUpdateAvailable') + ->willReturn('fakeversion'); + $this->installer->expects(self::once()) + ->method('updateAppstoreApp') + ->with('fakeid', false) + ->willReturn(true); + + $output = []; + $this->outputInterface->expects(self::any()) + ->method('writeln') + ->willReturnCallback( + function (string $line) use (&$output) { + $output[] = $line; + } + ); + + $this->assertEquals(0, self::invokePrivate($this->command, 'execute', [$this->inputInterface, $this->outputInterface])); + $this->assertEquals( + [ + 'fakeid new version available: fakeversion', + 'fakeid updated', + ], + $output + ); + } +}