Completed
Push — master ( cc71a2...fb9589 )
by Tõnis
03:19
created

SiteControllerTest::_after()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace andmemasin\emailsvalidator;
3
4
use andmemasin\emailsvalidator\controllers\SiteController;
5
use yii\base\Action;
6
7
class SiteControllerTest extends \Codeception\Test\Unit
8
{
9
    /**
10
     * @var \andmemasin\emailsvalidator\UnitTester
11
     */
12
    protected $tester;
13
14
    /** @var SiteController */
15
    public $model;
16
17
    protected function _before()
0 ignored issues
show
Coding Style introduced by
_before uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
18
    {
19
        $_SERVER['REQUEST_URI']='index.php';
20
        $config = require( __DIR__ . "/../_config/test.php");
21
        $this->model = new SiteController('site', new \yii\web\Application($config));
22
        \Yii::$app->controller = $this->model;
23
        \Yii::$app->controller->action = new Action('fake', $this->model);
24
    }
25
26
    protected function _after()
27
    {
28
    }
29
30
    // tests
31
    public function testActionIndex()
32
    {
33
        $result = $this->model->actionIndex();
0 ignored issues
show
Unused Code introduced by
$result 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...
34
35
    }
36
}