Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Apr 30, 2023
1 parent 5c0886d commit ebe966d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 33 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"illuminate/http": "^8.0|^9.0|^10.0"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
"illuminate/config": "^8.0|^9.0|^10.0",
"illuminate/container": "^8.0|^9.0|^10.0",
"mikey179/vfsstream": "^1.6",
Expand Down
16 changes: 9 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false" bootstrap="tests/bootstrap.php"
backupGlobals="false"
bootstrap="tests/bootstrap.php"
colors="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<coverage/>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
6 changes: 3 additions & 3 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function path(): string
return rtrim($this->config['path'], '/').'/';
}

public function makeDirectory(string $path): Api
public function makeDirectory(string $path): ApiContract
{
if ($this->files->isDirectory($path) === false) {
$this->files->makeDirectory($path, 0777, true, true);
Expand All @@ -63,7 +63,7 @@ public function makeDirectory(string $path): Api
return $this;
}

public function cleanDirectory(string $path): Api
public function cleanDirectory(string $path): ApiContract
{
$time = time();
$maxFileAge = 3600;
Expand All @@ -90,7 +90,7 @@ public function receive(string $name)
: $this->request->file($name);
}

public function deleteUploadedFile($uploadedFile)
public function deleteUploadedFile($uploadedFile): ApiContract
{
$file = $uploadedFile->getPathname();
if ($this->files->isFile($file) === true) {
Expand Down
13 changes: 3 additions & 10 deletions src/Contracts/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@ public function domain(): string;

public function path(): string;

/**
* @return self
*/
public function makeDirectory(string $path);
public function makeDirectory(string $path): Api;

/**
* @return self
*/
public function cleanDirectory(string $path);
public function cleanDirectory(string $path): Api;

/**
* @return UploadedFile|SymfonyUploadedFile
Expand All @@ -32,9 +26,8 @@ public function receive(string $name);

/**
* @param UploadedFile|SymfonyUploadedFile $uploadedFile
* @return self
*/
public function deleteUploadedFile($uploadedFile);
public function deleteUploadedFile($uploadedFile): Api;

public function completedResponse(JsonResponse $response): JsonResponse;
}
25 changes: 12 additions & 13 deletions tests/ReceiverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ public function testReceive(): void
$uploadedFile->allows('getBasename')->once()->andReturn($basename = 'foo');
$uploadedFile->allows('getMimeType')->once()->andReturn($mimeType = 'foo');
$uploadedFile->allows('getSize')->once()->andReturn($size = 1000);
$uploadedFile->allows('move')->once()->with($path,
$filename = md5($basename).'.'.strtolower($clientOriginalExtension));
$uploadedFile->allows('move')->once()
->with($path, $filename = md5($basename).'.'.strtolower($clientOriginalExtension));

$api->allows('deleteUploadedFile')->once()->with($uploadedFile)->andReturnSelf();
$api->allows('completedResponse')->once()->with(m::type(JsonResponse::class))->andReturnUsing(function (
$response
) {
return $response;
});
$api->allows('completedResponse')->once()
->with(m::type(JsonResponse::class))->andReturnUsing(function ($response) {
return $response;
});

$response = $receiver->receive($inputName);
$this->assertSame([
Expand All @@ -63,12 +62,11 @@ public function testReceiveCustomCallback(): void
$api->allows('deleteUploadedFile')->once()->with($uploadedFile)->andReturnSelf();
$api->allows('completedResponse')->once()->with($response)->andReturn($response);

$this->assertSame(
$response,
$receiver->receive($inputName, function () use ($response) {
return $response;
})
);
$callback = function () use ($response) {
return $response;
};

$this->assertSame($response, $receiver->receive($inputName, $callback));
}

public function testReceiveAndThrowChunkedResponseException(): void
Expand All @@ -77,6 +75,7 @@ public function testReceiveAndThrowChunkedResponseException(): void
$inputName = 'foo';
$api->allows('receive')->once()->with($inputName)->andThrow(new ChunkedResponseException());
$callback = function () {
return new Response();
};

$this->assertInstanceOf(Response::class, $receiver->receive($inputName, $callback));
Expand Down

0 comments on commit ebe966d

Please sign in to comment.