|
1
|
|
|
<?php |
|
2
|
|
|
namespace OnurbTest\Bundle\YumlBundle\Curl; |
|
3
|
|
|
|
|
4
|
|
|
use Onurb\Bundle\YumlBundle\Curl\Curl; |
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
class CurlTest extends TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @covers \Onurb\Bundle\YumlBundle\Curl\Curl |
|
11
|
|
|
*/ |
|
12
|
|
|
public function testIsInstanceOf() |
|
13
|
|
|
{ |
|
14
|
|
|
$testUrl = 'http://testUrl.test'; |
|
15
|
|
|
$curl = curl_init(); |
|
16
|
|
|
$curlClass = new Curl($testUrl, $curl); |
|
17
|
|
|
$this->assertInstanceOf('Onurb\\Bundle\\YumlBundle\\Curl\\CurlInterface', $curlClass); |
|
18
|
|
|
|
|
19
|
|
|
$this->assertSame($testUrl, curl_getinfo($curl, CURLINFO_EFFECTIVE_URL)); |
|
20
|
|
|
|
|
21
|
|
|
curl_close($curl); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @covers \Onurb\Bundle\YumlBundle\Curl\Curl |
|
26
|
|
|
* @expectedException \Exception |
|
27
|
|
|
*/ |
|
28
|
|
|
public function testResponseWithWrongUrl() |
|
29
|
|
|
{ |
|
30
|
|
|
$testUrl = 'http://localhost.test/url_that_doesnt_exists'; |
|
31
|
|
|
$curl = new Curl($testUrl); |
|
32
|
|
|
|
|
33
|
|
|
$curl->getResponse(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @covers \Onurb\Bundle\YumlBundle\Curl\Curl |
|
38
|
|
|
*/ |
|
39
|
|
|
public function testResponseWithCorrectUrl() |
|
40
|
|
|
{ |
|
41
|
|
|
$testUrl = 'https://yuml.me'; |
|
42
|
|
|
$curl = new Curl($testUrl); |
|
43
|
|
|
|
|
44
|
|
|
$response = $curl->getResponse(); |
|
45
|
|
|
$this->assertSame('<!DOCTYPE', explode(' ', $response)[0]); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @covers \Onurb\Bundle\YumlBundle\Curl\Curl |
|
50
|
|
|
*/ |
|
51
|
|
|
public function testResponseWithPostData() |
|
52
|
|
|
{ |
|
53
|
|
|
$testUrl = 'https://yuml.me/diagram/plain/class'; |
|
54
|
|
|
$curl = new Curl($testUrl); |
|
55
|
|
|
|
|
56
|
|
|
$posts = array( |
|
57
|
|
|
'dsl_text' => '[Simple.Entity|+a;b;c]' |
|
58
|
|
|
); |
|
59
|
|
|
$curl->setPosts($posts); |
|
60
|
|
|
$response = $curl->getResponse(); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertSame('15a98c92.png', $response); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @covers \Onurb\Bundle\YumlBundle\Curl\Curl |
|
67
|
|
|
*/ |
|
68
|
|
|
public function testDowloadFile() |
|
69
|
|
|
{ |
|
70
|
|
|
$fileUrl = 'https://yuml.me/15a98c92.png'; |
|
71
|
|
|
$fileName = 'test.png'; |
|
72
|
|
|
|
|
73
|
|
|
$this->assertFalse(file_exists($fileName)); |
|
74
|
|
|
|
|
75
|
|
|
$curl = new Curl($fileUrl); |
|
76
|
|
|
$curl->setOutput($fileName); |
|
77
|
|
|
$curl->getResponse(); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertTrue(file_exists($fileName)); |
|
80
|
|
|
if (file_exists($fileName)) { |
|
81
|
|
|
unlink($fileName); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|