Skip to content

#27500 PHPUnit 8 for module Elasticsearch6 #27712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
namespace Magento\Elasticsearch6\Test\Unit\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\Resolver;

use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeAdapter;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ResolverInterface
as FieldTypeResolver;
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ConverterInterface
as FieldTypeConverterInterface;
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ResolverInterface
as FieldTypeResolver;
use Magento\Elasticsearch6\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\Resolver\DefaultResolver;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use PHPUnit\Framework\TestCase;

/**
* @SuppressWarnings(PHPMD)
*/
class DefaultResolverTest extends \PHPUnit\Framework\TestCase
class DefaultResolverTest extends TestCase
{
/**
* @var DefaultResolver
Expand All @@ -40,7 +41,7 @@ class DefaultResolverTest extends \PHPUnit\Framework\TestCase
*
* @return void
*/
protected function setUp()
protected function setUp(): void
{
$objectManager = new ObjectManagerHelper($this);
$this->fieldTypeResolver = $this->getMockBuilder(FieldTypeResolver::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,37 @@
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Elasticsearch6\Test\Unit\Model\Client;

use Elasticsearch\Client;
use Elasticsearch\Namespaces\IndicesNamespace;
use Magento\AdvancedSearch\Model\Client\ClientInterface as ElasticsearchClient;
use Magento\Elasticsearch\Model\Adapter\FieldMapper\AddDefaultSearchField;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Elasticsearch6\Model\Client\Elasticsearch;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Test elasticsearch client methods
*/
class ElasticsearchTest extends \PHPUnit\Framework\TestCase
class ElasticsearchTest extends TestCase
{
/**
* @var ElasticsearchClient
*/
protected $model;

/**
* @var \Elasticsearch\Client|\PHPUnit_Framework_MockObject_MockObject
* @var Client|MockObject
*/
protected $elasticsearchClientMock;

/**
* @var \Elasticsearch\Namespaces\IndicesNamespace|\PHPUnit_Framework_MockObject_MockObject
* @var IndicesNamespace|MockObject
*/
protected $indicesMock;

Expand All @@ -41,9 +48,9 @@ class ElasticsearchTest extends \PHPUnit\Framework\TestCase
*
* @return void
*/
protected function setUp()
protected function setUp(): void
{
$this->elasticsearchClientMock = $this->getMockBuilder(\Elasticsearch\Client::class)
$this->elasticsearchClientMock = $this->getMockBuilder(Client::class)
->setMethods(
[
'indices',
Expand All @@ -57,7 +64,7 @@ protected function setUp()
)
->disableOriginalConstructor()
->getMock();
$this->indicesMock = $this->getMockBuilder(\Elasticsearch\Namespaces\IndicesNamespace::class)
$this->indicesMock = $this->getMockBuilder(IndicesNamespace::class)
->setMethods(
[
'exists',
Expand Down Expand Up @@ -97,11 +104,9 @@ protected function setUp()
);
}

/**
* @expectedException \Magento\Framework\Exception\LocalizedException
*/
public function testConstructorOptionsException()
{
$this->expectException('Magento\Framework\Exception\LocalizedException');
$result = $this->objectManager->getObject(
Elasticsearch::class,
[
Expand All @@ -117,7 +122,7 @@ public function testConstructorOptionsException()
public function testConstructorWithOptions()
{
$result = $this->objectManager->getObject(
\Magento\Elasticsearch6\Model\Client\Elasticsearch::class,
Elasticsearch::class,
[
'options' => $this->getOptions()
]
Expand All @@ -130,7 +135,7 @@ public function testConstructorWithOptions()
*
* @param array $options
* @param string $expectedResult
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
* @throws \ReflectionException
* @dataProvider getOptionsDataProvider
*/
Expand Down Expand Up @@ -221,7 +226,7 @@ public function testTestConnectionFalse()
public function testTestConnectionPing()
{
$this->model = $this->objectManager->getObject(
\Magento\Elasticsearch6\Model\Client\Elasticsearch::class,
Elasticsearch::class,
[
'options' => $this->getEmptyIndexOption(),
'elasticsearchClient' => $this->elasticsearchClientMock
Expand Down Expand Up @@ -391,10 +396,10 @@ public function testGetAlias()

/**
* Test createIndexIfNotExists() method, case when operation fails
* @expectedException \Exception
*/
public function testCreateIndexFailure()
{
$this->expectException('Exception');
$this->indicesMock->expects($this->once())
->method('create')
->with(
Expand Down Expand Up @@ -478,10 +483,10 @@ public function testAddFieldsMapping()

/**
* Test testAddFieldsMapping() method
* @expectedException \Exception
*/
public function testAddFieldsMappingFailure()
{
$this->expectException('Exception');
$this->indicesMock->expects($this->once())
->method('putMapping')
->with(
Expand Down Expand Up @@ -568,10 +573,10 @@ public function testDeleteMapping()

/**
* Test deleteMapping() method
* @expectedException \Exception
*/
public function testDeleteMappingFailure()
{
$this->expectException('Exception');
$this->indicesMock->expects($this->once())
->method('deleteMapping')
->with(
Expand Down