7
7
8
8
namespace Magento \ReCaptchaWebapiGraphQl \Test \Unit \Plugin ;
9
9
10
+ use GraphQL \Language \AST \OperationDefinitionNode ;
10
11
use Magento \Framework \App \Request \Http ;
11
12
use Magento \Framework \GraphQl \Config \Element \Field ;
12
- use Magento \Framework \GraphQl \Config \Element \TypeInterface ;
13
13
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
14
- use Magento \Framework \GraphQl \Schema \ Type \ Output \ ElementMapper \ Formatter \ Fields ;
14
+ use Magento \Framework \GraphQl \Query \ ResolverInterface ;
15
15
use Magento \Framework \Validation \ValidationResult ;
16
16
use Magento \ReCaptchaValidationApi \Api \Data \ValidationConfigInterface ;
17
17
use Magento \ReCaptchaValidationApi \Api \ValidatorInterface ;
21
21
use Magento \ReCaptchaWebapiGraphQl \Plugin \GraphQlValidator ;
22
22
use PHPUnit \Framework \MockObject \MockObject ;
23
23
use PHPUnit \Framework \TestCase ;
24
+ use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
24
25
25
26
class GraphQlValidatorTest extends TestCase
26
27
{
@@ -82,22 +83,20 @@ public function getPluginCases(): array
82
83
*/
83
84
public function testPlugin (bool $ isMutation , bool $ configFound , bool $ isValid , bool $ expectException ): void
84
85
{
85
- $ configMock = $ this ->getMockForAbstractClass (TypeInterface::class);
86
86
//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 ' ;
88
90
//Emulating endpoint info
89
91
$ fieldMock = $ this ->createMock (Field::class);
90
92
$ fieldMock ->method ('getResolver ' )->willReturn ('\\' . ($ class = 'Class ' ));
91
93
$ fieldMock ->method ('getName ' )->willReturn ($ name = 'name ' );
92
- $ configMock ->method ('getFields ' )
93
- ->willReturn ([$ fieldMock , $ fieldMock ]);
94
94
$ this ->endpointFactoryMock ->method ('create ' )
95
95
->with (['class ' => $ class , 'method ' => 'resolve ' , 'name ' => $ name ])
96
96
->willReturn ($ this ->createMock (Endpoint::class));
97
97
//Emulating config found
98
98
$ this ->configProviderMock ->method ('getConfigFor ' )
99
- ->willReturnOnConsecutiveCalls (
100
- null ,
99
+ ->willReturn (
101
100
$ configFound ? $ this ->getMockForAbstractClass (ValidationConfigInterface::class) : null
102
101
);
103
102
//Emulating validation result
@@ -109,6 +108,11 @@ public function testPlugin(bool $isMutation, bool $configFound, bool $isValid, b
109
108
$ this ->expectException (GraphQlInputException::class);
110
109
}
111
110
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
+ );
113
117
}
114
118
}
0 commit comments