Skip to content

Commit 5844eab

Browse files
committed
MAGE-1226: add some command tests
1 parent 197d68e commit 5844eab

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

Test/Integration/Indexing/Category/CategoriesIndexingTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Algolia\AlgoliaSearch\Test\Integration\Indexing\Category;
44

5+
use Algolia\AlgoliaSearch\Console\Command\Indexer\IndexCategoriesCommand;
56
use Algolia\AlgoliaSearch\Service\Category\BatchQueueProcessor as CategoryBatchQueueProcessor;
67
use Algolia\AlgoliaSearch\Test\Integration\Indexing\IndexingTestCase;
78

@@ -52,4 +53,10 @@ public function testDefaultIndexableAttributes()
5253
$extraAttributes = implode(', ', array_keys($hit));
5354
$this->assertTrue(empty($hit), 'Extra category attributes (' . $extraAttributes . ') are indexed and should not be.');
5455
}
56+
57+
public function testIndexingCategoriesCommand()
58+
{
59+
$indexCategoriesCmd = $this->objectManager->get(IndexCategoriesCommand::class);
60+
$this->processCommandTest($indexCategoriesCmd,'categories', $this->assertValues->expectedCategory);
61+
}
5562
}

Test/Integration/Indexing/IndexingTestCase.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
namespace Algolia\AlgoliaSearch\Test\Integration\Indexing;
44

55
use Algolia\AlgoliaSearch\Api\Processor\BatchQueueProcessorInterface;
6+
use Algolia\AlgoliaSearch\Console\Command\Indexer\AbstractIndexerCommand;
67
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
78
use Algolia\AlgoliaSearch\Test\Integration\TestCase;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
811

912
abstract class IndexingTestCase extends TestCase
1013
{
@@ -23,11 +26,35 @@ protected function processTest(
2326
$this->algoliaHelper->clearIndex($this->indexPrefix . 'default_' . $indexSuffix);
2427

2528
$batchQueueProcessor->processBatch(1);
29+
$this->algoliaHelper->waitLastTask();
30+
31+
$this->assertNumberofHits($indexSuffix, $expectedNbHits);
32+
}
33+
34+
protected function processCommandTest(
35+
AbstractIndexerCommand $command,
36+
$indexSuffix,
37+
$expectedNbHits
38+
) {
39+
$this->algoliaHelper->clearIndex($this->indexPrefix . 'default_' . $indexSuffix);
2640

41+
$this->mockProperty($command, 'output', OutputInterface::class);
42+
$this->invokeMethod(
43+
$command,
44+
'execute',
45+
[
46+
$this->createMock(InputInterface::class),
47+
$this->createMock(OutputInterface::class)
48+
]
49+
);
2750
$this->algoliaHelper->waitLastTask();
2851

29-
$resultsDefault = $this->algoliaHelper->query($this->indexPrefix . 'default_' . $indexSuffix, '', []);
52+
$this->assertNumberofHits($indexSuffix, $expectedNbHits);
53+
}
3054

55+
protected function assertNumberofHits($indexSuffix, $expectedNbHits)
56+
{
57+
$resultsDefault = $this->algoliaHelper->query($this->indexPrefix . 'default_' . $indexSuffix, '', []);
3158
$this->assertEquals($expectedNbHits, $resultsDefault['results'][0]['nbHits']);
3259
}
3360

Test/Integration/Indexing/Page/PagesIndexingTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Algolia\AlgoliaSearch\Test\Integration\Indexing\Page;
44

5+
use Algolia\AlgoliaSearch\Console\Command\Indexer\IndexPagesCommand;
56
use Algolia\AlgoliaSearch\Helper\Entity\PageHelper;
67
use Algolia\AlgoliaSearch\Service\Page\BatchQueueProcessor as PageBatchQueueProcessor;
78
use Algolia\AlgoliaSearch\Test\Integration\Indexing\IndexingTestCase;
@@ -147,4 +148,15 @@ public function testUtf8()
147148

148149
$testPage->delete();
149150
}
151+
152+
public function testIndexingPagesCommand()
153+
{
154+
$this->setConfig(
155+
'algoliasearch_autocomplete/autocomplete/excluded_pages',
156+
$this->getSerializer()->serialize([])
157+
);
158+
159+
$indexPagesCmd = $this->objectManager->get(IndexPagesCommand::class);
160+
$this->processCommandTest($indexPagesCmd, 'pages', $this->assertValues->expectedPages);
161+
}
150162
}

Test/Integration/Indexing/Product/ProductsIndexingTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Algolia\AlgoliaSearch\Test\Integration\Indexing\Product;
44

5+
use Algolia\AlgoliaSearch\Console\Command\Indexer\IndexProductsCommand;
56
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
67
use Algolia\AlgoliaSearch\Exceptions\ExceededRetriesException;
78
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
@@ -86,6 +87,16 @@ public function testDefaultIndexableAttributes()
8687
$this->assertEmpty($hit, 'Extra products attributes (' . $extraAttributes . ') are indexed and should not be.');
8788
}
8889

90+
public function testIndexingProductsCommand()
91+
{
92+
$this->setConfig(ConfigHelper::SHOW_OUT_OF_STOCK, 0);
93+
94+
$this->updateStockItem(self::OUT_OF_STOCK_PRODUCT_SKU, false);
95+
96+
$indexProductsCmd = $this->objectManager->get(IndexProductsCommand::class);
97+
$this->processCommandTest($indexProductsCmd, 'products', $this->assertValues->productsOnStockCount);
98+
}
99+
89100
private function getValidTestProduct()
90101
{
91102
if (!$this->testProductId) {

0 commit comments

Comments
 (0)