forked from magento/ece-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MCLOUD-5732: Add ECE-Tools warning about MySQL search being used (mag…
- Loading branch information
1 parent
c408c0a
commit 7e66df4
Showing
9 changed files
with
170 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
*/ | ||
class SearchEngine | ||
{ | ||
public const ENGINE_MYSQL = 'mysql'; | ||
|
||
/** | ||
* @var Environment | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MagentoCloud\Config\Validator\Deploy; | ||
|
||
use Magento\MagentoCloud\Config\SearchEngine; | ||
use Magento\MagentoCloud\Config\Validator; | ||
use Magento\MagentoCloud\Config\ValidatorInterface; | ||
|
||
/** | ||
* Validates if a deprecated MySQL search engine is used. | ||
*/ | ||
class DeprecatedSearchEngine implements ValidatorInterface | ||
{ | ||
/** | ||
* @var Validator\ResultFactory | ||
*/ | ||
private $resultFactory; | ||
|
||
/** | ||
* @var SearchEngine | ||
*/ | ||
private $searchEngine; | ||
|
||
/** | ||
* @param Validator\ResultFactory $resultFactory | ||
* @param SearchEngine $searchEngine | ||
*/ | ||
public function __construct(Validator\ResultFactory $resultFactory, SearchEngine $searchEngine) | ||
{ | ||
$this->resultFactory = $resultFactory; | ||
$this->searchEngine = $searchEngine; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function validate(): Validator\ResultInterface | ||
{ | ||
if (SearchEngine::ENGINE_MYSQL === $this->searchEngine->getName()) { | ||
return $this->resultFactory->error( | ||
'The MySQL search configuration option is deprecated. Use Elasticsearch instead.' | ||
); | ||
} | ||
|
||
return $this->resultFactory->success(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MagentoCloud\Config; | ||
|
||
use Magento\MagentoCloud\App\GenericException; | ||
|
||
/** | ||
* The generic Validator exception. | ||
*/ | ||
class ValidatorException extends GenericException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/Test/Unit/Config/Validator/Deploy/DeprecatedSearchEngineTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MagentoCloud\Test\Unit\Config\Validator\Deploy; | ||
|
||
use Magento\MagentoCloud\Config\SearchEngine; | ||
use Magento\MagentoCloud\Config\Validator\Deploy\DeprecatedSearchEngine; | ||
use Magento\MagentoCloud\Config\Validator\Result\Error; | ||
use Magento\MagentoCloud\Config\Validator\Result\Success; | ||
use Magento\MagentoCloud\Config\Validator\ResultFactory; | ||
use Magento\MagentoCloud\Config\ValidatorException; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @see DeprecatedSearchEngine | ||
*/ | ||
class DeprecatedSearchEngineTest extends TestCase | ||
{ | ||
/** | ||
* @var DeprecatedSearchEngine | ||
*/ | ||
private $validator; | ||
|
||
/** | ||
* @var ResultFactory|MockObject | ||
*/ | ||
private $resultFactoryMock; | ||
|
||
/** | ||
* @var SearchEngine|MockObject | ||
*/ | ||
private $searchEngineMock; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->resultFactoryMock = $this->createMock(ResultFactory::class); | ||
$this->searchEngineMock = $this->createMock(SearchEngine::class); | ||
|
||
$this->validator = new DeprecatedSearchEngine( | ||
$this->resultFactoryMock, | ||
$this->searchEngineMock | ||
); | ||
} | ||
|
||
/** | ||
* @throws ValidatorException | ||
*/ | ||
public function testValidate(): void | ||
{ | ||
$this->searchEngineMock->method('getName') | ||
->willReturn(SearchEngine::ENGINE_MYSQL); | ||
$this->resultFactoryMock->expects($this->once()) | ||
->method('error') | ||
->with( | ||
'The MySQL search configuration option is deprecated. Use Elasticsearch instead.' | ||
)->willReturn(new Error('Some error')); | ||
|
||
$this->validator->validate(); | ||
} | ||
|
||
/** | ||
* @throws ValidatorException | ||
*/ | ||
public function testValidateWithError(): void | ||
{ | ||
$this->searchEngineMock->method('getName') | ||
->willReturn('es'); | ||
$this->resultFactoryMock->expects($this->once()) | ||
->method('success') | ||
->willReturn(new Success()); | ||
|
||
$this->validator->validate(); | ||
} | ||
} |