1 | <?php |
||||
2 | /** |
||||
3 | * DronePHP (http://www.dronephp.com) |
||||
4 | * |
||||
5 | * @link http://github.com/Pleets/DronePHP |
||||
6 | * @copyright Copyright (c) 2016-2018 Pleets. (http://www.pleets.org) |
||||
7 | * @license http://www.dronephp.com/license |
||||
8 | * @author Darío Rivera <[email protected]> |
||||
9 | */ |
||||
10 | |||||
11 | namespace DroneTest\Util; |
||||
12 | |||||
13 | use Drone\Mvc\ModuleFactory; |
||||
14 | use Drone\Mvc\Router; |
||||
15 | use Drone\Mvc\View; |
||||
16 | use PHPUnit\Framework\TestCase; |
||||
17 | |||||
18 | class SimpleMvcApplicationTest extends TestCase |
||||
19 | { |
||||
20 | /** |
||||
21 | * Tests if we can create a simple Mvc application |
||||
22 | * |
||||
23 | * @return null |
||||
24 | */ |
||||
25 | public function testMakingMvcApplication() |
||||
26 | { |
||||
27 | $router = new Router(); |
||||
28 | |||||
29 | $router->addRoute([ |
||||
30 | 'AppRoute' => [ |
||||
31 | 'module' => 'Master', |
||||
32 | 'controller' => 'Admin', |
||||
33 | 'view' => 'index', |
||||
34 | ], |
||||
35 | ]); |
||||
36 | |||||
37 | // you should code the request to match /Master/Admin/index |
||||
38 | $router->setIdentifiers('Master', 'Admin', 'index'); |
||||
39 | |||||
40 | $router->setClassNameBuilder(function ($module, $class) { |
||||
41 | return "\\$module\Controller\\$class"; |
||||
42 | }); |
||||
43 | |||||
44 | \Drone\Loader\ClassMap::$path = 'test-skeleton/module/Master/source'; |
||||
45 | spl_autoload_register("Drone\Loader\ClassMap::autoload"); |
||||
46 | |||||
47 | $router->match(); |
||||
48 | $ctrl = $router->getController(); |
||||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||||
49 | |||||
50 | # inject the module dependency to the controller |
||||
51 | $router->getController()->setModule(ModuleFactory::create("Master", [ |
||||
0 ignored issues
–
show
Are you sure the usage of
Drone\Mvc\ModuleFactory:...er/config/config.php')) targeting Drone\Mvc\ModuleFactory::create() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() Drone\Mvc\ModuleFactory:...er/config/config.php')) of type null is incompatible with the type Drone\Mvc\AbstractModule expected by parameter $module of Drone\Mvc\AbstractController::setModule() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
52 | "config" => 'test-skeleton/module/Master/config/config.php', |
||||
53 | ])); |
||||
54 | |||||
55 | $result = $router->run(); |
||||
56 | |||||
57 | $this->assertSame(["message" => "Hello world!"], $result); |
||||
58 | |||||
59 | $router->addRoute([ |
||||
60 | 'AppRouteView' => [ |
||||
61 | 'module' => 'Master', |
||||
62 | 'controller' => 'Admin', |
||||
63 | 'view' => 'withView', |
||||
64 | ], |
||||
65 | ]); |
||||
66 | |||||
67 | $router->setIdentifiers('Master', 'Admin', 'withView'); |
||||
68 | $router->match(); |
||||
69 | $result = $router->run(); |
||||
70 | |||||
71 | $this->assertTrue($result instanceof View); |
||||
72 | |||||
73 | $result->setPath("test-skeleton/module/Master/source/view/Admin"); |
||||
74 | |||||
75 | $this->assertSame("<h1>Hello world!</h1>", $result->getContents()); |
||||
76 | } |
||||
77 | } |
||||
78 |