Issues (51)

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

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
 * (c) 2018 Douglas Reith.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
use PHPUnit\Framework\TestCase;
11
use Psr\Log\LoggerInterface;
12
use Symfony\Component\Console\Application;
13
use Symfony\Component\Console\Tester\ApplicationTester;
14
use Reith\ToyRobot\Domain\Space\Table;
15
16
// Persistence
17
use Reith\ToyRobot\Infrastructure\Persistence\InMemoryRobotStore;
18
use Reith\ToyRobot\Infrastructure\Persistence\RobotRepository;
19
20
// Console tasks
21
use Reith\ToyRobot\Console\Place;
22
use Reith\ToyRobot\Console\Report;
23
use Reith\ToyRobot\Console\Left;
24
use Reith\ToyRobot\Console\Right;
25
use Reith\ToyRobot\Console\Move;
26
use Reith\ToyRobot\Console\BusHelper;
27
28
// Buses
29
use Reith\ToyRobot\Infrastructure\Bus\CommandBus;
30
use Reith\ToyRobot\Infrastructure\Bus\QueryBus;
31
32
// Command and query handlers
33
use Reith\ToyRobot\CommandHandler\RobotPlacer;
34
use Reith\ToyRobot\CommandHandler\RobotMover;
35
use Reith\ToyRobot\QueryHandler\RobotReporter;
36
37
class toyrobotTest extends TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
38
{
39
    private $testApp;
40
41
    protected function setUp()
42
    {
43
        $mockLogger = self::createMock(LoggerInterface::class);
44
45
        $store = InMemoryRobotStore::getStore($mockLogger);
46
47
        // Pass to the repository
48
        $repository = new RobotRepository($store);
49
        $table = Table::create(5);
50
51
        // Create the command and query handlers
52
        $robotPlacer = new RobotPlacer($table, $repository, $mockLogger);
53
        $robotMover = new RobotMover($repository, $mockLogger);
54
        $robotReporter = new RobotReporter($repository, $mockLogger);
55
56
        // Create the busses and register the handlers
57
        $commandBus = (new CommandBus())
58
            ->registerHandler($robotPlacer)
59
            ->registerHandler($robotMover)
60
        ;
61
62
        $queryBus = (new QueryBus())
63
            ->registerHandler($robotReporter)
64
        ;
65
66
        // Set up the console
67
        $application = new Application();
68
        $application->setAutoExit(false);
69
        $application->addCommands([
70
            new Place(),
71
            new Report(),
72
            new Left(),
73
            new Right(),
74
            new Move(),
75
        ]);
76
77
        $busHelper = (new BusHelper())
78
            ->setCommandBus($commandBus)
79
            ->setQueryBus($queryBus)
80
        ;
81
82
        $application->getHelperSet()->set($busHelper);
83
84
        $this->testApp = new ApplicationTester($application);
85
    }
86
87
    public function testToyrobotApp()
88
    {
89
        $this->testApp->run([]);
90
91
        self::assertContains(
92
            'Place the robot on the table',
93
            $this->testApp->getDisplay()
94
        );
95
96
        self::assertSame(0, $this->testApp->getStatusCode(), $this->testApp->getDisplay());
97
    }
98
99
    public function testPlaceRobot()
100
    {
101
        $this->testApp->run(['place']);
102
103
        self::assertSame(0, $this->testApp->getStatusCode(), $this->testApp->getDisplay());
104
    }
105
106
    public function testRobotReport()
107
    {
108
        $this->testApp->run(['report']);
109
110
        self::assertSame(0, $this->testApp->getStatusCode(), $this->testApp->getDisplay());
111
    }
112
113
    public function testPlacingAndReporting()
114
    {
115
        $instruction = '2,2,S';
116
117
        $this->testApp->run(['command' => 'place', 'X,Y,F' => $instruction]);
118
119
        self::assertSame(0, $this->testApp->getStatusCode(), $this->testApp->getDisplay());
120
121
        $this->testApp->run(['report']);
122
123
        self::assertContains($instruction, $this->testApp->getDisplay());
124
125
        // 
126
        // An incorrect placement won't move the robot, it'll report
127
        // the same position
128
        //
129
        $this->testApp->run(['command' => 'place', 'X,Y,F' => '12,4,W']);
130
131
        self::assertNotEquals(0, $this->testApp->getStatusCode(), $this->testApp->getDisplay());
132
133
        $this->testApp->run(['report']);
134
135
        self::assertContains($instruction, $this->testApp->getDisplay());
136
    }
137
138 View Code Duplication
    public function testTurningLeft()
139
    {
140
        $instruction = '3,2,W';
141
142
        $this->testApp->run(['command' => 'place', 'X,Y,F' => $instruction]);
143
144
        self::assertSame(0, $this->testApp->getStatusCode(), $this->testApp->getDisplay());
145
146
        $this->testApp->run(['left']);
147
148
        self::assertSame(0, $this->testApp->getStatusCode(), $this->testApp->getDisplay());
149
150
        // Now face south
151
        self::assertContains('3,2,S', $this->testApp->getDisplay());
152
    }
153
154 View Code Duplication
    public function testTurningRight()
155
    {
156
        $instruction = '1,2,E';
157
158
        $this->testApp->run(['command' => 'place', 'X,Y,F' => $instruction]);
159
160
        self::assertSame(0, $this->testApp->getStatusCode(), $this->testApp->getDisplay());
161
162
        $this->testApp->run(['right']);
163
164
        self::assertSame(0, $this->testApp->getStatusCode(), $this->testApp->getDisplay());
165
166
        // Now face south
167
        self::assertContains('1,2,S', $this->testApp->getDisplay());
168
    }
169
170 View Code Duplication
    public function testMovingForward()
171
    {
172
        $instruction = '3,3,W';
173
174
        $this->testApp->run(['command' => 'place', 'X,Y,F' => $instruction]);
175
176
        self::assertSame(0, $this->testApp->getStatusCode(), $this->testApp->getDisplay());
177
178
        $this->testApp->run(['move']);
179
180
        self::assertSame(0, $this->testApp->getStatusCode(), $this->testApp->getDisplay());
181
182
        // Now x has decreased
183
        self::assertContains('2,3,W', $this->testApp->getDisplay());
184
    }
185
}
186