Issues (32)

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/Adapters/Phpunit/State.php (2 issues)

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
/**
4
 * This file is part of Collision.
5
 *
6
 * (c) Nuno Maduro <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 */
11
12
namespace NunoMaduro\Collision\Adapters\Phpunit;
13
14
use NunoMaduro\Collision\Contracts\Adapters\Phpunit\HasPrintableTestCaseName;
15
use PHPUnit\Framework\TestCase;
16
17
/**
18
 * @internal
19
 */
20
final class State
21
{
22
    /**
23
     * The complete test suite number of tests.
24
     *
25
     * @var int|null
26
     */
27
    public $suiteTotalTests;
28
29
    /**
30
     * The complete test suite tests.
31
     *
32
     * @var array<int, TestResult>
33
     */
34
    public $suiteTests = [];
35
36
    /**
37
     * The current test case class.
38
     *
39
     * @var string
40
     */
41
    public $testCaseName;
42
43
    /**
44
     * The current test case tests.
45
     *
46
     * @var array<int, TestResult>
47
     */
48
    public $testCaseTests = [];
49
50
    /**
51
     * The state constructor.
52
     */
53 3
    private function __construct(string $testCaseName)
54
    {
55 3
        $this->testCaseName = $testCaseName;
56 3
    }
57
58
    /**
59
     * Creates a new State starting from the given test case.
60
     */
61 3
    public static function from(TestCase $test): self
62
    {
63 3
        return new self(self::getPrintableTestCaseName($test));
64
    }
65
66
    /**
67
     * Adds the given test to the State.
68
     */
69
    public function add(TestResult $test): void
70
    {
71
        $this->testCaseTests[] = $test;
72
73
        $this->suiteTests[] = $test;
74
    }
75
76
    /**
77
     * Gets the test case title.
78
     */
79 View Code Duplication
    public function getTestCaseTitle(): string
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81
        foreach ($this->testCaseTests as $test) {
82
            if ($test->type === TestResult::FAIL) {
83
                return 'FAIL';
84
            }
85
        }
86
87
        foreach ($this->testCaseTests as $test) {
88
            if ($test->type !== TestResult::PASS) {
89
                return 'WARN';
90
            }
91
        }
92
93
        return 'PASS';
94
    }
95
96
    /**
97
     * Gets the test case title color.
98
     */
99 View Code Duplication
    public function getTestCaseTitleColor(): string
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
    {
101
        foreach ($this->testCaseTests as $test) {
102
            if ($test->type === TestResult::FAIL) {
103
                return 'red';
104
            }
105
        }
106
107
        foreach ($this->testCaseTests as $test) {
108
            if ($test->type !== TestResult::PASS) {
109
                return 'yellow';
110
            }
111
        }
112
113
        return 'green';
114
    }
115
116
    /**
117
     * Returns the number of tests on the current test case.
118
     */
119
    public function testCaseTestsCount(): int
120
    {
121
        return count($this->testCaseTests);
122
    }
123
124
    /**
125
     * Returns the number of tests on the complete test suite.
126
     */
127
    public function testSuiteTestsCount(): int
128
    {
129
        return count($this->suiteTests);
130
    }
131
132
    /**
133
     * Checks if the given test case is different from the current one.
134
     */
135
    public function testCaseHasChanged(TestCase $testCase): bool
136
    {
137
        return self::getPrintableTestCaseName($testCase) !== $this->testCaseName;
138
    }
139
140
    /**
141
     * Moves the a new test case.
142
     */
143
    public function moveTo(TestCase $testCase): void
144
    {
145
        $this->testCaseName = self::getPrintableTestCaseName($testCase);
146
147
        $this->testCaseTests = [];
148
    }
149
150
    /**
151
     * Foreach test in the test case.
152
     */
153
    public function eachTestCaseTests(callable $callback): void
154
    {
155
        foreach ($this->testCaseTests as $test) {
156
            $callback($test);
157
        }
158
    }
159
160
    public function countTestsInTestSuiteBy(string $type): int
161
    {
162
        return count(array_filter($this->suiteTests, function (TestResult $testResult) use ($type) {
163
            return $testResult->type === $type;
164
        }));
165
    }
166
167
    /**
168
     * Checks if the given test already contains a result.
169
     */
170
    public function existsInTestCase(TestCase $test): bool
171
    {
172
        foreach ($this->testCaseTests as $testResult) {
173
            if (TestResult::makeDescription($test) === $testResult->description) {
174
                return true;
175
            }
176
        }
177
178
        return false;
179
    }
180
181
    /**
182
     * Returns the printable test case name from the given `TestCase`.
183
     */
184 3
    private static function getPrintableTestCaseName(TestCase $test): string
185
    {
186 3
        if ($test instanceof HasPrintableTestCaseName) {
187
            $name = $test->getPrintableTestCaseName();
188
        } else {
189 3
            $name = get_class($test);
190
        }
191
192 3
        return $name;
193
    }
194
}
195