Issues (5)

Security Analysis    no request data  

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

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/Listener/RiskyToFailedListener.php (2 issues)

Severity
1
<?php
2
namespace Yoanm\PhpUnitExtended\Listener;
3
4
use PHPUnit\Framework\AssertionFailedError;
5
use PHPUnit\Framework\CoveredCodeNotExecutedException;
6
use PHPUnit\Framework\InvalidCoversTargetException;
7
use PHPUnit\Framework\MissingCoversAnnotationException;
8
use PHPUnit\Framework\OutputError;
9
use PHPUnit\Framework\Test;
10
use PHPUnit\Framework\TestCase;
11
use PHPUnit\Framework\TestListener;
12
use PHPUnit\Framework\TestListenerDefaultImplementation;
13
use PHPUnit\Framework\TestResult;
14
use PHPUnit\Framework\UnintentionallyCoveredCodeError;
15
use PHPUnit\Framework\Warning;
16
17
/**
18
 * @see doc/listener/StrictCoverageListener.md
19
 */
20
class RiskyToFailedListener implements TestListener
0 ignored issues
show
Deprecated Code introduced by
The interface PHPUnit\Framework\TestListener has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

20
class RiskyToFailedListener implements /** @scrutinizer ignore-deprecated */ TestListener

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
21
{
22
    use TestListenerDefaultImplementation;
0 ignored issues
show
Deprecated Code introduced by
The trait PHPUnit\Framework\TestLi...erDefaultImplementation has been deprecated: The `TestListener` interface is deprecated ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

22
    use /** @scrutinizer ignore-deprecated */ TestListenerDefaultImplementation;

This trait has been deprecated. The supplier of the trait has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the trait will be removed and what other trait to use instead.

Loading history...
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 1
    public function addWarning(Test $test, Warning $e, float $time) : void
28
    {
29 1
        $this->addErrorIfNeeded($test, $e, $time);
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 11
    public function addRiskyTest(Test $test, \Throwable $exception, float $time) : void
36
    {
37 11
        $this->addErrorIfNeeded($test, $exception, $time);
38
    }
39
40 12
    protected function addErrorIfNeeded(Test $test, \Throwable $exception, $time)
41
    {
42
        /* Must be TestCase instance to have access to "getTestResultObject" method */
43 12
        if ($test instanceof TestCase) {
44 12
            if (!$test->getTestResultObject()) {
45 11
                $test->setTestResultObject(new TestResult());
46
            }
47 12
            $test->getTestResultObject()->addFailure(
48 12
                $test,
49 12
                new AssertionFailedError(
50 12
                    sprintf(
51 12
                        "Strict mode - %s :\n%s",
52 12
                        $this->getErrorReason($exception),
53 12
                        $exception->getMessage()
54 12
                    )
55 12
                ),
56 12
                $time
57 12
            );
58
        }
59
    }
60
61 12
    protected function getErrorReason(\Throwable $exception): string
62
    {
63 12
        if ($exception instanceof OutputError) {
64
            /* beStrictAboutOutputDuringTests="true" */
65 1
            return 'No output during test';
66 11
        } elseif ($exception instanceof UnintentionallyCoveredCodeError
67 11
            || $exception instanceof InvalidCoversTargetException
68
        ) {
69
            /* checkForUnintentionallyCoveredCode="true" */
70 2
            return 'Executed code must be defined with @covers and @uses annotations';
71 9
        } elseif (str_contains($exception->getMessage(), '--- Global variables before the test')) {
72
            /* beStrictAboutChangesToGlobalState="true" (no specific exception) for globals */
73 1
            return 'No global variable manipulation during test';
74 8
        } elseif (str_contains($exception->getMessage(), '--- Static attributes before the test')) {
75
            /* beStrictAboutChangesToGlobalState="true" (no specific exception) for static var */
76
            /* Only when beStrictAboutChangesToGlobalState="true" */
77 1
            return 'No static attribute manipulation during test';
78 7
        } elseif (str_contains($exception->getMessage(), 'This test did not perform any assertions')) {
79
            /* beStrictAboutTestsThatDoNotTestAnything="true" (no specific exception) */
80 1
            return 'No test that do not test anything';
81 6
        } elseif ($exception instanceof CoveredCodeNotExecutedException
82 6
            || preg_match('#"@covers [^"]+" is invalid#', $exception->getMessage())
83
        ) {
84
            /* forceCoversAnnotation="true" (no specific exception) */
85 4
            return 'Only executed code must be defined with @covers and @uses annotations';
86 2
        } elseif ($exception instanceof MissingCoversAnnotationException
87 2
            || str_contains(
88 2
                $exception->getMessage(),
89 2
                'This test does not have a @covers annotation but is expected to have one'
90 2
            )
91
        ) {
92
            /* forceCoversAnnotation="true" (no specific exception) */
93 1
            return 'Missing @covers or @coversNothing annotation';
94
        }
95
96
        // Always return an error even if it's not a known/managed error
97 1
        return $exception->getMessage();
98
    }
99
}
100