summaryrefslogtreecommitdiffstats
path: root/test/unit/MessageEventTest.php
blob: a91d17a3e0e9ef6436a80925aa06dd08b169f6a3 (plain)
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
<?php

namespace SparkPost;

use \Mockery;


class MessageEventTest extends \PHPUnit_Framework_TestCase
{
  private $sparkPostMock;
  private $sut;

  /**
   * (non-PHPdoc)
   * @before
   * @see PHPUnit_Framework_TestCase::setUp()
   */
  public function setUp()
  {
    $this->sparkPostMock = Mockery::mock('SparkPost\SparkPost', function ($mock) {
      $mock->shouldReceive('getHttpHeaders')->andReturn([]);
    });
    $this->sparkPostMock->httpAdapter = Mockery::mock();
    $this->sut = new MessageEvent($this->sparkPostMock);
  }

  public function testDateTimeConversion()
  {
    $testBody = ['results' => ['my' => 'test']];
    $testFrom = new \DateTime("1978-08-27 04:05:02");
    $testFromStr = urlencode("1978-08-27T04:05");
    $testTo = new \DateTime("2016-04-04 19:00");
    $testToStr = urlencode("2016-04-04T19:00");

    $responseMock = Mockery::mock();
    $this->sparkPostMock->httpAdapter->shouldReceive('send')->
      once()->
      with("/message-events/?from={$testFromStr}&to={$testToStr}", 'GET', Mockery::type('array'), null)->
      andReturn($responseMock);
    $responseMock->shouldReceive('getStatusCode')->andReturn(200);
    $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($testBody));

    $this->assertEquals($testBody, $this->sut->search(["from" => $testFrom, "to" => $testTo]));
  }
}