TestCase.php 2.5 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
<?php
/**
 * @copyright  Vertex. All rights reserved.  https://www.vertexinc.com/
 * @author     Mediotype                     https://www.mediotype.com/
 */

namespace Vertex\Tax\Test\Integration;

use Magento\Framework\ObjectManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Vertex\Tax\Service\ServiceActionPerformerFactory;
use Vertex\Tax\Service\SoapClientFactory;
use Vertex\Tax\Test\Integration\Mock\SoapFactoryMock;

/**
 * Responsible for containing functionality used by all Vertex Integration Tests
 */
class TestCase extends \PHPUnit\Framework\TestCase
{
    /** @var ObjectManagerInterface */
    private $objectManager;

    /**
     * Instantiate the Object Manager and setup the SoapFactory mocker
     *
     * @return void
     */
    protected function setUp()
    {
        parent::setUp();
        $this->objectManager = Bootstrap::getObjectManager();
        $this->objectManager->configure(
            [
                'preferences' => [SoapClientFactory::class => SoapFactoryMock::class],
                ServiceActionPerformerFactory::class => [
                    'arguments' => [
                        'soapClientFactory' => [
                            'instance' => SoapFactoryMock::class
                        ]
                    ]
                ]
            ]
        );
    }

    /**
     * Retrieve the configured Object manager
     *
     * @return ObjectManagerInterface
     */
    public function getObjectManager()
    {
        return $this->objectManager;
    }

    /**
     * Get an instance of an object using the ObjectManager.
     *
     * @param string $className
     * @return mixed
     */
    protected function getObject($className)
    {
        return $this->getObjectManager()->get($className);
    }

    /**
     * Create an instance of an object using the ObjectManager.
     *
     * @param string $className
     * @param array $arguments
     * @return mixed
     */
    protected function createObject($className, array $arguments = [])
    {
        return $this->getObjectManager()->create($className, $arguments);
    }

    /**
     * Retrieve the SoapFactory that's been configured with the Object Manager
     *
     * @return SoapFactoryMock
     */
    public function getSoapFactory()
    {
        $factory = $this->objectManager->get(SoapClientFactory::class);
        if ($factory instanceof SoapFactoryMock) {
            return $factory;
        }
        throw new \RuntimeException('SoapClientFactory was not mock.  Misconfiguration occurred.');
    }
}