Skip to content

Commit 218c46f

Browse files
author
ogorkun
committed
MC-38984: Merge all ReCaptcha web API coverage stories
1 parent 585ab8f commit 218c46f

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

ReCaptchaWebapiGraphQl/Plugin/GraphQlValidator.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
namespace Magento\ReCaptchaWebapiGraphQl\Plugin;
99

1010
use Magento\Framework\App\Request\Http as HttpRequest;
11-
use Magento\Framework\GraphQl\Config\ConfigElementInterface;
12-
use Magento\Framework\GraphQl\Config\Element\TypeInterface;
1311
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1412
use Magento\Framework\GraphQl\Query\ResolverInterface;
15-
use Magento\Framework\GraphQl\Schema\Type\Output\ElementMapper\Formatter\Fields;
1613
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1714
use Magento\ReCaptchaValidationApi\Api\ValidatorInterface;
1815
use Magento\ReCaptchaWebapiApi\Api\WebapiValidationConfigProviderInterface;

ReCaptchaWebapiGraphQl/Test/Unit/Plugin/GraphQlValidatorTest.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
namespace Magento\ReCaptchaWebapiGraphQl\Test\Unit\Plugin;
99

10+
use GraphQL\Language\AST\OperationDefinitionNode;
1011
use Magento\Framework\App\Request\Http;
1112
use Magento\Framework\GraphQl\Config\Element\Field;
12-
use Magento\Framework\GraphQl\Config\Element\TypeInterface;
1313
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
14-
use Magento\Framework\GraphQl\Schema\Type\Output\ElementMapper\Formatter\Fields;
14+
use Magento\Framework\GraphQl\Query\ResolverInterface;
1515
use Magento\Framework\Validation\ValidationResult;
1616
use Magento\ReCaptchaValidationApi\Api\Data\ValidationConfigInterface;
1717
use Magento\ReCaptchaValidationApi\Api\ValidatorInterface;
@@ -21,6 +21,7 @@
2121
use Magento\ReCaptchaWebapiGraphQl\Plugin\GraphQlValidator;
2222
use PHPUnit\Framework\MockObject\MockObject;
2323
use PHPUnit\Framework\TestCase;
24+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
2425

2526
class GraphQlValidatorTest extends TestCase
2627
{
@@ -82,22 +83,20 @@ public function getPluginCases(): array
8283
*/
8384
public function testPlugin(bool $isMutation, bool $configFound, bool $isValid, bool $expectException): void
8485
{
85-
$configMock = $this->getMockForAbstractClass(TypeInterface::class);
8686
//Emulating query type
87-
$configMock->method('getName')->willReturn($isMutation ? 'Mutation' : 'Query');
87+
$infoMock = $this->createMock(ResolveInfo::class);
88+
$infoMock->operation = $this->createMock(OperationDefinitionNode::class);
89+
$infoMock->operation->operation = $isMutation ? 'mutation' : 'query';
8890
//Emulating endpoint info
8991
$fieldMock = $this->createMock(Field::class);
9092
$fieldMock->method('getResolver')->willReturn('\\' . ($class = 'Class'));
9193
$fieldMock->method('getName')->willReturn($name = 'name');
92-
$configMock->method('getFields')
93-
->willReturn([$fieldMock, $fieldMock]);
9494
$this->endpointFactoryMock->method('create')
9595
->with(['class' => $class, 'method' => 'resolve', 'name' => $name])
9696
->willReturn($this->createMock(Endpoint::class));
9797
//Emulating config found
9898
$this->configProviderMock->method('getConfigFor')
99-
->willReturnOnConsecutiveCalls(
100-
null,
99+
->willReturn(
101100
$configFound ? $this->getMockForAbstractClass(ValidationConfigInterface::class) : null
102101
);
103102
//Emulating validation result
@@ -109,6 +108,11 @@ public function testPlugin(bool $isMutation, bool $configFound, bool $isValid, b
109108
$this->expectException(GraphQlInputException::class);
110109
}
111110

112-
$this->model->beforeFormat($this->createMock(Fields::class), $configMock);
111+
$this->model->beforeResolve(
112+
$this->getMockForAbstractClass(ResolverInterface::class),
113+
$fieldMock,
114+
null,
115+
$infoMock
116+
);
113117
}
114118
}

0 commit comments

Comments
 (0)