PreventAssignedToSalesChannelsStockDeletingTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\InventorySalesApi\Test\Api\StockRepository;
  8. use Magento\Framework\Webapi\Exception;
  9. use Magento\Framework\Webapi\Rest\Request;
  10. use Magento\TestFramework\TestCase\WebapiAbstract;
  11. class PreventAssignedToSalesChannelsStockDeletingTest extends WebapiAbstract
  12. {
  13. /**
  14. * @magentoApiDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php
  15. * @magentoApiDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_with_sales_channels.php
  16. * @throws \Exception
  17. */
  18. public function testCouldNotDeleteException()
  19. {
  20. $stockId = 10;
  21. $serviceInfo = [
  22. 'rest' => [
  23. 'resourcePath' => '/V1/inventory/stocks/' . $stockId,
  24. 'httpMethod' => Request::HTTP_METHOD_DELETE,
  25. ],
  26. 'soap' => [
  27. 'service' => 'inventoryApiStockRepositoryV1',
  28. 'operation' => 'inventoryApiStockRepositoryV1DeleteById',
  29. ],
  30. ];
  31. $expectedMessage = 'Stock has at least one sale channel and could not be deleted.';
  32. try {
  33. (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST)
  34. ? $this->_webApiCall($serviceInfo)
  35. : $this->_webApiCall($serviceInfo, ['stockId' => $stockId]);
  36. $this->fail('Expected throwing exception');
  37. } catch (\Exception $e) {
  38. if (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST) {
  39. $errorData = $this->processRestExceptionResult($e);
  40. self::assertEquals($expectedMessage, $errorData['message']);
  41. self::assertEquals(Exception::HTTP_BAD_REQUEST, $e->getCode());
  42. } elseif (TESTS_WEB_API_ADAPTER === self::ADAPTER_SOAP) {
  43. $this->assertInstanceOf('SoapFault', $e);
  44. $this->checkSoapFault($e, $expectedMessage, 'env:Sender');
  45. } else {
  46. throw $e;
  47. }
  48. }
  49. }
  50. }