1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Testing\Feature\Foundation; |
4
|
|
|
|
5
|
|
|
use Hyde\Framework\Foundation\Filesystem; |
6
|
|
|
use Hyde\Framework\HydeKernel; |
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
|
|
|
// Filesystem with mocked Kernel path. Use the real one if you actually need to access the filesystem. |
18
|
|
|
protected Filesystem $filesystem; |
19
|
|
|
|
20
|
|
|
protected function setUp(): void |
21
|
|
|
{ |
22
|
|
|
parent::setUp(); |
23
|
|
|
|
24
|
|
|
$kernel = $this->mock(HydeKernel::class); |
25
|
|
|
$kernel->shouldReceive('getBasePath')->andReturn('/foo'); |
26
|
|
|
$this->filesystem = new Filesystem($kernel); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function test_get_base_path_returns_kernels_base_path() |
30
|
|
|
{ |
31
|
|
|
$this->assertEquals('/foo', $this->filesystem->getBasePath()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function test_path_method_exists() |
35
|
|
|
{ |
36
|
|
|
$this->assertTrue(method_exists(Filesystem::class, 'path')); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function test_path_method_returns_string() |
40
|
|
|
{ |
41
|
|
|
$this->assertIsString($this->filesystem->path()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function test_path_method_returns_base_path_when_not_supplied_with_argument() |
45
|
|
|
{ |
46
|
|
|
$this->assertEquals('/foo', $this->filesystem->path()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function test_path_method_returns_path_relative_to_base_path_when_supplied_with_argument() |
50
|
|
|
{ |
51
|
|
|
$this->assertEquals('/foo'.DIRECTORY_SEPARATOR.'foo/bar.php', $this->filesystem->path('foo/bar.php')); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function test_path_method_returns_qualified_file_path_when_supplied_with_argument() |
55
|
|
|
{ |
56
|
|
|
$this->assertEquals('/foo'.DIRECTORY_SEPARATOR.'file.php', $this->filesystem->path('file.php')); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function test_path_method_returns_expected_value_for_nested_path_arguments() |
60
|
|
|
{ |
61
|
|
|
$this->assertEquals('/foo'.DIRECTORY_SEPARATOR.'directory/file.php', $this->filesystem->path('directory/file.php')); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function test_path_method_strips_trailing_directory_separators_from_argument() |
65
|
|
|
{ |
66
|
|
|
$this->assertEquals('/foo'.DIRECTORY_SEPARATOR.'file.php', $this->filesystem->path('\\/file.php/')); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function test_path_method_returns_expected_value_regardless_of_trailing_directory_separators_in_argument() |
70
|
|
|
{ |
71
|
|
|
$this->assertEquals('/foo'.DIRECTORY_SEPARATOR.'bar/file.php', $this->filesystem->path('\\/bar/file.php/')); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function test_vendor_path_method_exists() |
75
|
|
|
{ |
76
|
|
|
$this->assertTrue(method_exists(Filesystem::class, 'vendorPath')); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function test_vendor_path_method_returns_string() |
80
|
|
|
{ |
81
|
|
|
$this->assertIsString($this->filesystem->vendorPath()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function test_vendor_path_method_returns_qualified_file_path_when_supplied_with_argument() |
85
|
|
|
{ |
86
|
|
|
$this->assertEquals($this->filesystem->vendorPath('file.php'), $this->filesystem->vendorPath().'/file.php'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function test_vendor_path_method_returns_expected_value_regardless_of_trailing_directory_separators_in_argument() |
90
|
|
|
{ |
91
|
|
|
$this->assertEquals('/foo'.DIRECTORY_SEPARATOR.'vendor/hyde/framework/file.php', $this->filesystem->vendorPath('\\//file.php/')); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function test_copy_method() |
95
|
|
|
{ |
96
|
|
|
$this->assertTrue(method_exists(Filesystem::class, 'copy')); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function test_copy_method_returns_404_when_file_does_not_exist() |
100
|
|
|
{ |
101
|
|
|
$this->assertEquals(404, $this->filesystem->copy('foo/bar.php', 'foo/baz.php')); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function test_copy_method_returns_409_when_destination_file_exists() |
105
|
|
|
{ |
106
|
|
|
touch('foo'); |
107
|
|
|
touch('bar'); |
108
|
|
|
$this->assertEquals(409, $this->filesystem->copy('foo', 'bar')); |
109
|
|
|
unlink('foo'); |
110
|
|
|
unlink('bar'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function test_copy_method_overwrites_destination_file_when_overwrite_is_true() |
114
|
|
|
{ |
115
|
|
|
touch('foo'); |
116
|
|
|
touch('bar'); |
117
|
|
|
$this->assertTrue($this->filesystem->copy('foo', 'bar', true)); |
118
|
|
|
unlink('foo'); |
119
|
|
|
unlink('bar'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function test_get_model_source_path() |
123
|
|
|
{ |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function test_get_blade_page_path() |
127
|
|
|
{ |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function test_get_markdown_page_path() |
131
|
|
|
{ |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function test_get_markdown_post_path() |
135
|
|
|
{ |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function test_get_documentation_page_path() |
139
|
|
|
{ |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function test_get_site_output_path() |
143
|
|
|
{ |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function test_path_to_relative() |
147
|
|
|
{ |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|