Passed
Pull Request — master (#405)
by Kirill
06:27
created

CacheTest::include()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 10
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