/var/www/hkosl.com/imusiccircle/webadmin/libraies/php-console/php-console/tests/Test/Storage/File.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php

namespace PhpConsole\Test\Storage;

class 
File extends \PhpConsole\Test\Storage {

    protected 
$filePath;

    
/**
     * @param bool $validatePathUnderDocRoot
     * @return \PhpConsole\Storage
     */
    
protected function initStorage($validatePathUnderDocRoot false) {
        
$this->filePath = \PhpConsole\Test\BASE_DIR DIRECTORY_SEPARATOR 'tmp' DIRECTORY_SEPARATOR 'file_storage_test.data';
        if(
file_exists($this->filePath)) {
            
unlink($this->filePath);
        }
        return new \
PhpConsole\Storage\File($this->filePath$validatePathUnderDocRoot);
    }

    protected function 
tearDown() {
        
parent::tearDown();
        if(
file_exists($this->filePath)) {
            
unlink($this->filePath);
        }
    }

    
/**
     * @expectedException \Exception
     */
    
public function testPathUnderDocRootThrowsException() {
        
$_SERVER['DOCUMENT_ROOT'] = dirname($this->filePath);
        
$this->initStorage(true);
    }

    public function 
testPathNotUnderDocRoot() {
        
$_SERVER['DOCUMENT_ROOT'] = $this->filePath DIRECTORY_SEPARATOR 'bla';
        
$this->initStorage(true);
    }
}