Skip to content

Commit

Permalink
Merge pull request #1 from magento-troll/imported-magento-catalog-sto…
Browse files Browse the repository at this point in the history
…refront-397

[Imported] Story 323 sf tests
  • Loading branch information
vgoncharenko authored Oct 20, 2020
2 parents 6588eb6 + 98ae3a0 commit 162d6fe
Showing 1 changed file with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use Magento\CatalogStorefront\Model\Storage\Client\DataDefinitionInterface;
use Magento\CatalogStorefront\Model\Storage\State;
use Magento\Framework\App\ResourceConnection;
use Magento\Indexer\Model\Indexer;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
use Magento\TestFramework\Workaround\ConsumerInvoker;
use Magento\TestFramework\Helper\CompareArraysRecursively;
use PHPUnit\Framework\TestResult;

/**
* Test abstract class for store front tests
Expand All @@ -30,6 +32,16 @@ abstract class StorefrontTestsAbstract extends TestCase
'catalog_data_exporter_products'
];

/**
* @var array
*/
private const QUEUES = [
'catalog.category.export.queue',
'catalog.product.export.queue',
'storefront.catalog.product.connector',
'storefront.catalog.category.connector',
];

/**
* @var CompareArraysRecursively
*/
Expand All @@ -52,6 +64,7 @@ protected function tearDown(): void
parent::tearDown();
$this->clearCatalogStorage();
$this->cleanFeeds();
$this->cleanOldMessages();
}

/**
Expand Down Expand Up @@ -102,15 +115,60 @@ private function cleanFeeds(): void
}
}

/**
* Clean old messages from rabbitmq
*
* @return void
*/
private function cleanOldMessages(): void
{
if ($this->isSoap()) {
return;
}

/** @var \Magento\Framework\Amqp\Config $amqpConfig */
$amqpConfig = Bootstrap::getObjectManager()
->get(\Magento\Framework\Amqp\Config::class);

foreach (self::QUEUES as $queue) {
$amqpConfig->getChannel()->queue_purge($queue);
}
}

/**
* Run tests and clean old messages before running other tests
*
* @param TestResult|null $result
* @return TestResult
*/
public function run(TestResult $result = null): TestResult
{
$this->cleanOldMessages();
$this->resetIndexerToOnSave();
return parent::run($result);
}

/**
* Runs consumers before test execution
*
* @throws \Throwable
*/
protected function runTest()
{
$this->runConsumers();
parent::runTest();
if (!$this->isSoap()) {
$this->runConsumers();
parent::runTest();
}
}

/**
* Check if it is SOAP request
*
* @return bool
*/
private function isSoap(): bool
{
return TESTS_WEB_API_ADAPTER === 'soap';
}

/**
Expand All @@ -124,6 +182,19 @@ public function runConsumers(array $consumers = []) : void
$consumerInvoker->invoke($consumers);
}

/**
* Resetting indexer to 'on save' mode
*
* @return void
*/
private function resetIndexerToOnSave(): void
{
$indexer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(Indexer::class);
$indexer->load('catalog_data_exporter_products');
$indexer->setScheduled(false);
}

/**
* Compare expected and actual results
*
Expand Down

0 comments on commit 162d6fe

Please sign in to comment.