SendRequestTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Test\Unit\Model\Vertex;
  7. use Magento\Framework\Exception\LocalizedException;
  8. use Vertex\Tax\Model\Config;
  9. use Vertex\Tax\Model\ApiClient;
  10. use Vertex\Tax\Test\Unit\TestCase;
  11. class SendRequestTest extends TestCase
  12. {
  13. const VERTEX_HOST = 'fake_vertex_host';
  14. const VERTEX_LOOKUP_HOST = 'fake_lookup_host';
  15. const CALCULATION_FUNCTION = 'CalculateTax60';
  16. const LOOKUP_FUNCTION = 'LookupTaxAreas60';
  17. public function setUp()
  18. {
  19. parent::setUp();
  20. }
  21. private function createCalculationConfigMock()
  22. {
  23. return $this->createPartialMock(Config::class, ['getVertexHost']);
  24. }
  25. private function createValidationConfigMock()
  26. {
  27. return $this->createPartialMock(
  28. Config::class,
  29. ['getVertexHost', 'getVertexAddressHost']
  30. );
  31. }
  32. public function testHappyTaxCalculation()
  33. {
  34. $calculationReturn = ['moo'];
  35. $configMock = $this->createCalculationConfigMock();
  36. $soapClientMock = $this->createPartialMock(\SoapClient::class, [static::CALCULATION_FUNCTION]);
  37. $soapClientMock->expects($this->once())
  38. ->method(static::CALCULATION_FUNCTION)
  39. ->willReturn($calculationReturn);
  40. $vertex = $this->getObject(
  41. ApiClient::class,
  42. ['config' => $configMock]
  43. );
  44. $result = $this->invokeInaccessibleMethod($vertex, 'performSoapCall', $soapClientMock, 'quote', '');
  45. $this->assertEquals($calculationReturn, $result);
  46. }
  47. public function testHappyTaxAreaLookup()
  48. {
  49. $lookupReturn = ['cow'];
  50. $configMock = $this->createValidationConfigMock();
  51. $soapClientMock = $this->createPartialMock(\SoapClient::class, [static::LOOKUP_FUNCTION]);
  52. $soapClientMock->expects($this->once())
  53. ->method(static::LOOKUP_FUNCTION)
  54. ->willReturn($lookupReturn);
  55. $vertex = $this->getObject(
  56. ApiClient::class,
  57. ['config' => $configMock]
  58. );
  59. $result = $this->invokeInaccessibleMethod($vertex, 'performSoapCall', $soapClientMock, 'tax_area_lookup', '');
  60. $this->assertEquals($lookupReturn, $result);
  61. }
  62. }