summaryrefslogtreecommitdiffstats
path: root/test/Json/PJsonCurlTest.php
blob: 707fa10dd47df644d82f598814469cb7419122c7 (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
<?php

require_once (dirname(__FILE__) . '/../../src/PurpleCode/PCurl/PCurlResponse.php');
require_once (dirname(__FILE__) . '/../../src/PurpleCode/PCurl/Json/PJsonCurlResponse.php');
require_once (dirname(__FILE__) . '/../../src/PurpleCode/PCurl/PCurl.php');
require_once (dirname(__FILE__) . '/../../src/PurpleCode/PCurl/Json/PJsonCurl.php');

use PurpleCode\PCurl\Json\PJsonCurl;

class PJsonCurlTest extends PHPUnit_Framework_TestCase {

  public function testShouldGetJsonFileAndParse() {
    // given  
    $cut = new PJsonCurl('file:///' . __DIR__ . '/test.json');

    // when
    $response = $cut->get('');

    // then
    $this->assertEquals(2, $response->getJson()->a->b);
    $this->assertEquals("a", $response->getJson()->a->c);
  }

  public function testShouldFailParseWrongFile() {
    // given
    $cut = new PJsonCurl('file:///' . __DIR__ . '/testinvalid.json');

    //then
    $this->setExpectedException('PurpleCode\PCurl\PCurlException');

    // when
    $response = $cut->get('');
  }

}