Completed
Pull Request — master (#365)
by Alessandro
04:01
created

SymfonyProxy::start()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCache package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCache\Test\Proxy;
13
14
/**
15
 * Controls the Symfony HttpCache proxy server.
16
 *
17
 * SYMFONY_CACHE_DIR directory to use for cache
18
 *                   (default sys_get_temp_dir() + '/foshttpcache-symfony')
19
 */
20
class SymfonyProxy implements ProxyInterface
21
{
22
    /**
23
     * Get Symfony cache directory.
24
     *
25
     * @return string
26
     */
27 6
    public function getCacheDir()
28
    {
29 6
        $path = defined('SYMFONY_CACHE_DIR') ? SYMFONY_CACHE_DIR : sys_get_temp_dir().'/foshttpcache-symfony';
30 6
        if (!$path || '/' === $path) {
31 1
            throw new \RuntimeException('Invalid test setup, the cache dir is '.$path);
32
        }
33
34 5
        return $path;
35
    }
36
37
    /**
38
     * Start the proxy server.
39
     */
40
    public function start()
41
    {
42
        $this->clear();
43
    }
44
45
    /**
46
     * Stop the proxy server.
47
     */
48
    public function stop()
49
    {
50
        // nothing to do
51
    }
52
53
    /**
54
     * Clear all cached content from the proxy server.
55
     */
56 5
    public function clear()
57
    {
58 5
        $path = realpath($this->getCacheDir());
59
60
        // false means the directory does not exist yet - it surely is empty then
61 5
        if (!is_dir($path)) {
62 1
            return;
63
        }
64
65 4
        $path = $this->getCacheDir();
66 4
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
67
            // @codeCoverageIgnoreStart
68
            system('DEL /S '.$path);
69
        } else {
70
            // @codeCoverageIgnoreEnd
71 4
            system('rm -r '.$path);
72
        }
73 4
    }
74
}
75