IndexerResetStateCommandTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Indexer\Test\Unit\Console\Command;
  7. use Magento\Backend\App\Area\FrontNameResolver;
  8. use Symfony\Component\Console\Tester\CommandTester;
  9. use Magento\Indexer\Console\Command\IndexerResetStateCommand;
  10. class IndexerResetStateCommandTest extends AbstractIndexerCommandCommonSetup
  11. {
  12. /**
  13. * Command being tested
  14. *
  15. * @var IndexerResetStateCommand
  16. */
  17. private $command;
  18. protected function setUp()
  19. {
  20. parent::setUp();
  21. $this->stateMock->expects($this->once())->method('setAreaCode')->with(FrontNameResolver::AREA_CODE);
  22. }
  23. public function testExecute()
  24. {
  25. $this->configureAdminArea();
  26. $indexerOne = $this->getIndexerMock(
  27. ['getState'],
  28. ['indexer_id' => 'indexer_1', 'title' => 'Title_indexerOne']
  29. );
  30. $this->initIndexerCollectionByItems([$indexerOne]);
  31. $stateMock = $this->createMock(\Magento\Indexer\Model\Indexer\State::class);
  32. $stateMock->expects($this->exactly(1))
  33. ->method('setStatus')
  34. ->with(\Magento\Framework\Indexer\StateInterface::STATUS_INVALID)
  35. ->will($this->returnSelf());
  36. $stateMock->expects($this->exactly(1))
  37. ->method('save');
  38. $indexerOne->expects($this->once())
  39. ->method('getState')
  40. ->willReturn($stateMock);
  41. $this->command = new IndexerResetStateCommand($this->objectManagerFactory);
  42. $commandTester = new CommandTester($this->command);
  43. $commandTester->execute([]);
  44. $actualValue = $commandTester->getDisplay();
  45. $this->assertSame(sprintf('Title_indexerOne indexer has been invalidated.') . PHP_EOL, $actualValue);
  46. }
  47. }