Repository navigation
Expand file tree
/
Copy pathFileWithVfsTest.php
More file actions
162 lines (134 loc) · 5.08 KB
/
Copy pathFileWithVfsTest.php
File metadata and controls
162 lines (134 loc) · 5.08 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Files;
use CodeIgniter\Test\CIUnitTestCase;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use PHPUnit\Framework\Attributes\Group;
/**
* @internal
*/
#[Group('Others')]
final class FileWithVfsTest extends CIUnitTestCase
{
// For VFS stuff
private ?vfsStreamDirectory $root = null;
private string $start;
private File $file;
protected function setUp(): void
{
parent::setUp();
$this->root = vfsStream::setup();
$path = '_support/Files/';
vfsStream::copyFromFileSystem(TESTPATH . $path, $this->root);
$this->start = $this->root->url() . '/';
$this->file = new File($this->start . 'able/apple.php');
}
protected function tearDown(): void
{
parent::tearDown();
$this->root = null;
}
public function testDestinationUnknown(): void
{
$destination = $this->start . 'charlie/cherry.php';
$this->assertSame($destination, $this->file->getDestination($destination));
}
public function testDestinationSameFileSameFolder(): void
{
$destination = $this->start . 'able/apple.php';
$this->assertSame($this->start . 'able/apple_1.php', $this->file->getDestination($destination));
}
public function testDestinationSameFileDifferentFolder(): void
{
$destination = $this->start . 'baker/apple.php';
$this->assertSame($destination, $this->file->getDestination($destination));
}
public function testDestinationDifferentFileSameFolder(): void
{
$destination = $this->start . 'able/date.php';
$this->assertSame($destination, $this->file->getDestination($destination));
}
public function testDestinationDifferentFileDifferentFolder(): void
{
$destination = $this->start . 'baker/date.php';
$this->assertSame($destination, $this->file->getDestination($destination));
}
public function testDestinationExistingFileDifferentFolder(): void
{
$destination = $this->start . 'baker/banana.php';
$this->assertSame($this->start . 'baker/banana_1.php', $this->file->getDestination($destination));
}
public function testDestinationDelimited(): void
{
$destination = $this->start . 'able/fig_3.php';
$this->assertSame($this->start . 'able/fig_4.php', $this->file->getDestination($destination));
}
public function testDestinationDelimitedAlpha(): void
{
$destination = $this->start . 'able/prune_ripe.php';
$this->assertSame($this->start . 'able/prune_ripe_1.php', $this->file->getDestination($destination));
}
public function testMoveNormal(): void
{
$destination = $this->start . 'baker';
$this->file->move($destination);
$this->assertTrue($this->root->hasChild('baker/apple.php'));
$this->assertFalse($this->root->hasChild('able/apple.php'));
}
public function testMoveRename(): void
{
$destination = $this->start . 'baker';
$this->file->move($destination, 'popcorn.php');
$this->assertTrue($this->root->hasChild('baker/popcorn.php'));
$this->assertFalse($this->root->hasChild('able/apple.php'));
}
public function testMoveOverwrite(): void
{
$destination = $this->start . 'baker';
$this->file->move($destination, 'banana.php', true);
$this->assertTrue($this->root->hasChild('baker/banana.php'));
$this->assertFalse($this->root->hasChild('able/apple.php'));
}
public function testMoveDontOverwrite(): void
{
$destination = $this->start . 'baker';
$this->file->move($destination, 'banana.php');
$this->assertTrue($this->root->hasChild('baker/banana_1.php'));
$this->assertFalse($this->root->hasChild('able/apple.php'));
}
public function testMoveFailure(): void
{
$this->expectException('Exception');
$here = $this->root->url();
chmod($here, 400); // make a read-only folder
$destination = $here . '/charlie';
$this->file->move($destination); // try to move our file there
}
/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/1782
*/
public function testMoveReturnsNewInstance(): void
{
$destination = $this->start . 'baker';
$file = $this->file->move($destination);
$this->assertTrue($this->root->hasChild('baker/apple.php'));
$this->assertInstanceOf(File::class, $file);
$this->assertSame($destination . '/apple.php', $file->getPathname());
}
public function testMovePermissions(): void
{
$destination = $this->start . 'baker';
$this->file->move($destination);
$expectedPerms = 0666 & ~umask();
$this->assertSame($expectedPerms, $this->root->getChild('baker/apple.php')->getPermissions());
}
}