public function testLoadToken() { $token = 'token-value'; $itemData = [TokenInterface::TOKEN => 'token', TokenInterface::CITY => 'city']; $tokenMock = $this->createTokenMock(); $this->httpClientMock->expects($this->once())->method('get')->with("/services/v1/vault/tokens/{$token}.json")->willReturn([TokenService::API_NAME_TOKEN => $itemData]); $this->tokenFactoryMock->expects($this->once())->method('create')->with($itemData)->willReturn($tokenMock); $this->assertSame($tokenMock, $this->tokenService->loadToken($token)); }
public function testLoadEvent() { $eventId = 52231; $itemData = [EventInterface::ID => $eventId]; $eventMock = $this->getMockBuilder('SubscribePro\\Service\\Webhook\\EventInterface')->getMock(); $this->httpClientMock->expects($this->once())->method('get')->with("/services/v2/webhook-events/{$eventId}.json")->willReturn([WebhookService::API_NAME_WEBHOOK_EVENT => $itemData]); $this->eventFactoryMock->expects($this->once())->method('create')->with($itemData)->willReturn($eventMock); $this->assertSame($eventMock, $this->webhookService->loadEvent($eventId)); }
/** * Config options: * - client_id * - client_secret * - base_url * - logging_enable * default value false * - logging_level * default value @see \Psr\Log\LogLevel::INFO * - logging_file_name * default value @see SubscribePro\Http::DEFAULT_LOG_FILE_NAME * - logging_line_format * default value @see SubscribePro\Http::DEFAULT_LOG_LINE_FORMAT * - logging_message_format * default value @see SubscribePro\Http::DEFAULT_LOG_MESSAGE_FORMAT * - <service_name> * Config options for specified service * * @param array $config * @throws \SubscribePro\Exception\InvalidArgumentException */ public function __construct(array $config = []) { $config = array_merge(['client_id' => getenv(static::CLIENT_ID_ENV_NAME), 'client_secret' => getenv(static::CLIENT_SECRET_ENV_NAME), 'base_url' => null, 'logging_enable' => false, 'logging_level' => null, 'logging_file_name' => null, 'logging_line_format' => null, 'logging_message_format' => null], $config); if (!$config['client_id']) { throw new InvalidArgumentException('Required "client_id" key is not supplied in config and could not find fallback environment variable "' . static::CLIENT_ID_ENV_NAME . '"'); } if (!$config['client_secret']) { throw new InvalidArgumentException('Required "client_secret" key is not supplied in config and could not find fallback environment variable "' . static::CLIENT_SECRET_ENV_NAME . '"'); } $app = new App($config['client_id'], $config['client_secret']); unset($config['client_id']); unset($config['client_secret']); $this->http = new Http($app, $config['base_url']); unset($config['base_url']); if ($config['logging_enable']) { $this->http->addDefaultLogger($config['logging_file_name'], $config['logging_line_format'], $config['logging_message_format'], $config['logging_level']); } unset($config['logging_enable']); unset($config['logging_level']); unset($config['logging_file_name']); unset($config['logging_line_format']); unset($config['logging_message_format']); $this->serviceFactoryResolver = new ServiceFactoryResolver($this->http, $config); $this->toolFactory = new ToolFactory($this->http); }
public function testVoid() { $itemId = 12321; $resultData = [TransactionInterface::ID => $itemId]; $transactionMock = $this->createTransactionMock(); $this->transactionFactoryMock->expects($this->once())->method('create')->with($resultData)->willReturn($transactionMock); $this->httpClientMock->expects($this->once())->method('post')->with("/services/v1/vault/transactions/{$itemId}/void.json")->willReturn([TransactionService::API_NAME_TRANSACTION => $resultData]); $this->assertSame($transactionMock, $this->transactionService->void($itemId)); }
/** * @param int $customerId * @param array $filters * @param array $itemsData * @dataProvider loadProductsDataProvider */ public function testLoadProducts($customerId, $filters, $itemsData) { $this->httpClientMock->expects($this->once())->method('get')->with('/services/v2/products.json', $filters)->willReturn([ProductService::API_NAME_PRODUCTS => $itemsData]); $products = []; $productFactoryMap = []; foreach ($itemsData as $itemData) { $product = $this->createProductMock(); $productFactoryMap[] = [$itemData, $product]; $products[] = $product; } $this->productFactoryMock->expects($this->exactly(count($itemsData)))->method('create')->willReturnMap($productFactoryMap); $this->assertSame($products, $this->productService->loadProducts($customerId)); }
/** * @param array $filters * @param array $itemsData * @dataProvider loadCustomersDataProvider */ public function testLoadCustomers($filters, $itemsData) { $this->httpClientMock->expects($this->once())->method('get')->with('/services/v2/customers.json', $filters)->willReturn([CustomerService::API_NAME_CUSTOMERS => $itemsData]); $customers = []; $customerFactoryMap = []; foreach ($itemsData as $itemData) { $customer = $this->createCustomerMock(); $customerFactoryMap[] = [$itemData, $customer]; $customers[] = $customer; } $this->customerFactoryMock->expects($this->exactly(count($itemsData)))->method('create')->willReturnMap($customerFactoryMap); $this->assertSame($customers, $this->customerService->loadCustomers($filters)); }
public function testVerifyAndSaveToken() { $token = 'test-token'; $formData = [PaymentProfileInterface::CREDITCARD_FIRST_DIGITS => '123']; $expectedImportData = [PaymentProfileInterface::ID => '111']; $url = "/services/v1/vault/tokens/{$token}/verifyandstore.json"; $paymentProfileMock = $this->createProfileMock(); $paymentProfileMock->expects($this->once())->method('isTokenDataValid')->willReturn(true); $paymentProfileMock->expects($this->once())->method('getTokenFormData')->willReturn($formData); $paymentProfileMock->expects($this->once())->method('importData')->with($expectedImportData)->willReturnSelf(); $this->httpClientMock->expects($this->once())->method('post')->with($url, [PaymentProfileService::API_NAME_PROFILE => $formData])->willReturn([PaymentProfileService::API_NAME_PROFILE => $expectedImportData]); $this->assertSame($paymentProfileMock, $this->paymentProfileService->verifyAndSaveToken($token, $paymentProfileMock)); }
/** * @param int $customerId * @param array $filters * @param array $itemsData * @dataProvider loadAddressesDataProvider */ public function testLoadAddresses($customerId, $filters, $itemsData) { $this->httpClientMock->expects($this->once())->method('get')->with('/services/v2/addresses.json', $filters)->willReturn([AddressService::API_NAME_ADDRESSES => $itemsData]); $addresses = []; $addressFactoryMap = []; foreach ($itemsData as $itemData) { $address = $this->createAddressMock(); $addressFactoryMap[] = [$itemData, $address]; $addresses[] = $address; } $this->addressFactoryMock->expects($this->exactly(count($itemsData)))->method('create')->willReturnMap($addressFactoryMap); $this->assertSame($addresses, $this->addressService->loadAddresses($customerId)); }
/** * @param array $responseData * @param array $expectedResult * @dataProvider loadDataProvider */ public function testLoad($responseData, $expectedResult) { $this->httpClientMock->expects($this->once())->method('get')->with('/services/v2/config.json')->willReturn($responseData); $this->assertEquals($expectedResult, $this->configTool->load()); }
/** * @param string $url * @param \GuzzleHttp\Psr7\Response $response * @param string $filePath * @param array|int $result * @dataProvider getToSinkDataProvider */ public function testGetToSink($url, $response, $filePath, $result) { $this->clientMock->expects($this->once())->method('get')->with($url, [RequestOptions::SINK => $filePath])->willReturn($response); $this->assertEquals($result, $this->httpMock->getToSink($url, $filePath)); }
public function testSkipSubscription() { $subscriptionId = 3; $this->httpClientMock->expects($this->once())->method('post')->with("/services/v2/subscriptions/{$subscriptionId}/skip.json"); $this->subscriptionService->skipSubscription($subscriptionId); }