Passed
Push — master ( a91c75...3d6eb6 )
by Caen
03:47 queued 12s
created

FilesystemTest::test_copy_method()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Hyde\Framework\Testing\Feature\Foundation;
4
5
use Hyde\Framework\Foundation\Filesystem;
6
use Hyde\Framework\Hyde;
7
use Hyde\Testing\TestCase;
8
9
/**
10
 * @covers \Hyde\Framework\Foundation\Filesystem
11
 *
12
 * @see \Hyde\Framework\Testing\Unit\Foundation\FilesystemSafeCopyHelperTest
13
 * @see \Hyde\Framework\Testing\Unit\Foundation\FluentFilesystemModelPathHelpersTest
14
 */
15
class FilesystemTest extends TestCase
16
{
17
    protected string $originalBasePath;
18
19
    protected Filesystem $filesystem;
20
21
    protected function setUp(): void
22
    {
23
        parent::setUp();
24
25
        $this->originalBasePath = Hyde::getBasePath();
26
        $this->filesystem = new Filesystem(Hyde::getInstance());
27
        Hyde::getInstance()->setBasePath('/foo');
0 ignored issues
show
Bug introduced by
The method setBasePath() does not exist on Hyde\Framework\Contracts\HydeKernelContract. Since it exists in all sub-types, consider adding an abstract or default implementation to Hyde\Framework\Contracts\HydeKernelContract. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        Hyde::getInstance()->/** @scrutinizer ignore-call */ setBasePath('/foo');
Loading history...
28
    }
29
30
    protected function tearDown(): void
31
    {
32
        Hyde::getInstance()->setBasePath($this->originalBasePath);
33
34
        parent::tearDown();
35
    }
36
37
    public function test_get_base_path_returns_kernels_base_path()
38
    {
39
        $this->assertEquals('/foo', $this->filesystem->getBasePath());
40
    }
41
42
    public function test_path_method_exists()
43
    {
44
        $this->assertTrue(method_exists(Filesystem::class, 'path'));
45
    }
46
47
    public function test_path_method_returns_string()
48
    {
49
        $this->assertIsString($this->filesystem->path());
50
    }
51
52
    public function test_path_method_returns_base_path_when_not_supplied_with_argument()
53
    {
54
        $this->assertEquals('/foo', $this->filesystem->path());
55
    }
56
57
    public function test_path_method_returns_path_relative_to_base_path_when_supplied_with_argument()
58
    {
59
        $this->assertEquals('/foo'.DIRECTORY_SEPARATOR.'foo/bar.php', $this->filesystem->path('foo/bar.php'));
60
    }
61
62
    public function test_path_method_returns_qualified_file_path_when_supplied_with_argument()
63
    {
64
        $this->assertEquals('/foo'.DIRECTORY_SEPARATOR.'file.php', $this->filesystem->path('file.php'));
65
    }
66
67
    public function test_path_method_returns_expected_value_for_nested_path_arguments()
68
    {
69
        $this->assertEquals('/foo'.DIRECTORY_SEPARATOR.'directory/file.php', $this->filesystem->path('directory/file.php'));
70
    }
71
72
    public function test_path_method_strips_trailing_directory_separators_from_argument()
73
    {
74
        $this->assertEquals('/foo'.DIRECTORY_SEPARATOR.'file.php', $this->filesystem->path('\\/file.php/'));
75
    }
76
77
    public function test_path_method_returns_expected_value_regardless_of_trailing_directory_separators_in_argument()
78
    {
79
        $this->assertEquals('/foo'.DIRECTORY_SEPARATOR.'bar/file.php', $this->filesystem->path('\\/bar/file.php/'));
80
    }
81
82
    public function test_vendor_path_method_exists()
83
    {
84
        $this->assertTrue(method_exists(Filesystem::class, 'vendorPath'));
85
    }
86
87
    public function test_vendor_path_method_returns_string()
88
    {
89
        $this->assertIsString($this->filesystem->vendorPath());
90
    }
91
92
    public function test_vendor_path_method_returns_qualified_file_path_when_supplied_with_argument()
93
    {
94
        $this->assertEquals($this->filesystem->vendorPath('file.php'), $this->filesystem->vendorPath().'/file.php');
95
    }
96
97
    public function test_vendor_path_method_returns_expected_value_regardless_of_trailing_directory_separators_in_argument()
98
    {
99
        $this->assertEquals('/foo'.DIRECTORY_SEPARATOR.'vendor/hyde/framework/file.php', $this->filesystem->vendorPath('\\//file.php/'));
100
    }
101
102
    public function test_copy_method()
103
    {
104
        $this->assertTrue(method_exists(Filesystem::class, 'copy'));
105
    }
106
107
    public function test_copy_method_returns_404_when_file_does_not_exist()
108
    {
109
        $this->assertEquals(404, $this->filesystem->copy('foo/bar.php', 'foo/baz.php'));
110
    }
111
112
    public function test_copy_method_returns_409_when_destination_file_exists()
113
    {
114
        touch('foo');
115
        touch('bar');
116
        $this->assertEquals(409, $this->filesystem->copy('foo', 'bar'));
117
        unlink('foo');
118
        unlink('bar');
119
    }
120
121
    public function test_copy_method_overwrites_destination_file_when_overwrite_is_true()
122
    {
123
        touch('foo');
124
        touch('bar');
125
        $this->assertTrue($this->filesystem->copy('foo', 'bar', true));
126
        unlink('foo');
127
        unlink('bar');
128
    }
129
}
130