Skip to content

Commit 191fedb

Browse files
committed
Fix PHP 7.0..7.3
1 parent 1007cae commit 191fedb

1 file changed

Lines changed: 31 additions & 28 deletions

File tree

src/test/php/web/unittest/filters/CORSTest.class.php

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,54 +18,57 @@ private function filter(CORS $fixture, $method, $uri, $headers= [], $body= null)
1818
return $res;
1919
}
2020

21+
/** Returns fixture with the origin set */
22+
private function fixture(): CORS {
23+
return (new CORS())->origins(self::ORIGIN);
24+
}
25+
2126
/** Values for preflight test */
2227
private function preflights(): iterable {
23-
$cors= (new CORS())->origins(self::ORIGIN);
24-
yield [$cors, []];
25-
yield [(clone $cors)->origins(fn($origin) => self::ORIGIN === $origin ? $origin : null), []];
26-
yield [(clone $cors)->origins('*'), ['Access-Control-Allow-Origin' => '*']];
28+
yield [$this->fixture(), []];
29+
yield [$this->fixture()->origins(fn($origin) => self::ORIGIN === $origin ? $origin : null), []];
30+
yield [$this->fixture()->origins('*'), ['Access-Control-Allow-Origin' => '*']];
2731

2832
// Methods
29-
yield [(clone $cors)->methods(null), []];
30-
yield [(clone $cors)->methods([]), []];
31-
yield [(clone $cors)->methods('GET, POST'), ['Access-Control-Allow-Methods' => 'GET, POST']];
32-
yield [(clone $cors)->methods(['GET', 'POST']), ['Access-Control-Allow-Methods' => 'GET, POST']];
33+
yield [$this->fixture()->methods(null), []];
34+
yield [$this->fixture()->methods([]), []];
35+
yield [$this->fixture()->methods('GET, POST'), ['Access-Control-Allow-Methods' => 'GET, POST']];
36+
yield [$this->fixture()->methods(['GET', 'POST']), ['Access-Control-Allow-Methods' => 'GET, POST']];
3337

3438
// Headers
35-
yield [(clone $cors)->headers(null), []];
36-
yield [(clone $cors)->headers([]), []];
37-
yield [(clone $cors)->headers('X-Input'), ['Access-Control-Allow-Headers' => 'X-Input']];
38-
yield [(clone $cors)->headers(['X-Input']), ['Access-Control-Allow-Headers' => 'X-Input']];
39+
yield [$this->fixture()->headers(null), []];
40+
yield [$this->fixture()->headers([]), []];
41+
yield [$this->fixture()->headers('X-Input'), ['Access-Control-Allow-Headers' => 'X-Input']];
42+
yield [$this->fixture()->headers(['X-Input']), ['Access-Control-Allow-Headers' => 'X-Input']];
3943

4044
// Age
41-
yield [(clone $cors)->maxAge(null), []];
42-
yield [(clone $cors)->maxAge(0), []];
43-
yield [(clone $cors)->maxAge(86400), ['Access-Control-Max-Age' => '86400']];
45+
yield [$this->fixture()->maxAge(null), []];
46+
yield [$this->fixture()->maxAge(0), []];
47+
yield [$this->fixture()->maxAge(86400), ['Access-Control-Max-Age' => '86400']];
4448

4549
// Expose
46-
yield [(clone $cors)->expose(null), []];
47-
yield [(clone $cors)->expose([]), []];
48-
yield [(clone $cors)->expose('X-Output'), ['Access-Control-Expose-Headers' => 'X-Output']];
49-
yield [(clone $cors)->expose(['X-Output']), ['Access-Control-Expose-Headers' => 'X-Output']];
50+
yield [$this->fixture()->expose(null), []];
51+
yield [$this->fixture()->expose([]), []];
52+
yield [$this->fixture()->expose('X-Output'), ['Access-Control-Expose-Headers' => 'X-Output']];
53+
yield [$this->fixture()->expose(['X-Output']), ['Access-Control-Expose-Headers' => 'X-Output']];
5054

5155
// Credentials
52-
yield [(clone $cors)->credentials(false), []];
53-
yield [(clone $cors)->credentials(true), ['Access-Control-Allow-Credentials' => 'true']];
56+
yield [$this->fixture()->credentials(false), []];
57+
yield [$this->fixture()->credentials(true), ['Access-Control-Allow-Credentials' => 'true']];
5458
}
5559

5660
/** Values for request test */
5761
private function requests(): iterable {
58-
$cors= (new CORS())->origins(self::ORIGIN);
59-
yield [$cors, []];
62+
yield [$this->fixture(), []];
6063

6164
// Only included in preflight
62-
yield [(clone $cors)->methods(['GET', 'POST']), []];
63-
yield [(clone $cors)->headers(['X-Input']), []];
64-
yield [(clone $cors)->maxAge(86400), []];
65+
yield [$this->fixture()->methods(['GET', 'POST']), []];
66+
yield [$this->fixture()->headers(['X-Input']), []];
67+
yield [$this->fixture()->maxAge(86400), []];
6568

6669
// Included in all requests
67-
yield [(clone $cors)->expose(['X-Output']), ['Access-Control-Expose-Headers' => 'X-Output']];
68-
yield [(clone $cors)->credentials(true), ['Access-Control-Allow-Credentials' => 'true']];
70+
yield [$this->fixture()->expose(['X-Output']), ['Access-Control-Expose-Headers' => 'X-Output']];
71+
yield [$this->fixture()->credentials(true), ['Access-Control-Allow-Credentials' => 'true']];
6972
}
7073

7174
/** Values for allowing_origin_with_any_4_digit_port */

0 commit comments

Comments
 (0)