Passed
Push — master ( 6215ec...1255dc )
by Darío
01:47
created

testMakingMvcApplication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 28
nc 1
nop 0
dl 0
loc 51
rs 9.472
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Router;
14
use Drone\Mvc\View;
15
use Drone\Mvc\ModuleFactory;
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
The assignment to $ctrl is dead and can be removed.
Loading history...
49
50
        # inject the module dependency to the controller
51
        $router->getController()->setModule(ModuleFactory::create("Master", [
0 ignored issues
show
Bug introduced by
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 getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
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 ignore-type  annotation

51
        $router->getController()->setModule(/** @scrutinizer ignore-type */ ModuleFactory::create("Master", [
Loading history...
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
        /*$result->setPath('test-skeleton/module/source/view');
78
        $result->setView($ctrl->getMethod());
79
        $result->render();*/
80
    }
81
}