TestCase.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\Integration;
  7. use Magento\Framework\ObjectManagerInterface;
  8. use Magento\TestFramework\Helper\Bootstrap;
  9. use Vertex\Tax\Service\ServiceActionPerformerFactory;
  10. use Vertex\Tax\Service\SoapClientFactory;
  11. use Vertex\Tax\Test\Integration\Mock\SoapFactoryMock;
  12. /**
  13. * Responsible for containing functionality used by all Vertex Integration Tests
  14. */
  15. class TestCase extends \PHPUnit\Framework\TestCase
  16. {
  17. /** @var ObjectManagerInterface */
  18. private $objectManager;
  19. /**
  20. * Instantiate the Object Manager and setup the SoapFactory mocker
  21. *
  22. * @return void
  23. */
  24. protected function setUp()
  25. {
  26. parent::setUp();
  27. $this->objectManager = Bootstrap::getObjectManager();
  28. $this->objectManager->configure(
  29. [
  30. 'preferences' => [SoapClientFactory::class => SoapFactoryMock::class],
  31. ServiceActionPerformerFactory::class => [
  32. 'arguments' => [
  33. 'soapClientFactory' => [
  34. 'instance' => SoapFactoryMock::class
  35. ]
  36. ]
  37. ]
  38. ]
  39. );
  40. }
  41. /**
  42. * Retrieve the configured Object manager
  43. *
  44. * @return ObjectManagerInterface
  45. */
  46. public function getObjectManager()
  47. {
  48. return $this->objectManager;
  49. }
  50. /**
  51. * Get an instance of an object using the ObjectManager.
  52. *
  53. * @param string $className
  54. * @return mixed
  55. */
  56. protected function getObject($className)
  57. {
  58. return $this->getObjectManager()->get($className);
  59. }
  60. /**
  61. * Create an instance of an object using the ObjectManager.
  62. *
  63. * @param string $className
  64. * @param array $arguments
  65. * @return mixed
  66. */
  67. protected function createObject($className, array $arguments = [])
  68. {
  69. return $this->getObjectManager()->create($className, $arguments);
  70. }
  71. /**
  72. * Retrieve the SoapFactory that's been configured with the Object Manager
  73. *
  74. * @return SoapFactoryMock
  75. */
  76. public function getSoapFactory()
  77. {
  78. $factory = $this->objectManager->get(SoapClientFactory::class);
  79. if ($factory instanceof SoapFactoryMock) {
  80. return $factory;
  81. }
  82. throw new \RuntimeException('SoapClientFactory was not mock. Misconfiguration occurred.');
  83. }
  84. }