Issues (83)

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.

Tests/Service/JobQueueTest.php (17 issues)

Labels

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
namespace SfCod\QueueBundle\Tests\Service;
4
5
use PHPUnit\Framework\MockObject\MockObject;
6
use PHPUnit\Framework\TestCase;
7
use SfCod\QueueBundle\Queue\QueueInterface;
8
use SfCod\QueueBundle\Service\JobQueue;
9
use SfCod\QueueBundle\Service\QueueManager;
10
use SfCod\QueueBundle\Tests\Data\LoadTrait;
11
12
/**
13
 * Class JobQueueTest
14
 *
15
 * @author Virchenko Maksim <[email protected]>
16
 *
17
 * @package SfCod\QueueBundle\Tests\Service
18
 */
19
class JobQueueTest extends TestCase
20
{
21
    use LoadTrait;
22
23
    /**
24
     * Set up test
25
     */
26
    protected function setUp()
27
    {
28
        $this->configure();
29
    }
30
31
    /**
32
     * Test pushing into queue
33
     */
34
    public function testPush()
35
    {
36
        $job = uniqid('job_');
37
        $data = array_rand(range(0, 100), 10);
38
        $queue = uniqid('queue_');
39
        $connection = uniqid('connection_');
40
41
        $manager = $this->mockManager();
42
        $manager
0 ignored issues
show
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in SfCod\QueueBundle\Service\QueueManager.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
43
            ->expects(self::once())
44
            ->method('push')
45
            ->with($job, $data, $queue, $connection)
46
            ->willReturn(true);
47
48
        $jobQueue = $this->mockJobQueue($manager);
0 ignored issues
show
It seems like $manager defined by $this->mockManager() on line 41 can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, SfCod\QueueBundle\Tests\...eueTest::mockJobQueue() does only seem to accept object<SfCod\QueueBundle\Service\QueueManager>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
49
50
        self::assertTrue($jobQueue->push($job, $data, $queue, $connection));
0 ignored issues
show
The method push does only exist in SfCod\QueueBundle\Service\JobQueue, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
51
    }
52
53
    /**
54
     * Test push unique job into queue
55
     */
56
    public function testPushUnique()
57
    {
58
        $job = uniqid('job_');
59
        $data = array_rand(range(0, 100), 10);
60
        $queue = uniqid('queue_');
61
        $connection = uniqid('connection_');
62
63
        $connectionMock = $this->createMock(QueueInterface::class);
64
        $connectionMock
65
            ->expects(self::once())
66
            ->method('exists')
67
            ->with(self::equalTo($job), self::equalTo($data), self::equalTo($queue))
68
            ->willReturn(false);
69
70
        $manager = $this->mockManager();
71
        $manager
0 ignored issues
show
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in SfCod\QueueBundle\Service\QueueManager.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
72
            ->expects(self::once())
73
            ->method('connection')
74
            ->with(self::equalTo($connection))
75
            ->willReturn($connectionMock);
76
        $manager
77
            ->expects(self::once())
78
            ->method('push')
79
            ->with($job, $data, $queue, $connection)
80
            ->willReturn(true);
81
82
        $jobQueue = $this->mockJobQueue($manager);
0 ignored issues
show
It seems like $manager defined by $this->mockManager() on line 70 can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, SfCod\QueueBundle\Tests\...eueTest::mockJobQueue() does only seem to accept object<SfCod\QueueBundle\Service\QueueManager>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
83
84
        self::assertTrue($jobQueue->pushUnique($job, $data, $queue, $connection));
0 ignored issues
show
The method pushUnique does only exist in SfCod\QueueBundle\Service\JobQueue, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
85
86
        $connectionMock = $this->createMock(QueueInterface::class);
87
        $connectionMock
88
            ->expects(self::once())
89
            ->method('exists')
90
            ->with(self::equalTo($job), self::equalTo($data), self::equalTo($queue))
91
            ->willReturn(true);
92
93
        $manager = $this->mockManager();
94
        $manager
95
            ->expects(self::once())
96
            ->method('connection')
97
            ->with(self::equalTo($connection))
98
            ->willReturn($connectionMock);
99
100
        $jobQueue = $this->mockJobQueue($manager);
0 ignored issues
show
It seems like $manager defined by $this->mockManager() on line 93 can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, SfCod\QueueBundle\Tests\...eueTest::mockJobQueue() does only seem to accept object<SfCod\QueueBundle\Service\QueueManager>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
101
102
        self::assertNull($jobQueue->pushUnique($job, $data, $queue, $connection));
103
    }
104
105
    /**
106
     * Test bulk pushing into queue
107
     */
108
    public function testBulk()
109
    {
110
        $jobs = [];
111
112
        for ($i = 0; $i < 10; ++$i) {
113
            $jobs[] = uniqid('job_' . $i);
114
        }
115
116
        $data = array_rand(range(0, 100), 10);
117
        $queue = uniqid('queue_');
118
        $connection = uniqid('connection_');
119
120
        $manager = $this->mockManager();
121
        $manager
0 ignored issues
show
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in SfCod\QueueBundle\Service\QueueManager.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
122
            ->expects(self::once())
123
            ->method('bulk')
124
            ->with($jobs, $data, $queue, $connection)
125
            ->willReturn(true);
126
127
        $jobQueue = $this->mockJobQueue($manager);
0 ignored issues
show
It seems like $manager defined by $this->mockManager() on line 120 can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, SfCod\QueueBundle\Tests\...eueTest::mockJobQueue() does only seem to accept object<SfCod\QueueBundle\Service\QueueManager>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
128
129
        self::assertTrue($jobQueue->bulk($jobs, $data, $queue, $connection));
0 ignored issues
show
The method bulk does only exist in SfCod\QueueBundle\Service\JobQueue, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
130
    }
131
132
    /**
133
     * Test pushing job with delay
134
     */
135
    public function testLater()
136
    {
137
        $delay = rand(1, 1000);
138
        $job = uniqid('job_');
139
        $data = array_rand(range(0, 100), 10);
140
        $queue = uniqid('queue_');
141
        $connection = uniqid('connection_');
142
143
        $manager = $this->mockManager();
144
        $manager
0 ignored issues
show
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in SfCod\QueueBundle\Service\QueueManager.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
145
            ->expects(self::once())
146
            ->method('later')
147
            ->with($delay, $job, $data, $queue, $connection)
148
            ->willReturn(true);
149
150
        $jobQueue = $this->mockJobQueue($manager);
0 ignored issues
show
It seems like $manager defined by $this->mockManager() on line 143 can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, SfCod\QueueBundle\Tests\...eueTest::mockJobQueue() does only seem to accept object<SfCod\QueueBundle\Service\QueueManager>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
151
152
        self::assertTrue($jobQueue->later($delay, $job, $data, $queue, $connection));
0 ignored issues
show
The method later does only exist in SfCod\QueueBundle\Service\JobQueue, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
153
    }
154
155
    /**
156
     * Test push unique job with delay into queue
157
     */
158
    public function testLaterUnique()
159
    {
160
        $delay = rand(1, 1000);
161
        $job = uniqid('job_');
162
        $data = array_rand(range(0, 100), 10);
163
        $queue = uniqid('queue_');
164
        $connection = uniqid('connection_');
165
166
        $connectionMock = $this->createMock(QueueInterface::class);
167
        $connectionMock
168
            ->expects(self::once())
169
            ->method('exists')
170
            ->with(self::equalTo($job), self::equalTo($data), self::equalTo($queue))
171
            ->willReturn(false);
172
173
        $manager = $this->mockManager();
174
        $manager
0 ignored issues
show
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in SfCod\QueueBundle\Service\QueueManager.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
175
            ->expects(self::once())
176
            ->method('connection')
177
            ->with(self::equalTo($connection))
178
            ->willReturn($connectionMock);
179
        $manager
180
            ->expects(self::once())
181
            ->method('later')
182
            ->with($delay, $job, $data, $queue, $connection)
183
            ->willReturn(true);
184
185
        $jobQueue = $this->mockJobQueue($manager);
0 ignored issues
show
It seems like $manager defined by $this->mockManager() on line 173 can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, SfCod\QueueBundle\Tests\...eueTest::mockJobQueue() does only seem to accept object<SfCod\QueueBundle\Service\QueueManager>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
186
187
        self::assertTrue($jobQueue->laterUnique($delay, $job, $data, $queue, $connection));
0 ignored issues
show
The method laterUnique does only exist in SfCod\QueueBundle\Service\JobQueue, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
188
189
        $connectionMock = $this->createMock(QueueInterface::class);
190
        $connectionMock
191
            ->expects(self::once())
192
            ->method('exists')
193
            ->with(self::equalTo($job), self::equalTo($data), self::equalTo($queue))
194
            ->willReturn(true);
195
196
        $manager = $this->mockManager();
197
        $manager
198
            ->expects(self::once())
199
            ->method('connection')
200
            ->with(self::equalTo($connection))
201
            ->willReturn($connectionMock);
202
203
        $jobQueue = $this->mockJobQueue($manager);
0 ignored issues
show
It seems like $manager defined by $this->mockManager() on line 196 can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, SfCod\QueueBundle\Tests\...eueTest::mockJobQueue() does only seem to accept object<SfCod\QueueBundle\Service\QueueManager>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
204
205
        self::assertNull($jobQueue->laterUnique($delay, $job, $data, $queue, $connection));
206
    }
207
208
    /**
209
     * Mock job queue
210
     *
211
     * @param QueueManager $manager
212
     *
213
     * @return JobQueue|MockObject
214
     */
215
    private function mockJobQueue(QueueManager $manager): JobQueue
216
    {
217
        $jobQueue = $this->getMockBuilder(JobQueue::class)
218
            ->setConstructorArgs([$manager])
219
            ->setMethods(null)
220
            ->getMock();
221
222
        return $jobQueue;
223
    }
224
225
    /**
226
     * Mock manager
227
     *
228
     * @return QueueManager|MockObject
229
     */
230
    private function mockManager(): QueueManager
231
    {
232
        $manager = $this->getMockBuilder(QueueManager::class)
233
            ->setMethods([
234
                'push',
235
                'bulk',
236
                'later',
237
                'connection',
238
            ])
239
            ->getMock();
240
241
        return $manager;
242
    }
243
}
244