| Total Complexity | 9 |
| Total Lines | 146 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 6 | class AddressTest extends Unit |
||
| 7 | { |
||
| 8 | /** |
||
| 9 | * Key - input data (absolute url) |
||
| 10 | * Value - relative part of url |
||
| 11 | * @var array |
||
| 12 | */ |
||
| 13 | private $data = [ |
||
| 14 | 'http://domain.ru:80/index.php?param=1#anchor' => '/index.php?param=1#anchor', |
||
| 15 | 'http://domain.ru:80/index.php?param=1' => '/index.php?param=1', |
||
| 16 | 'http://domain.ru:80/index.php' => '/index.php', |
||
| 17 | 'http://domain.ru:80/' => '/', |
||
| 18 | ]; |
||
| 19 | |||
| 20 | public function testUrl() |
||
| 21 | { |
||
| 22 | foreach ($this->data as $abs => $rel) { |
||
| 23 | $address = new Address($abs); |
||
| 24 | $this->assertEquals($abs, $address->abs()); |
||
| 25 | $this->assertEquals($rel, $address->rel()); |
||
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | public function testCustom() |
||
| 30 | { |
||
| 31 | $address = new Address('http://domain.ru:80/index.php?param=1#anchor'); |
||
| 32 | |||
| 33 | $a = clone $address; |
||
| 34 | $a->scheme = null; |
||
| 35 | $this->assertEquals('/index.php?param=1#anchor', $a->abs()); |
||
| 36 | |||
| 37 | $a = clone $address; |
||
| 38 | $a->host = null; |
||
| 39 | $this->assertEquals('/index.php?param=1#anchor', $a->abs()); |
||
| 40 | |||
| 41 | $a = clone $address; |
||
| 42 | $a->port = null; |
||
| 43 | $this->assertEquals('http://domain.ru/index.php?param=1#anchor', $a->abs()); |
||
| 44 | |||
| 45 | $a = clone $address; |
||
| 46 | $a->path = null; |
||
| 47 | $this->assertEquals('http://domain.ru:80/?param=1#anchor', $a->abs()); |
||
| 48 | |||
| 49 | $a = clone $address; |
||
| 50 | $a->query = null; |
||
| 51 | $this->assertEquals('http://domain.ru:80/index.php#anchor', $a->abs()); |
||
| 52 | |||
| 53 | $a = clone $address; |
||
| 54 | $a->fragment = null; |
||
| 55 | $this->assertEquals('http://domain.ru:80/index.php?param=1', $a->abs()); |
||
| 56 | } |
||
| 57 | |||
| 58 | public function testScheme() |
||
| 72 | } |
||
| 73 | |||
| 74 | public function testHost() |
||
| 75 | { |
||
| 76 | $a = new Address(''); |
||
| 77 | |||
| 78 | $a->host = 'http'; $this->assertEquals('http', $a->host); |
||
| 79 | $a->host = []; $this->assertEquals('http', $a->host); |
||
|
1 ignored issue
–
show
|
|||
| 80 | $a->host = true; $this->assertEquals('http', $a->host); |
||
| 81 | $a->host = ''; $this->assertNull($a->host); |
||
| 82 | $a->host = 'http'; |
||
| 83 | $a->host = false; $this->assertNull($a->host); |
||
| 84 | $a->host = 'http'; |
||
| 85 | $a->host = null; $this->assertNull($a->host); |
||
| 86 | $a->host = 'http'; |
||
| 87 | $a->host = 0; $this->assertNull($a->host); |
||
| 88 | } |
||
| 89 | |||
| 90 | public function testPort() |
||
| 91 | { |
||
| 92 | $a = new Address(''); |
||
| 93 | |||
| 94 | $a->port = 80; $this->assertEquals(80, $a->port); |
||
| 95 | $a->port = 'http'; $this->assertNull($a->port); |
||
|
1 ignored issue
–
show
|
|||
| 96 | $a->port = 80; |
||
| 97 | $a->port = []; $this->assertNull($a->port); |
||
| 98 | $a->port = true; $this->assertEquals(1, $a->port); |
||
| 99 | $a->port = false; $this->assertNull($a->port); |
||
| 100 | $a->port = 80; |
||
| 101 | $a->port = null; $this->assertNull($a->port); |
||
| 102 | $a->port = 80; |
||
| 103 | $a->port = 0; $this->assertNull($a->port); |
||
| 104 | } |
||
| 105 | |||
| 106 | public function testPath() |
||
| 107 | { |
||
| 108 | $a = new Address(''); |
||
| 109 | |||
| 110 | $a->path = 'http'; $this->assertEquals('http', $a->path); |
||
| 111 | $a->path = []; $this->assertEquals('http', $a->path); |
||
|
1 ignored issue
–
show
|
|||
| 112 | $a->path = true; $this->assertEquals('http', $a->path); |
||
| 113 | $a->path = ''; $this->assertNull($a->path); |
||
| 114 | $a->path = 'http'; |
||
| 115 | $a->path = false; $this->assertNull($a->path); |
||
| 116 | $a->path = 'http'; |
||
| 117 | $a->path = null; $this->assertNull($a->path); |
||
| 118 | $a->path = 'http'; |
||
| 119 | $a->path = 0; $this->assertNull($a->path); |
||
| 120 | } |
||
| 121 | |||
| 122 | public function testQuery() |
||
| 123 | { |
||
| 124 | $a = new Address(''); |
||
| 125 | $array = ['q' => 1]; |
||
| 126 | |||
| 127 | $a->query = $array; $this->assertEquals($array, $a->query); |
||
| 128 | $a->query = true; $this->assertEquals($array, $a->query); |
||
|
1 ignored issue
–
show
|
|||
| 129 | $a->query = 'q=2'; $this->assertEquals($array, $a->query); |
||
| 130 | $a->query = ''; $this->assertEquals([], $a->query); |
||
| 131 | $a->query = $array; |
||
| 132 | $a->query = false; $this->assertEquals([], $a->query); |
||
| 133 | $a->query = $array; |
||
| 134 | $a->query = null; $this->assertEquals([], $a->query); |
||
| 135 | $a->query = $array; |
||
| 136 | $a->query = 0; $this->assertEquals([], $a->query); |
||
| 137 | } |
||
| 138 | |||
| 139 | public function testFragment() |
||
| 152 | } |
||
| 153 | } |
||
| 154 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..