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 + ); + } +}