Completed
Push — master ( 6366df...fbe022 )
by Kirill
23s queued 19s
created

CacheTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 38
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A include() 0 8 2
A testCache() 0 13 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Router;
13
14
class CacheTest extends TestCase
15
{
16
    private $app;
17
18
    public function setUp(): void
19
    {
20
        parent::setUp();
21
22
        $this->app = $this->makeApp(['DEBUG' => false]);
23
    }
24
25
    public function testCache(): void
26
    {
27
        $cache = __DIR__ . '/App/runtime/cache/routes.php';
28
        $this->assertFileExists($cache);
29
30
        $this->assertIsIterable($this->include($cache));
31
        $this->assertCount(2, $this->include($cache));
32
33
34
        $cli = $this->app->getConsole();
35
        $cli->run('route:reset');
36
37
        $this->assertNull($this->include($cache));
38
    }
39
40
    /**
41
     * @param string $file
42
     * @return mixed
43
     */
44
    private function include(string $file)
45
    {
46
        // Required when "opcache.cli_enabled=1"
47
        if (\function_exists('\\opcache_invalidate')) {
48
            \opcache_invalidate($file);
49
        }
50
51
        return require $file;
52
    }
53
}
54