Completed
Push — master ( 9f51bb...4007ca )
by Christopher
12:02
created

TestCase::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 1
cts 1
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Phwoolcon\TestStarter;
4
5
use Phalcon\Di;
6
use Phalcon\Version;
7
use PHPUnit\Framework\TestCase as PhpunitTestCase;
8
use Phwoolcon\Aliases;
9
use Phwoolcon\Cache;
10
use Phwoolcon\Cache\Clearer;
11
use Phwoolcon\Cookies;
12
use Phwoolcon\Db;
13
use Phwoolcon\DiFix;
14
use Phwoolcon\Events;
15
use Phwoolcon\I18n;
16
use Phwoolcon\Log;
17
use Phwoolcon\Session;
18
use Phwoolcon\Util\Counter;
19
use Phwoolcon\Util\Timer;
20
21
class TestCase extends PhpunitTestCase
22
{
23
    use RemoteCoverageTrait;
24
25
    /**
26
     * @var Di
27
     */
28
    protected $di;
29
30 2
    protected function reloadConfig()
31
    {
32 2
        Config::register($this->di);
33 2
    }
34
35 2
    public function setUp()
0 ignored issues
show
Coding Style introduced by
setUp 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...
36 2
    {
37 2
        $_SERVER['SCRIPT_NAME'] = '/index.php';
38 2
        $_SERVER['PHWOOLCON_PHALCON_VERSION'] = (int)Version::getId();
39 2
        /* @var Di $di */
40 2
        $di = $this->di = Di::getDefault();
41 2
        Events::register($di);
42 2
        DiFix::fix($di);
43 2
        Db::register($di);
44 2
        Cache::register($di);
45 2
        Log::register($di);
46 2
        $this->reloadConfig();
47 2
        Counter::register($this->di);
48 2
        Aliases::register($di);
49
        I18n::register($di);
50 2
        Cookies::register($di);
51 2
        Session::register($di);
52 2
        Clearer::clear();
53 2
        parent::setUp();
54
55 2
        $class = get_class($this);
56
        Log::debug("================== Running {$class}::{$this->getName()}() ... ==================");
57 2
        Timer::start();
58 2
    }
59 2
60 2
    public function tearDown()
61
    {
62
        $elapsed = Timer::stop();
63
        parent::tearDown();
64
        Log::debug("================== Finished, time elapsed: {$elapsed}. ==================");
65
    }
66
}
67