GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 3.x ( d805b4...27c796 )
by Jindřich
01:53
created

IsMaintenanceTest.php ➔ get_headers()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 8
nop 1
dl 0
loc 30
rs 9.1288
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Mocks built-in get_headers function
5
 */
6
namespace Skautis\Wsdl;
7
8
$GLOBALS['callNumber'] = 0;
9
10
function get_headers(string $url){
0 ignored issues
show
Unused Code introduced by
The parameter $url is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
11
12
  try {
13
    // Pro testNotMaintenance
14
    if ($GLOBALS['callNumber'] === 0) {
15
      return ['HTTP/1.1 200 OK'];
16
    }
17
18
    // Pro testMaintenance
19
    if ($GLOBALS['callNumber'] === 1) {
20
      return ['HTTP/1.1 503 Service Unavailable'];
21
    }
22
23
    // Pro testMaintenanceNoHeaders
24
    if ($GLOBALS['callNumber'] === 2) {
25
      return false;
26
    }
27
28
    // Pro testDNSError
29
    if ($GLOBALS['callNumber'] === 3) {
30
      trigger_error(
31
        'get_headers(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution',
32
        E_USER_WARNING
33
      );
34
    }
35
  }
36
  finally {
37
    $GLOBALS['callNumber']++;
38
  }
39
}
40
41
42
namespace Test\Skautis;
43
44
use Mockery;
45
use PHPUnit_Framework_TestCase;
46
use Skautis\Config;
47
use Skautis\Wsdl\MaintenanceErrorException;
48
use Skautis\Wsdl\WebServiceFactoryInterface;
49
use Skautis\Wsdl\WebServiceName;
50
use Skautis\Wsdl\WsdlManager;
51
use Skautis\Wsdl\WebServiceInterface;
52
53
class IsMaintenanceTest extends PHPUnit_Framework_TestCase
54
{
55
56
  /**
57
   * @var WsdlManager
58
   */
59
  private $manager;
60
61
  protected function setUp()
62
  {
63
    $factory = Mockery::mock(WebServiceFactoryInterface::class);
64
    $config = new Config('42');
65
    $this->manager = new WsdlManager($factory, $config);
66
  }
67
68
  /**
69
   * Když get_headers vrátí pole obsahující HTTP status code OK
70
   */
71
  public function testNotMaintenance(): void {
72
    $this->assertFalse($this->manager->isMaintenance());
73
  }
74
75
  /**
76
   * Když get_headers vráti pole neobsahující HTTP status code OK
77
   *
78
   * @depends testNotMaintenance
79
   */
80
  public function testMaintenance(): void {
81
    $this->assertTrue($this->manager->isMaintenance());
82
  }
83
84
  /**
85
   * Když get_headers vrátí false místo pole
86
   *
87
   * @depends testNotMaintenance
88
   */
89
  public function testMaintenanceNoHeaders(): void {
90
    $this->assertTrue($this->manager->isMaintenance());
91
  }
92
93
  /**
94
   * Když get_headers způsobí PHP Warning
95
   *
96
   * @depends testMaintenanceNoHeaders
97
   */
98
  public function testDNSError(): void {
99
    $this->expectException(MaintenanceErrorException::class);
100
    $this->manager->isMaintenance();
101
  }
102
}
103
104