Completed
Pull Request — master (#168)
by Franco
02:41
created

tests/DMSFilesystemTestHelper.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
class DMSFilesystemTestHelper
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    /**
6
     * Files that are added to the DMS asset directory by the DMS instance. They will be removed after running tests.
7
     *
8
     * @var array
9
     */
10
    protected static $dmsFiles = array('.htaccess', 'web.config');
11
12
    /**
13
     * Deletes a directory and all files within it, or a file. Will automatically prepend the base path.
14
     *
15
     * This only work while a unit test is running for safety reasons.
16
     *
17
     * @param string $path
18
     */
19
    public static function delete($path)
20
    {
21
        if (!SapphireTest::is_running_test() || !file_exists($path)) {
22
            return false;
23
        }
24
25
        $path = BASE_PATH . DIRECTORY_SEPARATOR . $path;
26
        if (is_dir($path)) {
27
            $files = new RecursiveIteratorIterator(
28
                new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
29
                RecursiveIteratorIterator::CHILD_FIRST
30
            );
31
32
            foreach ($files as $fileinfo) {
33
                $action = $fileinfo->isDir() ? 'rmdir' : 'unlink';
34
                $action($fileinfo->getRealPath());
35
            }
36
37
            rmdir($path);
38
        } else {
39
            unlink($path);
40
        }
41
    }
42
}
43