-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExistenceCheckerTest.php
More file actions
163 lines (139 loc) · 4.14 KB
/
ExistenceCheckerTest.php
File metadata and controls
163 lines (139 loc) · 4.14 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
163
<?php
declare(strict_types=1);
/**
* This file is part of fast-forward/dev-tools.
*
* This source file is subject to the license bundled
* with this source code in the file LICENSE.
*
* @copyright Copyright (c) 2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
* @license https://opensource.org/licenses/MIT MIT License
*
* @see https://github.com/php-fast-forward/dev-tools
* @see https://github.com/php-fast-forward
* @see https://datatracker.ietf.org/doc/html/rfc2119
*/
namespace FastForward\DevTools\Tests\GitAttributes;
use FastForward\DevTools\GitAttributes\ExistenceChecker;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Symfony\Component\Filesystem\Filesystem;
#[CoversClass(ExistenceChecker::class)]
final class ExistenceCheckerTest extends TestCase
{
use ProphecyTrait;
/**
* @property ObjectProphecy<Filesystem> $filesystem
*/
private ObjectProphecy $filesystem;
private ExistenceChecker $checker;
/**
* @return void
*/
protected function setUp(): void
{
$this->filesystem = $this->prophesize(Filesystem::class);
$this->checker = new ExistenceChecker($this->filesystem->reveal());
}
/**
* @return void
*/
#[Test]
public function existsWillReturnTrueWhenPathExists(): void
{
$this->filesystem->exists('/project/.github/')
->willReturn(true)
->shouldBeCalledOnce();
self::assertTrue($this->checker->exists('/project', '/.github/'));
}
/**
* @return void
*/
#[Test]
public function existsWillReturnFalseWhenPathDoesNotExist(): void
{
$this->filesystem->exists('/project/.nonexistent/')
->willReturn(false)
->shouldBeCalledOnce();
self::assertFalse($this->checker->exists('/project', '/.nonexistent/'));
}
/**
* @return void
*/
#[Test]
public function filterExistingWillKeepOnlyExistingPaths(): void
{
$this->filesystem->exists('/project/.github/')
->willReturn(true);
$this->filesystem->exists('/project/README.md')
->willReturn(false);
$this->filesystem->exists('/project/docs/')
->willReturn(true);
$result = $this->checker->filterExisting('/project', ['/.github/', '/README.md', '/docs/']);
self::assertSame(['/.github/', '/docs/'], $result);
}
/**
* @return void
*/
#[Test]
public function filterExistingWillReturnEmptyArrayWhenNoneExist(): void
{
$this->filesystem->exists('/project/fake1')
->willReturn(false);
$this->filesystem->exists('/project/fake2')
->willReturn(false);
$result = $this->checker->filterExisting('/project', ['/fake1', '/fake2']);
self::assertSame([], $result);
}
/**
* @return void
*/
#[Test]
public function isDirectoryWillReturnTrueForDirectory(): void
{
self::assertTrue($this->checker->isDirectory(__DIR__, ''));
}
/**
* @return void
*/
#[Test]
public function isDirectoryWillReturnFalseForFile(): void
{
self::assertFalse($this->checker->isDirectory(__DIR__, '/ExistenceCheckerTest.php'));
}
/**
* @return void
*/
#[Test]
public function isFileWillReturnTrueForFile(): void
{
self::assertTrue($this->checker->isFile(__DIR__, '/ExistenceCheckerTest.php'));
}
/**
* @return void
*/
#[Test]
public function isFileWillReturnFalseForDirectory(): void
{
self::assertFalse($this->checker->isFile(__DIR__, ''));
}
/**
* @return void
*/
#[Test]
public function isDirectoryWillReturnFalseForNonExistent(): void
{
self::assertFalse($this->checker->isDirectory('/project', '/nonexistent'));
}
/**
* @return void
*/
#[Test]
public function isFileWillReturnFalseForNonExistent(): void
{
self::assertFalse($this->checker->isFile('/project', '/nonexistent.php'));
}
}