CrashTester   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 3
eloc 27
c 4
b 1
f 0
dl 0
loc 64
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 46 2
A getSubDir() 0 3 1
1
<?php
2
3
namespace HtaccessCapabilityTester\Testers;
4
5
use \HtaccessCapabilityTester\TestResult;
6
7
/**
8
 * Class for testing if a .htaccess results in a 500 Internal Server Error
9
 * (ie due to being malformed or containing directives that are unknown or not allowed)
10
 *
11
 * Notes:
12
 * - The tester only reports failure on a 500 Internal Server Error. All other status codes (even server errors)
13
 *       are treated as a success. The assumption here is that malformed .htaccess files / .htaccess
14
 *       files containing unknown or disallowed directives always results in a 500
15
 * - If your purpose is to test if a request succeeds (response 200 Ok), you should create your own class.
16
 *       (note that if you want to ensure that a php will succeed, make sure that a php is requested)
17
 *
18
 * @package    HtaccessCapabilityTester
19
 * @author     Bjørn Rosell <[email protected]>
20
 * @since      Class available since 0.7
21
 */
22
class CrashTester extends CustomTester
23
{
24
25
    /**
26
     * @param string $htaccessRules  The rules to check
27
     * @param string $subSubDir      subdir for the test files. If not supplied, a fingerprint of the rules will be used
28
     */
29 10
    public function __construct($htaccessRules, $subSubDir = null)
30
    {
31 10
        if (is_null($subSubDir)) {
32 3
            $subSubDir = hash('md5', $htaccessRules);
33
        }
34
35
        $test = [
36 10
            'subdir' => 'crash-tester/' . $subSubDir,
37
            'subtests' => [
38
                [
39 10
                    'subdir' => 'the-suspect',
40
                    'files' => [
41 10
                        ['.htaccess', $htaccessRules],
42
                        ['request-me.txt', 'thanks'],
43
                    ],
44
                    'request' => [
45
                        'url' => 'request-me.txt',
46
                        'bypass-standard-error-handling' => ['403', '404', '500']
47
                    ],
48
                    'interpretation' => [
49
                        ['success', 'status-code', 'not-equals', '500'],
50
                        // Otherwise fall through to next subtest
51
                    ]
52
                ],
53
                [
54
                    'subdir' => 'the-innocent',
55
                    'files' => [
56
                        ['.htaccess', '# I am no trouble'],
57
                        ['request-me.txt', 'thanks'],
58
                    ],
59
                    'request' => [
60
                        'url' => 'request-me.txt',
61
                        'bypass-standard-error-handling' => ['403', '404', '500']
62
                    ],
63
                    'interpretation' => [
64
                        // The suspect crashed. But if the innocent crashes too, we cannot judge
65
                        ['inconclusive', 'status-code', 'equals', '500'],
66
67
                        // The innocent did not crash. The suspect is guilty!
68
                        ['failure'],
69
                    ]
70
                ],
71
            ]
72
        ];
73
74 10
        parent::__construct($test);
75 10
    }
76
77
    /**
78
     * Child classes must implement this method, which tells which subdir the
79
     * test files are to be put.
80
     *
81
     * @return  string  A subdir for the test files
82
     */
83 10
    public function getSubDir()
84
    {
85 10
        return 'crash-tester';
86
    }
87
}
88