PaymentExperienceWebProfilesTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace Srmklive\PayPal\Tests\Unit\Client;
  3. use GuzzleHttp\Utils;
  4. use PHPUnit\Framework\Attributes\Test;
  5. use PHPUnit\Framework\TestCase;
  6. use Srmklive\PayPal\Tests\MockClientClasses;
  7. use Srmklive\PayPal\Tests\MockRequestPayloads;
  8. use Srmklive\PayPal\Tests\MockResponsePayloads;
  9. class PaymentExperienceWebProfilesTest extends TestCase
  10. {
  11. use MockClientClasses;
  12. use MockRequestPayloads;
  13. use MockResponsePayloads;
  14. #[Test]
  15. public function it_can_list_web_experience_profiles(): void
  16. {
  17. $expectedResponse = $this->mockListWebProfilesResponse();
  18. $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles';
  19. $expectedParams = [
  20. 'headers' => [
  21. 'Accept' => 'application/json',
  22. 'Accept-Language' => 'en_US',
  23. 'Authorization' => 'Bearer some-token',
  24. ],
  25. ];
  26. $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
  27. $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
  28. }
  29. #[Test]
  30. public function it_can_create_web_experience_profile(): void
  31. {
  32. $expectedResponse = $this->mockWebProfileResponse();
  33. $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles';
  34. $expectedParams = [
  35. 'headers' => [
  36. 'Accept' => 'application/json',
  37. 'Accept-Language' => 'en_US',
  38. 'Authorization' => 'Bearer some-token',
  39. 'PayPal-Request-Id' => 'some-request-id',
  40. ],
  41. 'json' => $this->mockCreateWebProfileParams(),
  42. ];
  43. $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
  44. $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
  45. }
  46. #[Test]
  47. public function it_can_delete_web_experience_profile(): void
  48. {
  49. $expectedResponse = '';
  50. $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles/XP-A88A-LYLW-8Y3X-E5ER';
  51. $expectedParams = [
  52. 'headers' => [
  53. 'Accept' => 'application/json',
  54. 'Accept-Language' => 'en_US',
  55. 'Authorization' => 'Bearer some-token',
  56. ],
  57. ];
  58. $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'delete');
  59. $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->delete($expectedEndpoint, $expectedParams)->getBody(), true));
  60. }
  61. #[Test]
  62. public function it_can_partially_update_web_experience_profile(): void
  63. {
  64. $expectedResponse = '';
  65. $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles/XP-A88A-LYLW-8Y3X-E5ER';
  66. $expectedParams = [
  67. 'headers' => [
  68. 'Accept' => 'application/json',
  69. 'Accept-Language' => 'en_US',
  70. 'Authorization' => 'Bearer some-token',
  71. ],
  72. 'json' => $this->partiallyUpdateWebProfileParams(),
  73. ];
  74. $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch');
  75. $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true));
  76. }
  77. #[Test]
  78. public function it_can_fully_update_web_experience_profile(): void
  79. {
  80. $expectedResponse = '';
  81. $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles/XP-A88A-LYLW-8Y3X-E5ER';
  82. $expectedParams = [
  83. 'headers' => [
  84. 'Accept' => 'application/json',
  85. 'Accept-Language' => 'en_US',
  86. 'Authorization' => 'Bearer some-token',
  87. ],
  88. 'json' => $this->updateWebProfileParams(),
  89. ];
  90. $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch');
  91. $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true));
  92. }
  93. #[Test]
  94. public function it_can_get_web_experience_profile_details(): void
  95. {
  96. $expectedResponse = $this->mockWebProfileResponse();
  97. $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles/XP-A88A-LYLW-8Y3X-E5ER';
  98. $expectedParams = [
  99. 'headers' => [
  100. 'Accept' => 'application/json',
  101. 'Accept-Language' => 'en_US',
  102. 'Authorization' => 'Bearer some-token',
  103. ],
  104. ];
  105. $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
  106. $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
  107. }
  108. }