summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/PCurlTest.php25
-rw-r--r--test/PJsonCurlTest.php39
-rw-r--r--test/test.json1
-rw-r--r--test/testInvalid.json1
4 files changed, 53 insertions, 13 deletions
diff --git a/test/PCurlTest.php b/test/PCurlTest.php
index 841603a..566ad0f 100644
--- a/test/PCurlTest.php
+++ b/test/PCurlTest.php
@@ -6,39 +6,38 @@ use PurpleCode\PCurl\PCurl;
class PCurlTest extends PHPUnit_Framework_TestCase {
- private function getCACertBundlePath() {
- return __DIR__.'\ca-cert.crt';
- }
+ private function getCACertBundlePath() {
+ return __DIR__.'\ca-cert.crt';
+ }
public function testShouldGetGooglePageViaHttp() {
// given
- $cut = new PCurl('http://www.google.pl');
+ $cut = new PCurl('http://www.google.pl');
// when
$response = $cut->get('/');
-
// then
- $this->assertSelectRegExp('title', '/Google/', 1, $response);
+ $this->assertSelectRegExp('title', '/Google/', 1, $response->getBody());
}
- public function testShouldGetGooglePageAndCheckHttpsCertificate() {
+ public function testShouldGetGooglePageAndCheckHttpsCertificate() {
// given
- $cut = new PCurl('https://www.google.pl');
- $cut->useSSLCertificate($this->getCACertBundlePath());
+ $cut = new PCurl('https://www.google.pl');
+ $cut->useSSLCertificate($this->getCACertBundlePath());
// when
$response = $cut->get('/');
// then
- $this->assertSelectRegExp('title', '/Google/', 1, $response);
- }
+ $this->assertSelectRegExp('title', '/Google/', 1, $response->getBody());
+ }
public function testShouldGetGooglePageAndThrowExceptionOnMissingCertificate() {
// given
$cut = new PCurl('https://www.google.com');
- // then
- $this->setExpectedException('PurpleCode\PCurl\PCurlException');
+ // then
+ $this->setExpectedException('PurpleCode\PCurl\PCurlException');
// when
$response = $cut->get('/');
diff --git a/test/PJsonCurlTest.php b/test/PJsonCurlTest.php
new file mode 100644
index 0000000..8aec5b8
--- /dev/null
+++ b/test/PJsonCurlTest.php
@@ -0,0 +1,39 @@
+<?php
+
+
+require_once (dirname(__FILE__) . '/../src/PurpleCode/PCurl/PCurlResponse.php');
+require_once (dirname(__FILE__) . '/../src/PurpleCode/PCurl/PCurlJsonResponse.php');
+require_once (dirname(__FILE__) . '/../src/PurpleCode/PCurl/PCurl.php');
+require_once (dirname(__FILE__) . '/../src/PurpleCode/PCurl/PJsonCurl.php');
+
+use PurpleCode\PCurl\PJsonCurl;
+
+class PCurlTest extends PHPUnit_Framework_TestCase {
+
+ private function getCACertBundlePath() {
+ return __DIR__.'\ca-cert.crt';
+ }
+
+ public function testShouldGetJsonFileAndParse() {
+ // given
+ $cut = new PJsonCurl('file://test.json');
+
+ // when
+ $response = $cut->get('');
+
+ // then
+ $this->assertEquals(2, $response->getBody()->a->b);
+ $this->assertEquals("a", $response->getBody()->a->c);
+ }
+
+ public function testShouldFailParseWrongFile() {
+ // given
+ $cut = new PJsonCurl('file://testInvaliud.json');
+
+ //then
+ $this->setExpectedException('PurpleCode\PCurl\PCurlException');
+
+ // when
+ $response = $cut->get('');
+ }
+} \ No newline at end of file
diff --git a/test/test.json b/test/test.json
new file mode 100644
index 0000000..bb4ed6f
--- /dev/null
+++ b/test/test.json
@@ -0,0 +1 @@
+{"a":{"b":2,"c":"a"}} \ No newline at end of file
diff --git a/test/testInvalid.json b/test/testInvalid.json
new file mode 100644
index 0000000..8c548c8
--- /dev/null
+++ b/test/testInvalid.json
@@ -0,0 +1 @@
+{"a":3} \ No newline at end of file