DataFingerprintTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @author Roeland Jago Douma <rullzer@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Tests\Core\Command\Maintenance;
  22. use OC\Core\Command\Maintenance\DataFingerprint;
  23. use OCP\AppFramework\Utility\ITimeFactory;
  24. use OCP\IConfig;
  25. use Symfony\Component\Console\Input\InputInterface;
  26. use Symfony\Component\Console\Output\OutputInterface;
  27. use Test\TestCase;
  28. class DataFingerprintTest extends TestCase {
  29. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  30. protected $config;
  31. /** @var \PHPUnit\Framework\MockObject\MockObject */
  32. protected $consoleInput;
  33. /** @var \PHPUnit\Framework\MockObject\MockObject */
  34. protected $consoleOutput;
  35. /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
  36. protected $timeFactory;
  37. /** @var \Symfony\Component\Console\Command\Command */
  38. protected $command;
  39. protected function setUp(): void {
  40. parent::setUp();
  41. $this->config = $this->getMockBuilder(IConfig::class)->getMock();
  42. $this->timeFactory = $this->getMockBuilder(ITimeFactory::class)->getMock();
  43. $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
  44. $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
  45. /** @var \OCP\IConfig $config */
  46. $this->command = new DataFingerprint($this->config, $this->timeFactory);
  47. }
  48. public function testSetFingerPrint() {
  49. $this->timeFactory->expects($this->once())
  50. ->method('getTime')
  51. ->willReturn(42);
  52. $this->config->expects($this->once())
  53. ->method('setSystemValue')
  54. ->with('data-fingerprint', md5(42));
  55. self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
  56. }
  57. }