Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Casmo committed Mar 28, 2023
1 parent fe52ae5 commit 392e654
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/UploadcareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public function fileSize(string $path): FileAttributes
return $this->getFileinfo($path);
}

public function listContents(string $path, bool $deep): iterable
public function listContents(string $path = '', bool $deep = true): iterable
{
$result = $this->api->file()->listFiles();

Expand Down
5 changes: 0 additions & 5 deletions tests/ExampleTest.php

This file was deleted.

62 changes: 62 additions & 0 deletions tests/UploadcareAdapterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

use Illuminate\Http\UploadedFile;
use League\Flysystem\Config;
use League\Flysystem\FileAttributes;
use Uploadcare\Api;
use Uploadcare\Configuration;
use Vormkracht10\UploadcareAdapter\UploadcareAdapter;


beforeEach(function () {
$this->api = new Api(Configuration::create('demopublickey', 'demosecretkey'));

$this->uploadcareAdapter = new UploadcareAdapter($this->api, []);
});

it('writes and returns uuid', function () {
$uuid = $this->uploadcareAdapter->writeGetUuid('filename.txt', 'content', new Config());

expect($uuid)->toBeString();
});

it('does find existing files', function () {
$uuid = $this->uploadcareAdapter->writeGetUuid('filename.txt', 'content', new Config());

$exists = $this->uploadcareAdapter->fileExists($uuid);

expect($exists)->toBeTrue();
});

it('does not find invalid files', function () {
$exists = $this->uploadcareAdapter->fileExists('this-does-not-exists');

expect($exists)->toBeFalse();
});

it('writes streams and returns uuid', function() {
$uuid = $this->uploadcareAdapter->writeStreamGetUuid('filename.txt', tmpfile(), new Config());

expect($uuid)->toBeString();
});

it('writes uploadedfile and returns uuid', function() {
$uploadedFile = new UploadedFile(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'dummy.txt', 'dummy.txt');
$uuid = $this->uploadcareAdapter->putGetUuid('filename.txt', $uploadedFile);

expect($uuid)->toBeString();
});

it('does get information of a file', function () {
$uuid = $this->uploadcareAdapter->writeGetUuid('filename.txt', 'content', new Config());

$fileInfo = $this->uploadcareAdapter->getFileinfo($uuid);

expect($fileInfo)->toBeInstanceOf(FileAttributes::class);
});

it('does list files', function () {
$files = $this->uploadcareAdapter->listContents();

expect($files)->toBeIterable();
});
1 change: 1 addition & 0 deletions tests/files/dummy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content

0 comments on commit 392e654

Please sign in to comment.