getMockBuilder('Magento\Authorization\Model\UserContextInterface') ->disableOriginalConstructor()->setMethods(['getUserId', 'getUserType'])->getMockForAbstractClass(); $userContextMock->expects($this->any())->method('getUserId')->will($this->returnValue($userId)); $userContextMock->expects($this->any())->method('getUserType')->will($this->returnValue($userType)); $paramOverriderCustomerId = $objectManager->getObject( 'Magento\Webapi\Controller\Rest\ParamOverriderCustomerId', ['userContext' => $userContextMock] ); /** @var \Magento\Webapi\Controller\Rest\ParamsOverrider $paramsOverrider */ $paramsOverrider = $objectManager->getObject( 'Magento\Webapi\Controller\Rest\ParamsOverrider', ['paramOverriders' => ['%customer_id%' => $paramOverriderCustomerId ]] ); $this->assertEquals($expectedOverriddenParams, $paramsOverrider->override($requestData, $parameters)); } /** * @return array */ public function overrideParamsDataProvider() { return [ 'force false, value present' => [ ['Name1' => 'valueIn'], ['Name1' => ['force' => false, 'value' => 'valueOverride']], ['Name1' => 'valueIn'], 1, UserContextInterface::USER_TYPE_INTEGRATION, ], 'force true, value present' => [ ['Name1' => 'valueIn'], ['Name1' => ['force' => true, 'value' => 'valueOverride']], ['Name1' => 'valueOverride'], 1, UserContextInterface::USER_TYPE_INTEGRATION, ], 'force true, value not present' => [ ['Name1' => 'valueIn'], ['Name2' => ['force' => true, 'value' => 'valueOverride']], ['Name1' => 'valueIn', 'Name2' => 'valueOverride'], 1, UserContextInterface::USER_TYPE_INTEGRATION, ], 'force false, value not present' => [ ['Name1' => 'valueIn'], ['Name2' => ['force' => false, 'value' => 'valueOverride']], ['Name1' => 'valueIn', 'Name2' => 'valueOverride'], 1, UserContextInterface::USER_TYPE_INTEGRATION, ], 'force true, value present, override value is %customer_id%' => [ ['Name1' => 'valueIn'], ['Name1' => ['force' => true, 'value' => '%customer_id%']], ['Name1' => '1234'], 1234, UserContextInterface::USER_TYPE_CUSTOMER, ], 'force true, value present, override value is %customer_id%, not a customer' => [ ['Name1' => 'valueIn'], ['Name1' => ['force' => true, 'value' => '%customer_id%']], ['Name1' => null], 1234, UserContextInterface::USER_TYPE_INTEGRATION, ], ]; } }