summaryrefslogtreecommitdiffstats
path: root/test/PJsonCurlTest.php
blob: 80f765dcfcda295cba4d0e502756e65422041ad7 (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
<?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 {

  private function getCACertBundlePath() {
    return __DIR__.'\ca-cert.crt';
  }

  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('');
  }
}