Scalr\Tests\Service\CloudStack\CloudStackTestCase::getCloudStackMock PHP Метод

getCloudStackMock() публичный Метод

Gets an CloudStack mock
public getCloudStackMock ( string $serviceName = null, Closure | callback | string $callback = null ) : CloudStack
$serviceName string Service name (Network, Volume etc..)
$callback Closure | callback | string optional callback for QueryClientResponse mock
Результат Scalr\Service\CloudStack\CloudStack Returns CloudStack Mock stub
    public function getCloudStackMock($serviceName = null, $callback = null)
    {
        $me = $this;
        $serviceInstance = null;
        $csStub = $this->getMock(self::CLOUDSTACK_NS . '\\CloudStack', array('__get', 'getClient'), array('fakeEndpoint', 'fakeApiKey', 'fakeSecretKey', self::PLATFORM));
        $queryClientClass = self::CLOUDSTACK_NS . '\\Client\\QueryClient';
        $queryClientStub = $this->getMock($queryClientClass, array('call'), array('fakeEndPoint', 'fakeApiKey', 'fakeSecretKey', self::PLATFORM));
        if (is_string($callback)) {
            $mth = $callback;
            $callback = function () use($me, $mth) {
                return $me->getQueryClientResponseMock($me->getFixtureFileContent($mth), null);
            };
        } else {
            if (!is_callable($callback)) {
                throw new \InvalidArgumentException('Invalid callback');
            }
        }
        $queryClientStub->expects($this->any())->method('call')->will($this->returnCallback($callback));
        $csStub->expects($this->any())->method('getClient')->will($this->returnValue($queryClientStub));
        if ($serviceName !== null) {
            $serviceInstance = $this->getServiceInterfaceMock($serviceName, $csStub);
        }
        $csStub->expects($this->any())->method('__get')->will($this->returnValue($serviceInstance));
        return $csStub;
    }