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.

  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/Process/ProcessQueueTest.php (3 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
 * File ProcessQueueTest.php
4
 *
5
 * @author Edward Pfremmer <[email protected]>
6
 */
7
namespace Epfremme\ProcessQueue\Tests\Process;
8
9
use Epfremme\Collection\Collection;
10
use Epfremme\ProcessQueue\System\ProcessorCounter;
11
use Epfremme\ProcessQueue\Process\ProcessQueue;
12
use GuzzleHttp\Promise\Promise;
13
use Symfony\Component\Process\Process;
14
15
/**
16
 * Class ProcessQueueTest
17
 *
18
 * @package Epfremme\ProcessQueue\Tests\Process
19
 */
20
class ProcessQueueTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * Add optional promise to process options
24
     *
25
     * @param Process $process
26
     * @return Promise
27
     */
28
    private function addPromise(Process $process)
29
    {
30
        /** @var Promise $promise */
31
        $promise = new Promise(function() use ($process, &$promise) {
32
            $process->wait();
33
            $promise->resolve($process);
34
        });
35
36
        $process->setOptions([ProcessQueue::PROMISE_KEY => $promise]);
37
38
        return $promise;
39
    }
40
41
    public function testConstruct()
42
    {
43
        $queue = new ProcessQueue();
44
        $counter = new ProcessorCounter();
45
46
        $this->assertInstanceOf(\Countable::class, $queue);
47
        $this->assertAttributeEquals($counter->getCpuCount(), 'limit', $queue);
48
    }
49
50
    public function testConstructWithArgs()
51
    {
52
        $queue = new ProcessQueue(4);
53
54
        $this->assertInstanceOf(\Countable::class, $queue);
55
        $this->assertAttributeEquals(4, 'limit', $queue);
56
    }
57
58
    public function testConstructWithNumericString()
59
    {
60
        $queue = new ProcessQueue('4');
61
62
        $this->assertInstanceOf(\Countable::class, $queue);
63
        $this->assertAttributeEquals(4, 'limit', $queue);
64
    }
65
66
    /** @expectedException \InvalidArgumentException */
67
    public function testConstructNonNumericException()
68
    {
69
        new ProcessQueue([new \ArrayObject()]);
0 ignored issues
show
array(new \ArrayObject()) is of type array<integer,object<Arr..."object<ArrayObject>"}>, but the function expects a integer|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70
    }
71
72
    /** @expectedException \InvalidArgumentException */
73
    public function testConstructLessThenZeroException()
74
    {
75
        new ProcessQueue(0);
76
    }
77
78
    public function testAdd()
79
    {
80
        $queue = new ProcessQueue();
81
        $process = new Process('pwd');
82
83
        $queue->add($process);
84
85
        $this->assertNotEmpty($queue);
86
        $this->assertCount(1, $queue);
87
    }
88
89
    /** @depends testAdd */
90
    public function testGetPending()
91
    {
92
        $queue = new ProcessQueue();
93
        $process = new Process('pwd');
94
95
        $queue->add($process);
96
97
        $pending = $queue->getPending();
98
99
        $this->assertInstanceOf(Collection::class, $pending);
100
        $this->assertContainsOnly(Process::class, $pending);
101
        $this->assertInstanceOf(Process::class, $pending->get(0));
102
        $this->assertSame($process, $pending->get(0));
103
    }
104
105
    /** @depends testAdd */
106 View Code Duplication
    public function testGetRunning()
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...
107
    {
108
        $queue = new ProcessQueue();
109
        $process = new Process('sleep 0.1');
110
111
        $queue->add($process);
112
113
        $this->assertEmpty($queue->getRunning());
114
115
        $process->start();
116
117
        $running = $queue->getRunning();
118
119
        $this->assertInstanceOf(Collection::class, $running);
120
        $this->assertContainsOnly(Process::class, $running);
121
        $this->assertInstanceOf(Process::class, $running->get(0));
122
        $this->assertSame($process, $running->get(0));
123
    }
124
125
    /** @depends testAdd */
126 View Code Duplication
    public function testGetCompleted()
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...
127
    {
128
        $queue = new ProcessQueue();
129
        $process = new Process('pwd');
130
131
        $queue->add($process);
132
133
        $this->assertEmpty($queue->getCompleted());
134
135
        $process->run();
136
137
        $completed = $queue->getCompleted();
138
139
        $this->assertInstanceOf(Collection::class, $completed);
140
        $this->assertContainsOnly(Process::class, $completed);
141
        $this->assertInstanceOf(Process::class, $completed->get(0));
142
        $this->assertSame($process, $completed->get(0));
143
    }
144
145
    /** @depends testAdd */
146
    public function testResolve()
147
    {
148
        $queue = new ProcessQueue();
149
        $process = new Process('pwd');
150
151
        $queue->add($process);
152
        $process->start();
153
        $queue->resolve($process);
154
155
        $this->assertEmpty($queue);
156
        $this->assertCount(0, $queue);
157
        $this->assertTrue($process->isTerminated());
158
    }
159
160
    /** @depends testAdd */
161
    public function testResolveWithPromise()
162
    {
163
        $queue = new ProcessQueue();
164
        $process = new Process('pwd');
165
        $promise = $this->addPromise($process);
166
167
        $isResolved = false;
168
        $promise->then(function() use (&$isResolved) {
169
            $isResolved = true;
170
        });
171
172
        $this->assertFalse($isResolved);
173
174
        $queue->add($process);
175
        $process->start();
176
        $queue->resolve($process);
177
178
        $this->assertEmpty($queue);
179
        $this->assertCount(0, $queue);
180
        $this->assertTrue($isResolved);
181
        $this->assertTrue($process->isTerminated());
182
    }
183
184
    /** @depends testAdd */
185
    public function testInvoke()
186
    {
187
        $queue = new ProcessQueue();
188
        $process = new Process('pwd');
189
190
        $queue->add($process);
191
192
        /** @var Process $pending */
193
        foreach ($queue() as $pending) {
194
            $this->assertInstanceOf(Process::class, $pending);
195
            $this->assertFalse($pending->isStarted());
196
197
            $pending->start();
198
        }
199
200
        $this->assertEmpty($queue);
201
        $this->assertCount(0, $queue);
202
        $this->assertTrue($process->isTerminated());
203
    }
204
}
205