GetTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventoryApi\Test\Api\StockRepository;
  8. use Magento\Framework\Webapi\Exception;
  9. use Magento\Framework\Webapi\Rest\Request;
  10. use Magento\TestFramework\TestCase\WebapiAbstract;
  11. /**
  12. * Method Get is covered in CreateTest test
  13. * @see \Magento\InventoryApi\Test\Api\StockRepository\CreateTest::getStockDataById
  14. */
  15. class GetTest extends WebapiAbstract
  16. {
  17. /**#@+
  18. * Service constants
  19. */
  20. const RESOURCE_PATH = '/V1/inventory/stocks';
  21. const SERVICE_NAME = 'inventoryApiStockRepositoryV1';
  22. /**#@-*/
  23. public function testGetNoSuchEntityException()
  24. {
  25. $notExistingId = -1;
  26. $serviceInfo = [
  27. 'rest' => [
  28. 'resourcePath' => self::RESOURCE_PATH . '/' . $notExistingId,
  29. 'httpMethod' => Request::HTTP_METHOD_GET,
  30. ],
  31. 'soap' => [
  32. 'service' => self::SERVICE_NAME,
  33. 'operation' => self::SERVICE_NAME . 'Get',
  34. ],
  35. ];
  36. $expectedMessage = 'Stock with id "%value" does not exist.';
  37. try {
  38. (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST)
  39. ? $this->_webApiCall($serviceInfo)
  40. : $this->_webApiCall($serviceInfo, ['stockId' => $notExistingId]);
  41. $this->fail('Expected throwing exception');
  42. } catch (\Exception $e) {
  43. if (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST) {
  44. $errorData = $this->processRestExceptionResult($e);
  45. self::assertEquals($expectedMessage, $errorData['message']);
  46. self::assertEquals($notExistingId, $errorData['parameters']['value']);
  47. self::assertEquals(Exception::HTTP_NOT_FOUND, $e->getCode());
  48. } elseif (TESTS_WEB_API_ADAPTER === self::ADAPTER_SOAP) {
  49. $this->assertInstanceOf('SoapFault', $e);
  50. $this->checkSoapFault($e, $expectedMessage, 'env:Sender', ['value' => $notExistingId]);
  51. } else {
  52. throw $e;
  53. }
  54. }
  55. }
  56. }