PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.4
Booking for Appointments and Events Calendar – Amelia v2.4.4
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / apimatic / core / src / TestCase / HeadersMatcher.php
ameliabooking / vendor / apimatic / core / src / TestCase Last commit date
BodyMatchers 1 year ago CoreTestCase.php 1 year ago HeadersMatcher.php 1 year ago StatusCodeMatcher.php 1 year ago TestParam.php 1 year ago
HeadersMatcher.php
68 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Core\TestCase;
6
7 use PHPUnit\Framework\TestCase;
8
9 class HeadersMatcher
10 {
11 private $headers = [];
12 private $allowExtra = false;
13 private $testCase;
14 public function __construct(TestCase $testCase)
15 {
16 $this->testCase = $testCase;
17 }
18
19 /**
20 * Set an array of arrays, where inner arrays must be of length 2,
21 * i.e. index0 => headerValue, index1 => checkValueBool
22 *
23 * @param array<string,array> $headers
24 */
25 public function setHeaders(array $headers): void
26 {
27 $this->headers = $headers;
28 }
29
30 /**
31 * Sets allowExtra flag to true.
32 */
33 public function allowExtra(): void
34 {
35 $this->allowExtra = true;
36 }
37
38 /**
39 * Asserts if provided headers match according to the properties set within object.
40 */
41 public function assert(array $headers)
42 {
43 if (empty($this->headers)) {
44 return;
45 }
46
47 // Http headers are case-insensitive
48 $expected = array_change_key_case($this->headers);
49 $actual = array_change_key_case($headers);
50 $message = "Headers do not match";
51 if (!$this->allowExtra) {
52 $message = "$message strictly";
53 $this->testCase->assertCount(count($expected), $actual, $message);
54 }
55
56 $actualKeys = array_keys($actual);
57 array_walk($expected, function ($valueArray, $key) use ($actual, $actualKeys, $message): void {
58 $this->testCase->assertTrue(in_array($key, $actualKeys, true), $message);
59 if (!is_bool($valueArray[1])) {
60 return;
61 }
62 if ($valueArray[1]) {
63 $this->testCase->assertEquals($valueArray[0], $actual[$key], $message);
64 }
65 });
66 }
67 }
68