Passed
Push — master ( 9e3a16...830a01 )
by Ax
09:07
created

SleeperAvatarTest::remoteFileExists()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 22
rs 9.9332
1
<?php
2
3
use PHPUnit\Framework\TestCase;
4
use SchoppAx\Sleeper\SleeperClient;
5
use SchoppAx\Sleeper\Api\Avatars;
6
7
class SleeperAvatarTest extends TestCase
8
{
9
10
  private function remoteFileExists($url) {
11
    $curl = curl_init($url);
12
13
    //don't fetch the actual page, you only want to check the connection is ok
14
    curl_setopt($curl, CURLOPT_NOBODY, true);
15
16
    $result = curl_exec($curl);
17
    $ret = false;
18
19
    //if request did not fail
20
    if ($result !== false) {
21
      //if request was ok, check response code
22
      $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
23
24
      if ($statusCode == 200) {
25
        $ret = true;
26
      }
27
    }
28
29
    curl_close($curl);
30
31
    return $ret;
32
  }
33
34
  public function testAvatar()
35
  {
36
    $client = new SleeperClient();
37
38
    $url = $client->avatars()->find('79f5f8ecdd59fe94b668993366552b3a');
0 ignored issues
show
Bug introduced by
The method avatars() does not exist on SchoppAx\Sleeper\SleeperClient. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
    $url = $client->/** @scrutinizer ignore-call */ avatars()->find('79f5f8ecdd59fe94b668993366552b3a');
Loading history...
39
    $exists = $this->remoteFileExists($url);
40
41
    $this->assertIsBool($exists);
42
    $this->assertEquals($exists, true);
43
  }
44
45
}
46