-
Notifications
You must be signed in to change notification settings - Fork 9.4k
magento/magento2#: Remove a redundant getMappedNums from a loop #27939
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
magento-engcom-team
merged 11 commits into
magento:2.4-develop
from
atwixfirster:framework-EnumLookup
Sep 30, 2020
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1c87648
magento/magento2#: Remove a redundant getMappedNums from a loop
atwixfirster cd9e834
magento/magento2#: Remove a redundant getMappedNums from a loop
c68c447
Merge branch '2.4-develop' into framework-EnumLookup
atwixfirster d2bc662
Merge branch '2.4-develop' into framework-EnumLookup
atwixfirster 862609f
Merge branch '2.4-develop' into framework-EnumLookup
engcom-Echo 740ce6b
minor change
engcom-Echo e113e37
minor change
engcom-Echo 814cf2b
Revert exception
d240573
Merge branch '2.4-develop' into framework-EnumLookup
engcom-Echo 1bb4814
return to equal comparison
engcom-Echo 033401b
Merge branch '2.4-develop' into framework-EnumLookup
engcom-Echo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
154 changes: 154 additions & 0 deletions
154
lib/internal/Magento/Framework/GraphQl/Test/Unit/Query/EnumLookupTest.php
This file contains hidden or 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,154 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Framework\GraphQl\Test\Unit\Query; | ||
|
||
use Magento\Framework\Config\DataInterface; | ||
use Magento\Framework\GraphQl\Config\ConfigElementFactoryInterface; | ||
use Magento\Framework\GraphQl\Config\Element\Enum; | ||
use Magento\Framework\GraphQl\Config\Element\EnumValue; | ||
use Magento\Framework\GraphQl\ConfigInterface; | ||
use Magento\Framework\GraphQl\Query\EnumLookup; | ||
use Magento\Framework\GraphQl\Query\Fields as QueryFields; | ||
use Magento\Framework\GraphQl\Schema\Type\Enum\DataMapperInterface; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Unit test for \Magento\Framework\GraphQl\Query\EnumLookup | ||
*/ | ||
class EnumLookupTest extends TestCase | ||
{ | ||
private const ENUM_NAME = 'SubscriptionStatusesEnum'; | ||
|
||
/** | ||
* @var DataInterface|MockObject | ||
*/ | ||
private $configDataMock; | ||
|
||
/** | ||
* @var ConfigElementFactoryInterface|MockObject | ||
*/ | ||
private $configElementFactoryMock; | ||
|
||
/** | ||
* @var DataMapperInterface|MockObject | ||
*/ | ||
private $enumDataMapperMock; | ||
|
||
/** | ||
* Testable Object | ||
* | ||
* @var EnumLookup | ||
*/ | ||
private $enumLookup; | ||
|
||
/** | ||
* @var Enum|MockObject | ||
*/ | ||
private $enumMock; | ||
|
||
/** | ||
* Object Manager Instance | ||
* | ||
* @var ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var QueryFields|MockObject | ||
*/ | ||
private $queryFieldsMock; | ||
|
||
/** | ||
* @var ConfigInterface|MockObject | ||
*/ | ||
private $typeConfigMock; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $map = []; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $values = []; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->objectManager = new ObjectManager($this); | ||
|
||
$this->map = [ | ||
self::ENUM_NAME => [ | ||
'subscribed' => '1', | ||
'not_active' => '2', | ||
'unsubscribed' => '3', | ||
'unconfirmed' => '4', | ||
] | ||
]; | ||
|
||
$this->values = [ | ||
'NOT_ACTIVE' => new EnumValue('not_active', 'NOT_ACTIVE'), | ||
'SUBSCRIBED' => new EnumValue('subscribed', 'SUBSCRIBED'), | ||
'UNSUBSCRIBED' => new EnumValue('unsubscribed', 'UNSUBSCRIBED'), | ||
'UNCONFIRMED' => new EnumValue('unconfirmed', 'UNCONFIRMED'), | ||
]; | ||
|
||
$this->enumMock = $this->getMockBuilder(Enum::class) | ||
->setConstructorArgs( | ||
[ | ||
self::ENUM_NAME, | ||
$this->values, | ||
'Subscription statuses', | ||
] | ||
) | ||
->getMock(); | ||
|
||
$this->enumDataMapperMock = $this->createMock(DataMapperInterface::class); | ||
$this->configDataMock = $this->createMock(DataInterface::class); | ||
$this->configElementFactoryMock = $this->createMock(ConfigElementFactoryInterface::class); | ||
$this->queryFieldsMock = $this->createMock(QueryFields::class); | ||
$this->typeConfigMock = $this->createMock(ConfigInterface::class); | ||
|
||
$this->enumLookup = $this->objectManager->getObject( | ||
EnumLookup::class, | ||
[ | ||
'typeConfig' => $this->typeConfigMock, | ||
'enumDataMapper' => $this->enumDataMapperMock, | ||
] | ||
); | ||
} | ||
|
||
public function testGetEnumValueFromField() | ||
{ | ||
$enumName = self::ENUM_NAME; | ||
$fieldValue = '1'; | ||
|
||
$this->enumDataMapperMock | ||
->expects($this->once()) | ||
->method('getMappedEnums') | ||
->willReturn($this->map[$enumName]); | ||
|
||
$this->typeConfigMock | ||
->expects($this->once()) | ||
->method('getConfigElement') | ||
->willReturn($this->enumMock); | ||
|
||
$this->enumMock | ||
->expects($this->once()) | ||
->method('getValues') | ||
->willReturn($this->values); | ||
|
||
$this->assertEquals( | ||
'SUBSCRIBED', | ||
$this->enumLookup->getEnumValueFromField($enumName, $fieldValue) | ||
); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.