Skip to content

Commit

Permalink
[TASK] Remove dev dependency mikey179/vfsstream
Browse files Browse the repository at this point in the history
  • Loading branch information
brotkrueml committed Dec 14, 2022
1 parent a292445 commit 465b8c2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"ergebnis/composer-normalize": "~2.28.3",
"infection/infection": "^0.26",
"maglnet/composer-require-checker": "^4.1",
"mikey179/vfsstream": "^1.6.10",
"php-coveralls/php-coveralls": "^2.5",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "1.9.3",
Expand Down
16 changes: 6 additions & 10 deletions tests/Unit/Client/RestClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
use Brotkrueml\JobRouterClient\Resource\FileInterface;
use donatj\MockWebServer\MockWebServer;
use donatj\MockWebServer\Response;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use PHPUnit\Framework\TestCase;

final class RestClientTest extends TestCase
Expand All @@ -33,7 +31,6 @@ final class RestClientTest extends TestCase

private static ClientConfiguration $configuration;
private static MockWebServer $server;
private vfsStreamDirectory $root;

public static function setUpBeforeClass(): void
{
Expand All @@ -52,11 +49,6 @@ public static function tearDownAfterClass(): void
self::$server->stop();
}

protected function setUp(): void
{
$this->root = vfsStream::setup();
}

/**
* @test
*/
Expand Down Expand Up @@ -431,7 +423,7 @@ public function formDataIsCorrectlySend(): void

$restClient = new RestClient(self::$configuration);

$filePath = $this->root->url() . '/some-file.txt';
$filePath = \tempnam('/tmp', 'jrc_');
\file_put_contents($filePath, 'foo');

$formData = [
Expand Down Expand Up @@ -475,6 +467,8 @@ public function formDataIsCorrectlySend(): void
$files = $lastRequest->getFiles();
self::assertArrayHasKey('processtable', $files);
self::assertSame('bar.txt', $files['processtable']['name']['fields'][1]['value']);

\unlink($filePath);
}

/**
Expand Down Expand Up @@ -527,7 +521,7 @@ public function requestUsingFileInterfaceIsHandledCorrectly(): void

$restClient = new RestClient(self::$configuration);

$filePath = $this->root->url() . '/some-file.txt';
$filePath = \tempnam('/tmp', 'jrc_');
\file_put_contents($filePath, 'foo');

$fileMock = $this->createMock(FileInterface::class);
Expand Down Expand Up @@ -563,5 +557,7 @@ public function requestUsingFileInterfaceIsHandledCorrectly(): void
$files = $lastRequest->getFiles();
self::assertArrayHasKey('processtable', $files);
self::assertSame('foo.txt', $files['processtable']['name']['fields'][0]['value']);

\unlink($filePath);
}
}
41 changes: 21 additions & 20 deletions tests/Unit/Resource/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,57 @@
use Brotkrueml\JobRouterClient\Exception\InvalidResourceException;
use Brotkrueml\JobRouterClient\Resource\File;
use Brotkrueml\JobRouterClient\Resource\FileInterface;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use PHPUnit\Framework\TestCase;

class FileTest extends TestCase
{
private vfsStreamDirectory $root;

protected function setUp(): void
{
$this->root = vfsStream::setup();
}

/**
* @test
*/
public function classImplementsFileInterface(): void
{
$path = $this->root->url() . '/some-file.txt';
$path = \tempnam('/tmp', 'jrc_');
\touch($path);

$subject = new File($path);

self::assertInstanceOf(FileInterface::class, $subject);

\unlink($path);
}

/**
* @test
*/
public function constructWithOnlyPathThenGettersAreImplementedCorrectly(): void
{
$path = $this->root->url() . '/some-file.txt';
$path = \tempnam('/tmp', 'jrc_');
\touch($path);

$subject = new File($path);

self::assertSame($path, $subject->getPath());
self::assertSame('some-file.txt', $subject->getFileName());
self::assertSame(\basename($path), $subject->getFileName());
self::assertSame('', $subject->getContentType());

\unlink($path);
}

/**
* @test
*/
public function constructWithAllArgumentsThenGettersAreImplementedCorrectly(): void
{
$path = $this->root->url() . '/some-file.txt';
$path = \tempnam('/tmp', 'jrc_');
\touch($path);

$subject = new File($path, 'other-filename.txt', 'foo/bar');

self::assertSame($path, $subject->getPath());
self::assertSame('other-filename.txt', $subject->getFileName());
self::assertSame('foo/bar', $subject->getContentType());

\unlink($path);
}

/**
Expand All @@ -80,47 +77,51 @@ public function constructThrowsExceptionWhenGivenPathDoesNotExist(): void
{
$this->expectException(InvalidResourceException::class);
$this->expectExceptionCode(1582273757);
$this->expectExceptionMessage('The file "vfs://root/not-existing-file.txt" does not exist or is not readable');
$this->expectExceptionMessage('The file "/tmp/not-existing-file.txt" does not exist or is not readable');

new File($this->root->url() . '/not-existing-file.txt');
new File('/tmp/not-existing-file.txt');
}

/**
* @test
*/
public function constructWithOnlyPathThenToArrayIsImplementedCorrectly(): void
{
$path = $this->root->url() . '/some-file.txt';
$path = \tempnam('/tmp', 'jrc_');
\touch($path);

$subject = new File($path);

self::assertSame(
[
'path' => 'vfs://root/some-file.txt',
'filename' => 'some-file.txt',
'path' => $path,
'filename' => \basename($path),
],
$subject->toArray()
);

\unlink($path);
}

/**
* @test
*/
public function constructWithAllArgumentsThenToArrayIsImplementedCorrectly(): void
{
$path = $this->root->url() . '/some-file.txt';
$path = \tempnam('/tmp', 'jrc_');
\touch($path);

$subject = new File($path, 'other-filename.txt', 'foo/bar');

self::assertSame(
[
'path' => 'vfs://root/some-file.txt',
'path' => $path,
'filename' => 'other-filename.txt',
'contentType' => 'foo/bar',
],
$subject->toArray()
);

\unlink($path);
}
}

0 comments on commit 465b8c2

Please sign in to comment.