Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.45 KB | None | 0 0
  1. class ActiveTest extends TestCase
  2. {
  3.     use ApiTesterTrait;
  4.  
  5.     private const ACTION_URI = '/events/active';
  6.  
  7.     public function setUp(): void
  8.     {
  9.         $this->setUpClient();
  10.     }
  11.  
  12.     public function testReturnExpectedEvents(): void
  13.     {
  14.         $mock = json_decode(file_get_contents(__DIR__ . '/mocks/active.json'), true);
  15.  
  16.         $response = $this->client->get(self::ACTION_URI, [
  17.             'query' => [
  18.                 'idClient' => 1
  19.             ],
  20.             'headers' => [
  21.                 'Authorization' => $this->authorization
  22.             ]
  23.         ]);
  24.  
  25.         $body = json_decode($response->getBody(), true);
  26.         $props = ['idEvent', 'sellingDateStart', 'sellingDateEnd', 'reservationExpirationDays', 'reservationExpirationDate', 'reservationDelay', 'eventObject', 'image', 'clientPoolsAllowed', 'isClientAllowed'];
  27.  
  28.         foreach ($body as $index => $event) {
  29.             foreach ($props as $prop) {
  30.                 $events[$index][$prop] = $event[$prop];
  31.             }
  32.         }
  33.  
  34.         $this->assertEquals($mock, $events ?? []);
  35.     }
  36.  
  37.     public function testReturnExpectedEventsOnNonEmptyServiceType(): void
  38.     {
  39.         $mock = json_decode(file_get_contents(__DIR__ . '/mocks/active.json'), true);
  40.  
  41.         $response = $this->client->get(self::ACTION_URI, [
  42.             'query' => [
  43.                 'idClient' => 1,
  44.                 'serviceType' => 'dms'
  45.             ],
  46.             'headers' => [
  47.                 'Authorization' => $this->authorization
  48.             ]
  49.         ]);
  50.  
  51.         $body = json_decode($response->getBody(), true);
  52.         $props = ['idEvent', 'sellingDateStart', 'sellingDateEnd', 'reservationExpirationDays', 'reservationExpirationDate', 'reservationDelay', 'eventObject', 'image', 'clientPoolsAllowed', 'isClientAllowed'];
  53.  
  54.         foreach ($body as $index => $event) {
  55.             foreach ($props as $prop) {
  56.                 $events[$index][$prop] = $event[$prop];
  57.             }
  58.         }
  59.  
  60.         $this->assertEquals($mock, $events ?? []);
  61.     }
  62.  
  63.     public function testReturnBadRequestOnNonExistentClient(): void
  64.     {
  65.         $response = $this->client->get(self::ACTION_URI, [
  66.             'query' => [
  67.                 'idClient' => 9999
  68.             ],
  69.             'headers' => [
  70.                 'Authorization' => $this->authorization
  71.             ],
  72.             'http_errors' => false
  73.         ]);
  74.  
  75.         $this->assertEquals(400, $response->getStatusCode());
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement