Completed
Push — master ( 19e140...7b3764 )
by Christopher
03:11
created

TestCase::reloadConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
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\Config;
12
use Phwoolcon\Cookies;
13
use Phwoolcon\Db;
14
use Phwoolcon\DiFix;
15
use Phwoolcon\Events;
16
use Phwoolcon\I18n;
17
use Phwoolcon\Log;
18
use Phwoolcon\Session;
19
use Phwoolcon\Util\Counter;
20
use Phwoolcon\Util\Timer;
21
22
class TestCase extends PhpunitTestCase
23
{
24
    use RemoteCoverageTrait;
25
26
    /**
27
     * @var Di
28
     */
29
    protected $di;
30
31 2
    protected function prepareTestRoot()
32
    {
33 2
        if (is_file($testRootReady = TEST_ROOT_PATH . '/ready')) {
34 1
            return;
35
        }
36 1
        $assembler = new ResourceAggregator(getcwd());
37 1
        $assembler->aggregate();
38 1
        touch($testRootReady);
39 1
    }
40
41 2
    protected function reloadConfig()
42
    {
43 2
        Config::register($this->di);
44 2
    }
45
46 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...
47
    {
48 2
        $this->prepareTestRoot();
49
50 2
        $_SERVER['SCRIPT_NAME'] = '/index.php';
51 2
        $_SERVER['PHWOOLCON_PHALCON_VERSION'] = (int)Version::getId();
52
        /* @var Di $di */
53 2
        $di = $this->di = Di::getDefault();
54 2
        Events::register($di);
55 2
        DiFix::fix($di);
56 2
        Db::register($di);
57 2
        Cache::register($di);
58 2
        Log::register($di);
59 2
        $this->reloadConfig();
60 2
        Counter::register($this->di);
61 2
        Aliases::register($di);
62 2
        I18n::register($di);
63 2
        Cookies::register($di);
64 2
        Session::register($di);
65 2
        Clearer::clear();
66 2
        parent::setUp();
67
68 2
        $class = get_class($this);
69 2
        Log::debug("================== Running {$class}::{$this->getName()}() ... ==================");
70 2
        Timer::start();
71 2
    }
72
73 2
    public function tearDown()
74
    {
75 2
        $elapsed = Timer::stop();
76 2
        parent::tearDown();
77 2
        Log::debug("================== Finished, time elapsed: {$elapsed}. ==================");
78 2
    }
79
}
80