diff --git a/dev/tests/integration/testsuite/Magento/Webapi/Model/ServiceMetadataTest.php b/dev/tests/integration/testsuite/Magento/Webapi/Model/ServiceMetadataTest.php index c74b0888d24d548bf2b673bd211aa4f31f0316dd..521e0b6fc7c3a2234c05ce31b4e1fe8e2dd2ddd3 100644 --- a/dev/tests/integration/testsuite/Magento/Webapi/Model/ServiceMetadataTest.php +++ b/dev/tests/integration/testsuite/Magento/Webapi/Model/ServiceMetadataTest.php @@ -5,231 +5,116 @@ */ namespace Magento\Webapi\Model; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\Webapi\Model\ServiceMetadata; +use Magento\Customer\Api\AccountManagementInterface; + class ServiceMetadataTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Webapi\Model\ServiceMetadata + * @var ServiceMetadata */ private $serviceMetadata; - /** - * Set up helper. - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ protected function setUp() { - $interfaceParameters = [ - 'activateById' => [ - 'interface' => [ - 'in' => [ - 'parameters' => [ - 'customerId' => [ - 'force' => true, - 'value' => '%customer_id%', - ], - 'requiredInputParameter' => [ - 'required' => true, - ], - ], - ], - 'out' => [ - 'parameters' => [ - 'outputParameter' => [ - 'type' => 'string', - ], - ], - ], - ], - ], - ]; - $classReflection = $this->getMock( - \Magento\Webapi\Model\Config\ClassReflector::class, - ['reflectClassMethods', 'extractClassDescription'], - [], - '', - false - ); - $classReflection->expects($this->any()) - ->method('reflectClassMethods') - ->will($this->returnValue($interfaceParameters)); - $classReflection->expects($this->any()) - ->method('extractClassDescription') - ->will($this->returnValue('classDescription')); - - $servicesConfig = [ - 'services' => [\Magento\Customer\Api\AccountManagementInterface::class => [ - 'V1' => [ - 'methods' => [ - 'activateById' => [ - 'resources' => [ - [ - 'Magento_Customer::manage', - ], - ], - 'secure' => false, - ], - ], - ], - ], \Magento\Customer\Api\CustomerRepositoryInterface::class => [ - 'V1' => [ - 'methods' => [ - 'getById' => [ - 'resources' => [ - [ - 'Magento_Customer::customer', - ], - ], - 'secure' => false, - ], - ], - ], - ], - ], - 'routes' => [ - '/V1/customers/me/activate' => [ - 'PUT' => [ - 'secure' => false, - 'service' => [ - 'class' => \Magento\Customer\Api\AccountManagementInterface::class, - 'method' => 'activateById', - ], - 'resources' => [ - 'self' => true, - ], - 'parameters' => [ - 'customerId' => [ - 'force' => true, - 'value' => '%customer_id%', - ], - ], - ], - ], - '/V1/customers/:customerId' => [ - 'GET' => [ - 'secure' => false, - 'service' => [ - 'class' => \Magento\Customer\Api\CustomerRepositoryInterface::class, - 'method' => 'getById', - ], - 'resources' => [ - 'Magento_Customer::customer' => true, - ], - 'parameters' => [ - ], - ], - ], - ] - ]; - - /** - * @var $cacheMock \Magento\Webapi\Model\Cache\Type\Webapi - */ - $cacheMock = $this->getMockBuilder(\Magento\Webapi\Model\Cache\Type\Webapi::class) - ->disableOriginalConstructor() - ->getMock(); - - /** @var $readerMock \Magento\Webapi\Model\Config\Reader */ - $readerMock = $this->getMockBuilder(\Magento\Webapi\Model\Config\Reader::class) - ->disableOriginalConstructor() - ->getMock(); - $readerMock->expects($this->any())->method('read')->will($this->returnValue($servicesConfig)); - - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - - /** @var $config \Magento\Webapi\Model\Config */ - $config = $objectManager->create( - \Magento\Webapi\Model\Config::class, - [ - 'cache' => $cacheMock, - 'configReader' => $readerMock, - ] - ); - - $typeProcessor = $objectManager->create(\Magento\Framework\Reflection\TypeProcessor::class); - - /** @var $config \Magento\Webapi\Model\ServiceMetadata */ - $this->serviceMetadata = $objectManager->create( - \Magento\Webapi\Model\ServiceMetadata::class, - [ - 'config' => $config, - 'cache' => $cacheMock, - 'classReflector' => $classReflection, - 'typeProcessor' => $typeProcessor, - ] - ); + $objectManager = Bootstrap::getObjectManager(); + $this->serviceMetadata = $objectManager->create(ServiceMetadata::class); } public function testGetServiceMetadata() { - $expectedResult = [ + $expected = [ 'methods' => [ - 'activateById' => [ - 'method' => 'activateById', - 'inputRequired' => '', - 'isSecure' => '', - 'resources' => [['Magento_Customer::manage']], + 'activate' => [ + 'method' => 'activate', + 'inputRequired' => false, + 'isSecure' => false, + 'resources' => [ + 'Magento_Customer::manage' + ], + 'documentation' => 'Activate a customer account using a key that was sent in a confirmation email.', 'interface' => [ 'in' => [ 'parameters' => [ - 'customerId' => [ - 'force' => true, - 'value' => '%customer_id%', - ], - 'requiredInputParameter' => [ + 'email' => [ + 'type' => 'string', 'required' => true, + 'documentation' => null ], - ], + 'confirmationKey' => [ + 'type' => 'string', + 'required' => true, + 'documentation' => null + ] + ] ], 'out' => [ 'parameters' => [ - 'outputParameter' => [ - 'type' => 'string', - ], + 'result' => [ + 'type' => 'CustomerDataCustomerInterface', + 'required' => true, + 'documentation' => '' + ] ], - ], - ], - ], + 'throws' => [ + '\Magento\Framework\Exception\LocalizedException' + ] + ] + ] + ] ], - 'class' => \Magento\Customer\Api\AccountManagementInterface::class, - 'description' => 'classDescription', + 'class' => AccountManagementInterface::class, + 'description' => 'Interface for managing customers accounts.', ]; - $result = $this->serviceMetadata->getServiceMetadata('customerAccountManagementV1'); - $this->assertEquals($expectedResult, $result); + $actual = $this->serviceMetadata->getServiceMetadata('customerAccountManagementV1'); + $this->assertEquals(array_replace_recursive($expected, $actual), $actual); } public function testGetRouteMetadata() { - $expectedResult = [ + $expected = [ 'methods' => [ - 'activateById' => [ - 'method' => 'activateById', - 'inputRequired' => '', - 'isSecure' => '', - 'resources' => [['Magento_Customer::manage']], + 'activate' => [ + 'method' => 'activate', + 'inputRequired' => false, + 'isSecure' => false, + 'resources' => [ + 'Magento_Customer::manage' + ], + 'documentation' => 'Activate a customer account using a key that was sent in a confirmation email.', 'interface' => [ 'in' => [ 'parameters' => [ - 'customerId' => [ - 'force' => true, - 'value' => '%customer_id%', - ], - 'requiredInputParameter' => [ + 'email' => [ + 'type' => 'string', 'required' => true, + 'documentation' => null ], - ], + 'confirmationKey' => [ + 'type' => 'string', + 'required' => true, + 'documentation' => null + ] + ] ], 'out' => [ 'parameters' => [ - 'outputParameter' => [ - 'type' => 'string', - ], + 'result' => [ + 'type' => 'CustomerDataCustomerInterface', + 'required' => true, + 'documentation' => '' + ] ], - ], - ], - ], + 'throws' => [ + '\Magento\Framework\Exception\LocalizedException' + ] + ] + ] + ] ], - 'class' => \Magento\Customer\Api\AccountManagementInterface::class, - 'description' => 'classDescription', + 'class' => AccountManagementInterface::class, + 'description' => 'Interface for managing customers accounts.', 'routes' => [ '/V1/customers/me/activate' => [ 'PUT' => [ @@ -244,7 +129,7 @@ class ServiceMetadataTest extends \PHPUnit_Framework_TestCase ] ] ]; - $result = $this->serviceMetadata->getRouteMetadata('customerAccountManagementV1'); - $this->assertEquals($expectedResult, $result); + $actual = $this->serviceMetadata->getRouteMetadata('customerAccountManagementV1'); + $this->assertEquals(array_replace_recursive($expected, $actual), $actual); } } diff --git a/dev/tests/integration/testsuite/Magento/Webapi/Model/Soap/ConfigTest.php b/dev/tests/integration/testsuite/Magento/Webapi/Model/Soap/ConfigTest.php index 74e6728fcee26dd8b3eb0869c770b7b978f0aa6a..4ab3bccd42d95ceee2d969156a76fa7665966333 100644 --- a/dev/tests/integration/testsuite/Magento/Webapi/Model/Soap/ConfigTest.php +++ b/dev/tests/integration/testsuite/Magento/Webapi/Model/Soap/ConfigTest.php @@ -5,161 +5,112 @@ */ namespace Magento\Webapi\Model\Soap; -// @codingStandardsIgnoreFile +use Magento\TestFramework\Helper\Bootstrap; +use Magento\Webapi\Model\Soap\Config; +use Magento\Customer\Api\AccountManagementInterface; +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Framework\Exception\LocalizedException; class ConfigTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Webapi\Model\Soap\Config + * @var Config */ - private $_soapConfig; + private $soapConfig; - /** - * @var \Magento\TestFramework\Helper\Bootstrap - */ - private $objectManager; - - /** - * Set up helper. - */ protected function setUp() { - $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - - $typeProcessor = $this->objectManager->create(\Magento\Framework\Reflection\TypeProcessor::class); - - $objectManagerMock = $this->getMockBuilder( - \Magento\Framework\App\ObjectManager::class - )->disableOriginalConstructor()->getMock(); - - $classReflection = $this->getMock( - \Magento\Webapi\Model\Config\ClassReflector::class, - ['reflectClassMethods'], - ['_typeProcessor' => $typeProcessor], - '' - ); - $classReflection->expects($this->any())->method('reflectClassMethods')->will($this->returnValue([])); + $objectManager = Bootstrap::getObjectManager(); + $this->soapConfig = $objectManager->create(Config::class); + } - $servicesConfig = [ - 'services' => [\Magento\Customer\Api\AccountManagementInterface::class => [ - 'V1' => [ - 'methods' => [ - 'activate' => [ - 'resources' => [ - [ - 'Magento_Customer::manage', - ], - ], - 'secure' => false, - ], + public function testGetRequestedSoapServices() + { + $expected = [ + 'customerAccountManagementV1' => [ + 'methods' => [ + 'activate' => [ + 'method' => 'activate', + 'inputRequired' => false, + 'isSecure' => false, + 'resources' => [ + 'Magento_Customer::manage' ], - ], - ], \Magento\Customer\Api\CustomerRepositoryInterface::class => [ - 'V1' => [ - 'methods' => [ - 'getById' => [ - 'resources' => [ - [ - 'Magento_Customer::customer', + 'documentation' + => 'Activate a customer account using a key that was sent in a confirmation email.', + 'interface' => [ + 'in' => [ + 'parameters' => [ + 'email' => [ + 'type' => 'string', + 'required' => true, + 'documentation' => null ], - ], - 'secure' => false, + 'confirmationKey' => [ + 'type' => 'string', + 'required' => true, + 'documentation' => null + ] + ] ], - ], - ], + 'out' => [ + 'parameters' => [ + 'result' => [ + 'type' => 'CustomerDataCustomerInterface', + 'required' => true, + 'documentation' => null + ] + ], + 'throws' => [ + '\Magento\Framework\Exception\LocalizedException' + ] + ] + ] + ] ], - ], - ]; - - /** - * @var $registryMock \Magento\Framework\Registry - */ - $registryMock = $this->getMockBuilder(\Magento\Framework\Registry::class) - ->disableOriginalConstructor() - ->getMock(); - - /** - * @var $cacheMock \Magento\Webapi\Model\Cache\Type\Webapi - */ - $cacheMock = $this->getMockBuilder(\Magento\Webapi\Model\Cache\Type\Webapi::class) - ->disableOriginalConstructor() - ->getMock(); - - /** @var $readerMock \Magento\Webapi\Model\Config\Reader */ - $readerMock = $this->getMockBuilder(\Magento\Webapi\Model\Config\Reader::class) - ->disableOriginalConstructor() - ->getMock(); - $readerMock->expects($this->any())->method('read')->will($this->returnValue($servicesConfig)); - - /** @var $config \Magento\Webapi\Model\Config */ - $config = new \Magento\Webapi\Model\Config($cacheMock, $readerMock); - - /** @var $config \Magento\Webapi\Model\ServiceMetadata */ - $serviceMetadata = $this->objectManager->create( - \Magento\Webapi\Model\ServiceMetadata::class, - [ - 'config' => $config, - 'cache' => $cacheMock, - 'classReflector' => $classReflection, - 'typeProcessor' => $typeProcessor + 'class' => AccountManagementInterface::class, + 'description' => 'Interface for managing customers accounts.', ] - ); - - $this->_soapConfig = $this->objectManager->create( - \Magento\Webapi\Model\Soap\Config::class, + ]; + $actual = $this->soapConfig->getRequestedSoapServices( [ - 'objectManager' => $objectManagerMock, - 'registry' => $registryMock, - 'serviceMetadata' => $serviceMetadata, + 'customerAccountManagementV1', + 'NonExistentService' ] ); - } - - public function testGetRequestedSoapServices() - { - $expectedResult = [ - 'customerAccountManagementV1' => - [ - 'methods' => [ - 'activate' => [ - 'method' => 'activate', - 'inputRequired' => '', - 'isSecure' => '', - 'resources' => [['Magento_Customer::manage']], - ], - ], - 'class' => \Magento\Customer\Api\AccountManagementInterface::class, - 'description' => 'Interface for managing customers accounts.', - ], - ]; - - $result = $this->_soapConfig->getRequestedSoapServices( - ['customerAccountManagementV1', 'moduleBarV2', 'moduleBazV1'] - ); - - $this->assertEquals($expectedResult, $result); + $this->assertEquals(array_replace_recursive($expected, $actual), $actual); } public function testGetServiceMethodInfo() { - $expectedResult = [ - 'class' => \Magento\Customer\Api\CustomerRepositoryInterface::class, + $expected = [ + 'class' => CustomerRepositoryInterface::class, 'method' => 'getById', 'isSecure' => false, - 'resources' => [['Magento_Customer::customer']], + 'resources' => [ + 'Magento_Customer::customer', + 'self' + ], ]; - $methodInfo = $this->_soapConfig->getServiceMethodInfo( + $actual = $this->soapConfig->getServiceMethodInfo( 'customerCustomerRepositoryV1GetById', - ['customerCustomerRepositoryV1', 'moduleBazV1'] + [ + 'customerCustomerRepositoryV1', + 'NonExistentService' + ] ); - $this->assertEquals($expectedResult, $methodInfo); + $this->assertEquals($expected, $actual); } public function testGetSoapOperation() { - $expectedResult = 'customerAccountManagementV1Activate'; - $soapOperation = $this->_soapConfig - ->getSoapOperation(\Magento\Customer\Api\AccountManagementInterface::class, 'activate', 'V1'); - $this->assertEquals($expectedResult, $soapOperation); + $expected = 'customerAccountManagementV1Activate'; + $actual = $this->soapConfig + ->getSoapOperation( + AccountManagementInterface::class, + 'activate', + 'V1' + ); + $this->assertEquals($expected, $actual); } }