DataFingerprintTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace Tests\Core\Command\Maintenance;
  8. use OC\Core\Command\Maintenance\DataFingerprint;
  9. use OCP\AppFramework\Utility\ITimeFactory;
  10. use OCP\IConfig;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. use Test\TestCase;
  14. class DataFingerprintTest extends TestCase {
  15. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  16. protected $config;
  17. /** @var \PHPUnit\Framework\MockObject\MockObject */
  18. protected $consoleInput;
  19. /** @var \PHPUnit\Framework\MockObject\MockObject */
  20. protected $consoleOutput;
  21. /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
  22. protected $timeFactory;
  23. /** @var \Symfony\Component\Console\Command\Command */
  24. protected $command;
  25. protected function setUp(): void {
  26. parent::setUp();
  27. $this->config = $this->getMockBuilder(IConfig::class)->getMock();
  28. $this->timeFactory = $this->getMockBuilder(ITimeFactory::class)->getMock();
  29. $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
  30. $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
  31. /** @var \OCP\IConfig $config */
  32. $this->command = new DataFingerprint($this->config, $this->timeFactory);
  33. }
  34. public function testSetFingerPrint(): void {
  35. $this->timeFactory->expects($this->once())
  36. ->method('getTime')
  37. ->willReturn(42);
  38. $this->config->expects($this->once())
  39. ->method('setSystemValue')
  40. ->with('data-fingerprint', md5(42));
  41. self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
  42. }
  43. }