Passed
Push — master ( c4e8d5...9061ac )
by Eric
02:13
created

MethodsTest::testNoneEmpty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Utility - Collection of various PHP utility functions.
7
 *
8
 * @author    Eric Sizemore <[email protected]>
9
 * @version   2.0.0
10
 * @copyright (C) 2017 - 2024 Eric Sizemore
11
 * @license   The MIT License (MIT)
12
 *
13
 * Copyright (C) 2017 - 2024 Eric Sizemore <https://www.secondversion.com>.
14
 *
15
 * Permission is hereby granted, free of charge, to any person obtaining a copy
16
 * of this software and associated documentation files (the "Software"), to
17
 * deal in the Software without restriction, including without limitation the
18
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
19
 * sell copies of the Software, and to permit persons to whom the Software is
20
 * furnished to do so, subject to the following conditions:
21
 *
22
 * The above copyright notice and this permission notice shall be included in
23
 * all copies or substantial portions of the Software.
24
 *
25
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31
 * THE SOFTWARE.
32
 */
33
34
namespace Esi\Utility\Tests\Enums\Http;
35
36
use Esi\Utility\Enums\Http\Methods;
37
use PHPUnit\Framework\TestCase;
38
use PHPUnit\Framework\Attributes\CoversClass;
39
40
/**
41
 * Methods enum tests.
42
 */
43
#[CoversClass(Methods::class)]
44
class MethodsTest extends TestCase
45
{
46
    /**
47
     * Holds all cases of the Methods enum.
48
     *
49
     * @var array<int, Methods>
50
     */
51
    protected array $methods;
52
53
    /**
54
     * Build the $methods array.
55
     */
56
    #[\Override]
57
    public function setUp(): void
58
    {
59
        $this->methods = Methods::cases();
60
    }
61
62
    /**
63
     * Simple, perhaps unnecessary, test to make sure no empty values.
64
     */
65
    public function testNoneEmpty(): void
66
    {
67
        self::assertNotEmpty($this->methods);
68
69
        foreach ($this->methods as $method) {
70
            self::assertNotEmpty($method->getValue());
71
        }
72
    }
73
74
    /**
75
     * Test the isSafe() method.
76
     */
77
    public function testIsSafe(): void
78
    {
79
        static $safe = [
80
            Methods::GET->getValue(),
81
            Methods::HEAD->getValue(),
82
            Methods::OPTIONS->getValue(),
83
            Methods::PRI->getValue(),
84
            Methods::PROPFIND->getValue(),
85
            Methods::REPORT->getValue(),
86
            Methods::SEARCH->getValue(),
87
            Methods::TRACE->getValue(),
88
        ];
89
90
        foreach ($this->methods as $method) {
91
            if (in_array($method->getName(), $safe, true)) {
92
                self::assertTrue($method->isSafe());
93
            } else {
94
                self::assertFalse($method->isSafe());
95
            }
96
        }
97
    }
98
99
    /**
100
     * Test the isIdempotent() method.
101
     */
102
    public function testIsIdempotent(): void
103
    {
104
        static $notIdempotent = [
105
            Methods::CONNECT->getValue(),
106
            Methods::LOCK->getValue(),
107
            Methods::PATCH->getValue(),
108
            Methods::POST->getValue(),
109
        ];
110
111
        foreach ($this->methods as $method) {
112
            if (in_array($method->getName(), $notIdempotent, true)) {
113
                self::assertFalse($method->isIdempotent());
114
            } else {
115
                self::assertTrue($method->isIdempotent());
116
            }
117
        }
118
    }
119
}
120