forked from phpactor/phpactor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdapterTestCase.php
106 lines (85 loc) · 3.74 KB
/
AdapterTestCase.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
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
<?php
namespace Phpactor\Filesystem\Tests\Adapter;
use Phpactor\Filesystem\Domain\Filesystem;
abstract class AdapterTestCase extends IntegrationTestCase
{
public function setUp(): void
{
$this->initWorkspace();
$this->loadProject();
}
public function testFind(): void
{
$fileList = $this->filesystem()->fileList();
$this->assertTrue($fileList->contains($this->filesystem()->createPath('src/Foobar.php')));
$location = $this->filesystem()->createPath('src/Hello/Goodbye.php');
$foo = $fileList->contains($location);
$this->assertTrue($foo);
}
public function testRemove(): void
{
$file = $this->filesystem()->createPath('src/Hello/Goodbye.php');
$this->assertTrue(file_exists($file->path()));
$this->filesystem()->remove($file);
$this->assertFalse(file_exists($file->path()));
}
public function testRemoveDirectory(): void
{
$file = $this->filesystem()->createPath('src/Hello');
$this->assertTrue(file_exists($file->path()));
$this->filesystem()->remove($file);
$this->assertFalse(file_exists($file->path()));
}
public function testMove(): void
{
$srcLocation = $this->filesystem()->createPath('src/Hello/Goodbye.php');
$destLocation = $this->filesystem()->createPath('src/Hello/Hello.php');
$this->filesystem()->move($srcLocation, $destLocation);
$this->assertTrue(file_exists($destLocation->path()));
$this->assertFalse(file_exists($srcLocation->path()));
}
public function testMoveDirectory(): void
{
$srcLocation = $this->filesystem()->createPath('src/Hello');
$destLocation = $this->filesystem()->createPath('src/Goodbye');
$this->filesystem()->move($srcLocation, $destLocation);
$this->assertTrue(file_exists($destLocation->path()));
$this->assertFalse(file_exists($srcLocation->path()));
$testFile = $this->filesystem()->createPath('src/Goodbye/Goodbye.php');
$this->assertTrue(file_exists($testFile->path()));
}
public function testCopy(): void
{
$srcLocation = $this->filesystem()->createPath('src/Hello/Goodbye.php');
$destLocation = $this->filesystem()->createPath('src/Hello/Hello.php');
$this->filesystem()->copy($srcLocation, $destLocation);
$this->assertTrue(file_exists($destLocation->path()));
$this->assertTrue(file_exists($srcLocation->path()));
}
public function testExists(): void
{
$path = $this->filesystem()->createPath('src/Hello/Goodbye.php');
$this->assertTrue($this->filesystem()->exists($path));
$path = $this->filesystem()->createPath('src/Hello/Plop.php');
$this->assertFalse($this->filesystem()->exists($path));
}
public function testCopyRecursive(): void
{
$srcLocation = $this->filesystem()->createPath('src');
$destLocation = $this->filesystem()->createPath('src/AAAn');
$list = $this->filesystem()->copy($srcLocation, $destLocation);
$this->assertTrue(file_exists($destLocation->path()));
$this->assertTrue(file_exists($srcLocation->path()));
$this->assertTrue(file_exists($srcLocation->path() . '/AAAn/Foobar.php'));
$this->assertTrue(file_exists($srcLocation->path() . '/AAAn/Hello/Goodbye.php'));
$this->assertCount(2, $list->srcFiles());
$this->assertCount(2, $list->destFiles());
}
public function testWriteGet(): void
{
$path = $this->filesystem()->createPath('src/Hello/Goodbye.php');
$this->filesystem()->writeContents($path, 'foo');
$this->assertEquals('foo', $this->filesystem()->getContents($path));
}
abstract protected function filesystem(): Filesystem;
}