1
|
|
|
<?php |
2
|
|
|
namespace OnurbTest\Bundle\YumlBundle\Curl; |
3
|
|
|
|
4
|
|
|
use Onurb\Bundle\YumlBundle\Curl\Curl; |
5
|
|
|
|
6
|
|
|
class CurlTest extends \PHPUnit_Framework_TestCase |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* @covers \Onurb\Bundle\YumlBundle\Curl\Curl |
10
|
|
|
*/ |
11
|
|
|
public function testIsInstanceOf() |
12
|
|
|
{ |
13
|
|
|
$testUrl = 'http://testUrl.test'; |
14
|
|
|
$curl = curl_init(); |
15
|
|
|
$curlClass = new Curl($testUrl, $curl); |
|
|
|
|
16
|
|
|
$this->assertInstanceOf('Onurb\\Bundle\\YumlBundle\\Curl\\CurlInterface', $curlClass); |
17
|
|
|
|
18
|
|
|
$this->assertSame($testUrl, curl_getinfo($curl, CURLINFO_EFFECTIVE_URL)); |
19
|
|
|
|
20
|
|
|
curl_close($curl); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @covers \Onurb\Bundle\YumlBundle\Curl\Curl |
25
|
|
|
* @expectedException \Exception |
26
|
|
|
*/ |
27
|
|
|
public function testResponseWithWrongUrl() |
28
|
|
|
{ |
29
|
|
|
$testUrl = 'http://localhost.test/url_that_doesnt_exists'; |
30
|
|
|
$curl = new Curl($testUrl); |
31
|
|
|
|
32
|
|
|
$curl->getResponse(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @covers \Onurb\Bundle\YumlBundle\Curl\Curl |
37
|
|
|
*/ |
38
|
|
|
public function testResponseWithCorrectUrl() |
39
|
|
|
{ |
40
|
|
|
$testUrl = 'http://yuml.me'; |
41
|
|
|
$curl = new Curl($testUrl); |
42
|
|
|
|
43
|
|
|
$response = $curl->getResponse(); |
44
|
|
|
$this->assertSame('<!DOCTYPE', explode(' ', $response)[0]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @covers \Onurb\Bundle\YumlBundle\Curl\Curl |
49
|
|
|
*/ |
50
|
|
|
public function testResponseWithPostData() |
51
|
|
|
{ |
52
|
|
|
$testUrl = 'http://yuml.me/diagram/plain/class'; |
53
|
|
|
$curl = new Curl($testUrl); |
54
|
|
|
|
55
|
|
|
$posts = array( |
56
|
|
|
'dsl_text' => '[Simple.Entity|+a;b;c]' |
57
|
|
|
); |
58
|
|
|
$curl->setPosts($posts); |
59
|
|
|
$response = $curl->getResponse(); |
60
|
|
|
|
61
|
|
|
$this->assertSame('15a98c92.png', $response); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @covers \Onurb\Bundle\YumlBundle\Curl\Curl |
66
|
|
|
*/ |
67
|
|
|
public function testDowloadFile() |
68
|
|
|
{ |
69
|
|
|
$fileUrl = 'http://yuml.me/15a98c92.png'; |
70
|
|
|
$fileName = 'test.png'; |
71
|
|
|
|
72
|
|
|
$this->assertFalse(file_exists($fileName)); |
73
|
|
|
|
74
|
|
|
$curl = new Curl($fileUrl); |
75
|
|
|
$curl->setOutput($fileName); |
76
|
|
|
$curl->getResponse(); |
77
|
|
|
|
78
|
|
|
$this->assertTrue(file_exists($fileName)); |
79
|
|
|
if (file_exists($fileName)) { |
80
|
|
|
unlink($fileName); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: