Issues (17)

Security Analysis    not enabled

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/ApplicationTest.php (15 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
namespace ProtonTests;
4
5
use League\Container\Container;
6
use League\Event\Emitter;
7
use League\Route\Http\Exception\NotFoundException;
8
use League\Route\RouteCollection;
9
use Monolog\Logger;
10
use Proton;
11
use Proton\Application;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
15
class ApplicationTest extends \PHPUnit_Framework_TestCase
16
{
17
    public function testSetGet()
18
    {
19
        $app = new Application();
20
        $this->assertTrue($app->getContainer() instanceof Container);
21
        $this->assertTrue($app->getRouter() instanceof RouteCollection);
22
        $this->assertTrue($app->getEventEmitter() instanceof Emitter);
23
24
        $logger = $app->getLogger();
25
        $this->assertTrue($logger instanceof Logger);
26
        $this->assertEquals($logger, $app->getLogger('default'));
27
    }
28
29
    public function testArrayAccessContainer()
30
    {
31
        $app = new Application();
32
        $app['foo'] = 'bar';
33
34
        $this->assertSame('bar', $app['foo']);
35
        $this->assertTrue(isset($app['foo']));
36
        unset($app['foo']);
37
        $this->assertFalse(isset($app['foo']));
38
    }
39
40
    public function testSubscribe()
41
    {
42
        $app = new Application();
43
44
        $app->subscribe('request.received', function ($event, $request) {
45
            $this->assertInstanceOf('League\Event\Event', $event);
46
            $this->assertInstanceOf('Symfony\Component\HttpFoundation\Request', $request);
47
        });
48
49
        $reflected = new \ReflectionProperty($app, 'emitter');
50
        $reflected->setAccessible(true);
51
        $emitter = $reflected->getValue($app);
52
        $this->assertTrue($emitter->hasListeners('request.received'));
53
54
        $foo = null;
55
        $app->subscribe('response.created', function ($event, $request, $response) use (&$foo) {
0 ignored issues
show
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
            $foo = 'bar';
57
        });
58
59
        $request = Request::createFromGlobals();
60
        $response = $app->handle($request);
61
62
        $this->assertEquals('bar', $foo);
63
        $this->assertEquals(404, $response->getStatusCode());
64
    }
65
66
    public function testTerminate()
67
    {
68
        $app = new Application();
69
70
        $app->subscribe('response.sent', function ($event, $request, $response) {
71
            $this->assertInstanceOf('League\Event\Event', $event);
72
            $this->assertInstanceOf('Symfony\Component\HttpFoundation\Request', $request);
73
            $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
74
        });
75
76
        $request = Request::createFromGlobals();
77
        $response = $app->handle($request);
78
79
        $app->terminate($request, $response);
80
    }
81
82
    public function testHandleSuccess()
83
    {
84
        $app = new Application();
85
86
        $app->get('/', function ($request, $response) {
87
            $response->setContent('<h1>It works!</h1>');
88
            return $response;
89
        });
90
91
        $app->post('/', function ($request, $response) {
92
            $response->setContent('<h1>It works!</h1>');
93
            return $response;
94
        });
95
96
        $app->put('/', function ($request, $response) {
97
            $response->setContent('<h1>It works!</h1>');
98
            return $response;
99
        });
100
101
        $app->delete('/', function ($request, $response) {
102
            $response->setContent('<h1>It works!</h1>');
103
            return $response;
104
        });
105
106
        $app->patch('/', function ($request, $response) {
107
            $response->setContent('<h1>It works!</h1>');
108
            return $response;
109
        });
110
111
        $request = Request::createFromGlobals();
112
113
        $response = $app->handle($request, 1, true);
114
115
        $this->assertEquals('<h1>It works!</h1>', $response->getContent());
116
    }
117
118
    public function testHandleFailThrowException()
119
    {
120
        $app = new Application();
121
122
        $request = Request::createFromGlobals();
123
124
        try {
125
            $app->handle($request, 1, false);
126
        } catch (\Exception $e) {
127
            $this->assertTrue($e instanceof NotFoundException);
128
        }
129
    }
130
131
    public function testHandleWithOtherException()
132
    {
133
        $app = new Application();
134
        $app['debug'] = true;
135
136
        $request = Request::createFromGlobals();
137
138
        $app->subscribe('request.received', function ($event, $request, $response) {
0 ignored issues
show
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
139
            throw new \Exception('A test exception');
140
        });
141
142
        $response = $app->handle($request);
143
144
        $this->assertEquals(500, $response->getStatusCode());
145
    }
146
147
    public function testCustomExceptionDecorator()
148
    {
149
        $app = new Application();
150
        $app['debug'] = true;
151
152
        $request = Request::createFromGlobals();
153
154
        $app->subscribe('request.received', function ($event, $request, $response) {
0 ignored issues
show
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
155
            throw new \Exception('A test exception');
156
        });
157
158
        $app->setExceptionDecorator(function ($e) {
0 ignored issues
show
The parameter $e is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
159
            $response = new Response;
160
            $response->setStatusCode(500);
161
            $response->setContent('Fail');
162
            return $response;
163
        });
164
165
        $response = $app->handle($request);
166
167
        $this->assertEquals(500, $response->getStatusCode());
168
        $this->assertEquals('Fail', $response->getContent());
169
    }
170
171
    /**
172
     * @expectedException \LogicException
173
     */
174
    public function testExceptionDecoratorDoesntReturnResponseObject()
175
    {
176
        $app = new Application();
177
        $app->setExceptionDecorator(function ($e) {
0 ignored issues
show
The parameter $e is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
178
            return true;
179
        });
180
181
        $request = Request::createFromGlobals();
182
183
        $app->subscribe('request.received', function ($event, $request, $response) {
0 ignored issues
show
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
184
            throw new \Exception('A test exception');
185
        });
186
187
        $response = $app->handle($request);
0 ignored issues
show
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
188
    }
189
190
    public function testCustomEvents()
191
    {
192
        $app = new Application();
193
194
        $time = null;
195
        $app->subscribe('custom.event', function ($event, $args) use (&$time) {
196
            $time = $args;
197
        });
198
199
        $app->getEventEmitter()->emit('custom.event', time());
200
        $this->assertTrue($time !== null);
201
    }
202
203
    public function testRun()
204
    {
205
        $app = new Application();
206
207
        $app->get('/', function ($request, $response) {
208
            $response->setContent('<h1>It works!</h1>');
209
            return $response;
210
        });
211
212
        $app->subscribe('request.received', function ($event, $request) {
213
            $this->assertInstanceOf('League\Event\Event', $event);
214
            $this->assertInstanceOf('Symfony\Component\HttpFoundation\Request', $request);
215
        });
216
        $app->subscribe('response.sent', function ($event, $request, $response) {
217
            $this->assertInstanceOf('League\Event\Event', $event);
218
            $this->assertInstanceOf('Symfony\Component\HttpFoundation\Request', $request);
219
            $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
220
        });
221
222
        ob_start();
223
        $app->run();
224
        ob_get_clean();
225
    }
226
}
227