Issues (9)

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/Extra/PDOWrapperTest.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace QB\Extra;
6
7
use PDO;
8
use PDOStatement;
9
use PHPUnit\Framework\MockObject\MockObject;
10
use PHPUnit\Framework\TestCase;
11
use QB\Generic\Expr\Expr;
12
13
class PDOWrapperTest extends TestCase
14
{
15
    /** @var PDOWrapper System Under Test */
16
    protected PDOWrapper $sut;
17
18
    /** @var PDO|MockObject */
19
    protected PDO|MockObject $pdoMock;
20
21
    /**
22
     * @suppress PhanTypeMismatchArgument
23
     */
24
    public function setUp(): void
25
    {
26
        /** @var PDO $pdoMock */
27
        $pdoMock = $this->getMockBuilder(PDO::class)
28
            ->disableOriginalConstructor()
29
            ->getMock();
30
31
        $this->pdoMock = $pdoMock;
32
        $this->sut = new PDOWrapper($pdoMock);
33
    }
34
35
    /**
36
     * @suppress PhanTypeMismatchArgumentProbablyReal
37
     */
38
    public function testPrepareNumeric()
39
    {
40
        $sql    = '? AND ?';
41
        $values = [17, 23];
42
43
        $statementMock = $this->getMockBuilder(PDOStatement::class)->getMock();
44
        $statementMock
45
            ->expects($this->exactly(count($values)))
46
            ->method('bindParam')
47
            ->withConsecutive([1, 17, PDO::PARAM_INT], [2, 23, PDO::PARAM_INT]);
48
49
        $this->pdoMock->expects($this->once())->method('prepare')->with($sql)->willReturn($statementMock);
0 ignored issues
show
The method expects() does not exist on PDO. ( Ignorable by Annotation )

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

49
        $this->pdoMock->/** @scrutinizer ignore-call */ 
50
                        expects($this->once())->method('prepare')->with($sql)->willReturn($statementMock);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
51
        $query = new Expr($sql, $values);
52
53
        $this->sut->prepare($query);
54
    }
55
56
    /**
57
     * @suppress PhanTypeMismatchArgumentProbablyReal
58
     */
59
    public function testPrepareAssoc()
60
    {
61
        $sql    = ':foo AND :bar';
62
        $values = ['foo' => 'bar', 'bar' => 'baz'];
63
64
        $statementMock = $this->getMockBuilder(PDOStatement::class)->getMock();
65
        $statementMock
66
            ->expects($this->exactly(count($values)))
67
            ->method('bindParam')
68
            ->withConsecutive(['foo', 'bar', PDO::PARAM_STR], ['bar', 'baz', PDO::PARAM_STR]);
69
70
        $this->pdoMock->expects($this->once())->method('prepare')->with($sql)->willReturn($statementMock);
71
72
        $query = new Expr($sql, $values);
73
74
        $this->sut->prepare($query);
75
    }
76
77
    /**
78
     * @suppress PhanTypeMismatchArgumentProbablyReal
79
     */
80
    public function testExecute()
81
    {
82
        $returnValue = true;
83
84
        $sql    = ':foo AND :bar';
85
        $values = ['foo' => 'bar', 'bar' => 'baz'];
86
87
        $statementMock = $this->getMockBuilder(PDOStatement::class)->getMock();
88
        $statementMock
89
            ->expects($this->exactly(count($values)))
90
            ->method('bindParam')
91
            ->withConsecutive(['foo', 'bar', PDO::PARAM_STR], ['bar', 'baz', PDO::PARAM_STR]);
92
        $statementMock
93
            ->expects($this->once())
94
            ->method('execute')
95
            ->willReturn($returnValue);
96
97
        $this->pdoMock->expects($this->once())->method('prepare')->with($sql)->willReturn($statementMock);
98
99
        $query = new Expr($sql, $values);
100
101
        $actualValue = $this->sut->execute($query);
102
103
        $this->assertSame($returnValue, $actualValue);
104
    }
105
106
    /**
107
     * @suppress PhanTypeMismatchArgumentProbablyReal
108
     */
109
    public function testFetchAll()
110
    {
111
        $returnValue = [['foo', 'bar'], ['bar', 'baz']];
112
113
        $sql    = ':foo AND :bar';
114
        $values = ['foo' => 'bar', 'bar' => 'baz'];
115
116
        $statementMock = $this->getMockBuilder(PDOStatement::class)->getMock();
117
        $statementMock
118
            ->expects($this->exactly(count($values)))
119
            ->method('bindParam')
120
            ->withConsecutive(['foo', 'bar', PDO::PARAM_STR], ['bar', 'baz', PDO::PARAM_STR]);
121
        $statementMock
122
            ->expects($this->once())
123
            ->method('execute')
124
            ->willReturn(true);
125
        $statementMock
126
            ->expects($this->once())
127
            ->method('fetchAll')
128
            ->willReturn($returnValue);
129
130
        $this->pdoMock->expects($this->once())->method('prepare')->with($sql)->willReturn($statementMock);
131
132
        $query = new Expr($sql, $values);
133
134
        $actualValue = $this->sut->fetchAll($query);
135
136
        $this->assertSame($returnValue, $actualValue);
137
    }
138
139
    /**
140
     * @suppress PhanTypeMismatchArgumentProbablyReal
141
     */
142
    public function testFetchColumn()
143
    {
144
        $returnValue = 123;
145
146
        $sql    = ':foo AND :bar';
147
        $values = ['foo' => 'bar', 'bar' => 'baz'];
148
149
        $statementMock = $this->getMockBuilder(PDOStatement::class)->getMock();
150
        $statementMock
151
            ->expects($this->exactly(count($values)))
152
            ->method('bindParam')
153
            ->withConsecutive(['foo', 'bar', PDO::PARAM_STR], ['bar', 'baz', PDO::PARAM_STR]);
154
        $statementMock
155
            ->expects($this->once())
156
            ->method('execute')
157
            ->willReturn(true);
158
        $statementMock
159
            ->expects($this->once())
160
            ->method('fetchColumn')
161
            ->willReturn($returnValue);
162
163
        $this->pdoMock->expects($this->once())->method('prepare')->with($sql)->willReturn($statementMock);
164
165
        $query = new Expr($sql, $values);
166
167
        $actualValue = $this->sut->fetchColumn($query);
168
169
        $this->assertSame($returnValue, $actualValue);
170
    }
171
172
    /**
173
     * @suppress PhanTypeMismatchArgumentProbablyReal
174
     */
175
    public function testFetch()
176
    {
177
        $returnValue = ['foo', 'bar'];
178
179
        $sql    = ':foo AND :bar';
180
        $values = ['foo' => 'bar', 'bar' => 'baz'];
181
182
        $statementMock = $this->getMockBuilder(PDOStatement::class)->getMock();
183
        $statementMock
184
            ->expects($this->exactly(count($values)))
185
            ->method('bindParam')
186
            ->withConsecutive(['foo', 'bar', PDO::PARAM_STR], ['bar', 'baz', PDO::PARAM_STR]);
187
        $statementMock
188
            ->expects($this->once())
189
            ->method('execute')
190
            ->willReturn(true);
191
        $statementMock
192
            ->expects($this->once())
193
            ->method('fetch')
194
            ->willReturn($returnValue);
195
196
        $this->pdoMock->expects($this->once())->method('prepare')->with($sql)->willReturn($statementMock);
197
198
        $query = new Expr($sql, $values);
199
200
        $actualValue = $this->sut->fetch($query);
201
202
        $this->assertSame($returnValue, $actualValue);
203
    }
204
}
205