Skip to content

Commit

Permalink
Maintenance on CodeBase (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaEstes authored Sep 10, 2024
1 parent 7d69eb7 commit 461fa76
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
12 changes: 8 additions & 4 deletions Adapter/InMemoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function remove(string $path, ?ContextInterface $context = null): void
{
$path = $this->normalizePath($path);

foreach ($this->files as $key => $value) {
foreach (array_keys($this->files) as $key) {
if ($path === $key || str_starts_with($key, $path)) {
unset($this->files[$key]);
}
Expand All @@ -73,7 +73,11 @@ public function move(string $source, string $destination, ?ContextInterface $con

public function has(string $path, ?ContextInterface $context = null): bool
{
return $this->isFile($path) || $this->isDirectory($path);
if ($this->isFile($path)) {
return true;
}

return $this->isDirectory($path);
}

public function isFile(string $path, ?ContextInterface $context = null): bool
Expand All @@ -87,7 +91,7 @@ public function isDirectory(string $path, ?ContextInterface $context = null): bo
{
$path = $this->normalizePath($path);

foreach ($this->files as $key => $contents) {
foreach (array_keys($this->files) as $key) {
$parts = explode('/', $key);
array_pop($parts);

Expand Down Expand Up @@ -115,7 +119,7 @@ public function removeDirectory(string $path, ?ContextInterface $context = null)
{
$path = $this->normalizePath($path);

foreach ($this->files as $key => $value) {
foreach (array_keys($this->files) as $key) {
if (str_starts_with($key, $path)) {
unset($this->files[$key]);
return;
Expand Down
6 changes: 5 additions & 1 deletion Adapter/NativeAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public function remove(string $path, ?ContextInterface $context = null): void

public function has(string $path, ?ContextInterface $context = null): bool
{
return $this->isFile($path, $context) || $this->isDirectory($path, $context);
if ($this->isFile($path, $context)) {
return true;
}

return $this->isDirectory($path, $context);
}

public function isFile(string $path, ?ContextInterface $context = null): bool
Expand Down
2 changes: 1 addition & 1 deletion Tests/Adapter/ChainAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class ChainAdapterTest extends TestCase
{
private array $adapters = [];

public function setUp(): void
protected function setUp(): void
{
$this->adapters[] = new InMemoryAdapter();
}
Expand Down
1 change: 1 addition & 0 deletions Tests/Adapter/NativeAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
final class NativeAdapterTest extends TestCase
{
private AdapterInterface $adapter;

private string $prefix;

protected function setUp(): void
Expand Down
2 changes: 1 addition & 1 deletion Tests/Adapter/ReadOnlyAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class ReadOnlyAdapterTest extends TestCase
{
private AdapterInterface|MockObject $adapter;

public function setUp(): void
protected function setUp(): void
{
$this->adapter = $this->createMock(AdapterInterface::class);
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Adapter/WormAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class WormAdapterTest extends TestCase
{
private AdapterInterface $adapter;

public function setUp(): void
protected function setUp(): void
{
$this->adapter = new InMemoryAdapter();
}
Expand Down
18 changes: 9 additions & 9 deletions Tests/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,37 @@ public function testItCanSetValues(): void
{
$context = new Context();

$this->assertFalse(isset($context['testing']));
$this->assertArrayNotHasKey('testing', $context);

$context['testing'] = true;
$this->assertTrue(isset($context['testing']));
$this->assertArrayHasKey('testing', $context);
$this->assertTrue($context['testing']);
}

public function testItCanCheckIfKeysAreSet(): void
{
$context = new Context();

$this->assertFalse(isset($context['testing']));
$this->assertArrayNotHasKey('testing', $context);
$context['testing'] = true;
$this->assertTrue(isset($context['testing']));
$this->assertArrayHasKey('testing', $context);

unset($context['testing']);
$this->assertFalse(isset($context['testing']));
$this->assertArrayNotHasKey('testing', $context);
}

public function testItCanUnsetKeys(): void
{
$context = new Context();

$this->assertFalse(isset($context['testing']));
$this->assertArrayNotHasKey('testing', $context);
unset($context['testing']);
$this->assertFalse(isset($context['testing']));
$this->assertArrayNotHasKey('testing', $context);

$context['test'] = true;
$this->assertTrue(isset($context['test']));
$this->assertArrayHasKey('test', $context);
unset($context['test']);
$this->assertFalse(isset($context['test']));
$this->assertArrayNotHasKey('test', $context);
}

public function testItCanGetValues(): void
Expand Down

0 comments on commit 461fa76

Please sign in to comment.