Issues (76)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Logging/JUnit/Reader.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
namespace ParaTest\Logging\JUnit;
6
7
use ParaTest\Logging\MetaProvider;
8
9
class Reader extends MetaProvider
10
{
11
    /**
12
     * @var \SimpleXMLElement
13
     */
14
    protected $xml;
15
16
    /**
17
     * @var bool
18
     */
19
    protected $isSingle = false;
20
21
    /**
22
     * @var array
23
     */
24
    protected $suites = [];
25
26
    /**
27
     * @var string
28
     */
29
    protected $logFile;
30
31
    /**
32
     * @var array
33
     */
34
    protected static $defaultSuite = [
35
        'name' => '',
36
        'file' => '',
37
        'tests' => 0,
38
        'assertions' => 0,
39
        'failures' => 0,
40
        'errors' => 0,
41
        'skipped' => 0,
42
        'time' => 0,
43
    ];
44
45 55
    public function __construct(string $logFile)
46
    {
47 55
        if (!file_exists($logFile)) {
48 1
            throw new \InvalidArgumentException("Log file $logFile does not exist");
49
        }
50
51 55
        $this->logFile = $logFile;
52 55
        if (filesize($logFile) === 0) {
53
            throw new \InvalidArgumentException("Log file $logFile is empty. This means a PHPUnit process has crashed.");
54
        }
55 55
        $logFileContents = file_get_contents($this->logFile);
56 55
        $this->xml = new \SimpleXMLElement($logFileContents);
57 55
        $this->init();
58 55
    }
59
60
    /**
61
     * Returns whether or not this reader contains only
62
     * a single suite.
63
     *
64
     * @return bool
65
     */
66 2
    public function isSingleSuite(): bool
67
    {
68 2
        return $this->isSingle;
69
    }
70
71
    /**
72
     * Return the Reader's collection
73
     * of test suites.
74
     *
75
     * @return array
76
     */
77 16
    public function getSuites(): array
78
    {
79 16
        return $this->suites;
80
    }
81
82
    /**
83
     * Return an array that contains
84
     * each suite's instant feedback. Since
85
     * logs do not contain skipped or incomplete
86
     * tests this array will contain any number of the following
87
     * characters: .,F,E
88
     * TODO: Update this, skipped was added in phpunit.
89
     *
90
     * @return array
91
     */
92 12
    public function getFeedback(): array
93
    {
94 12
        $feedback = [];
95 12
        $suites = $this->isSingle ? $this->suites : $this->suites[0]->suites;
96 12
        foreach ($suites as $suite) {
97 12
            foreach ($suite->cases as $case) {
98 12
                if ($case->failures) {
99 8
                    $feedback[] = 'F';
100 12
                } elseif ($case->errors) {
101 9
                    $feedback[] = 'E';
102 12
                } elseif ($case->skipped) {
103
                    $feedback[] = 'S';
104
                } else {
105 12
                    $feedback[] = '.';
106
                }
107
            }
108
        }
109
110 12
        return $feedback;
111
    }
112
113
    /**
114
     * Remove the JUnit xml file.
115
     */
116 3
    public function removeLog()
117
    {
118 3
        unlink($this->logFile);
119 3
    }
120
121
    /**
122
     * Initialize the suite collection
123
     * from the JUnit xml document.
124
     */
125 55
    protected function init()
126
    {
127 55
        $this->initSuite();
128 55
        $cases = $this->getCaseNodes();
129 55
        foreach ($cases as $file => $nodeArray) {
130 55
            $this->initSuiteFromCases($nodeArray);
131
        }
132 55
    }
133
134
    /**
135
     * Uses an array of testcase nodes to build a suite.
136
     *
137
     * @param array $nodeArray an array of SimpleXMLElement nodes representing testcase elements
138
     */
139 55
    protected function initSuiteFromCases(array $nodeArray)
140
    {
141 55
        $testCases = [];
142 55
        $properties = $this->caseNodesToSuiteProperties($nodeArray, $testCases);
143 55
        if (!$this->isSingle) {
144 44
            $this->addSuite($properties, $testCases);
145
        } else {
146 51
            $this->suites[0]->cases = $testCases;
147
        }
148 55
    }
149
150
    /**
151
     * Creates and adds a TestSuite based on the given
152
     * suite properties and collection of test cases.
153
     *
154
     * @param $properties
155
     * @param $testCases
156
     */
157 44
    protected function addSuite($properties, array $testCases)
158
    {
159 44
        $suite = TestSuite::suiteFromArray($properties);
160 44
        $suite->cases = $testCases;
161 44
        $this->suites[0]->suites[] = $suite;
162 44
    }
163
164
    /**
165
     * Fold an array of testcase nodes into a suite array.
166
     *
167
     * @param array $nodeArray an array of testcase nodes
168
     * @param array $testCases an array reference. Individual testcases will be placed here.
169
     *
170
     * @return mixed
171
     */
172 55
    protected function caseNodesToSuiteProperties(array $nodeArray, array &$testCases = [])
173
    {
174 55
        $cb = [TestCase::class, 'caseFromNode'];
175
176 55
        return array_reduce($nodeArray, function ($result, $c) use (&$testCases, $cb) {
177 55
            $testCases[] = call_user_func_array($cb, [$c]);
178 55
            $result['name'] = (string) $c['class'];
179 55
            $result['file'] = (string) $c['file'];
180 55
            $result['tests'] = $result['tests'] + 1;
181 55
            $result['assertions'] += (int) $c['assertions'];
182 55
            $result['failures'] += count($c->xpath('failure'));
183 55
            $result['errors'] += count($c->xpath('error'));
184 55
            $result['skipped'] += count($c->xpath('skipped'));
185 55
            $result['time'] += (float) ($c['time']);
186
187 55
            return $result;
188 55
        }, static::$defaultSuite);
189
    }
190
191
    /**
192
     * Return a collection of testcase nodes
193
     * from the xml document.
194
     *
195
     * @return array
196
     */
197 55
    protected function getCaseNodes(): array
198
    {
199 55
        $caseNodes = $this->xml->xpath('//testcase');
200 55
        $cases = [];
201 55
        foreach ($caseNodes as $node) {
202 55
            $case = $node;
0 ignored issues
show
$case is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
203 55
            if (!isset($cases[(string) $node['file']])) {
204 55
                $cases[(string) $node['file']] = [];
205
            }
206 55
            $cases[(string) $node['file']][] = $node;
207
        }
208
209 55
        return $cases;
210
    }
211
212
    /**
213
     * Determine if this reader is a single suite
214
     * and initialize the suite collection with the first
215
     * suite.
216
     */
217 55
    protected function initSuite()
218
    {
219 55
        $suiteNodes = $this->xml->xpath('/testsuites/testsuite/testsuite');
220 55
        $this->isSingle = count($suiteNodes) === 0;
221 55
        $node = current($this->xml->xpath('/testsuites/testsuite'));
222
223 55
        if ($node !== false) {
224 55
            $this->suites[] = TestSuite::suiteFromNode($node);
225
        } else {
226 21
            $this->suites[] = TestSuite::suiteFromArray(self::$defaultSuite);
227
        }
228 55
    }
229
}
230