Skip to content

Commit bc8cdba

Browse files
committed
Adds test to cover Api::guessMimeType() when given directory path.
1 parent f6549eb commit bc8cdba

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/Api.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class Api implements ApiInterface
4040
const GITHUB_API_URL = 'https://api.github.com';
4141
const GITHUB_URL = 'https://github.com';
4242

43+
const MIME_TYPE_DIRECTORY = 'directory';
44+
4345
/** @var Client */
4446
private $client;
4547
/** @var Contents */
@@ -301,7 +303,7 @@ final public function guessMimeType($path)
301303
$meta = $this->getMetaData($path);
302304

303305
if ($this->hasKey($meta, self::KEY_TYPE) && $meta[self::KEY_TYPE] === self::KEY_DIRECTORY) {
304-
$mimeType = 'directory'; //application/x-directory
306+
$mimeType = self::MIME_TYPE_DIRECTORY; // or application/x-directory
305307
} else {
306308
$content = $this->getFileContents($path);
307309
$mimeType = MimeType::detectByContent($content);

tests/unit-tests/ApiTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,41 @@ final public function testApiShouldUseFileContentsToGuessMimeTypeWhenExtensionUn
403403
self::assertEquals($expected, $actual);
404404
}
405405

406+
/**
407+
* @covers ::guessMimeType
408+
*
409+
* @uses League\Flysystem\Util\MimeType
410+
* @uses Potherca\Flysystem\Github\Api::getFileContents
411+
* @uses Potherca\Flysystem\Github\Api::getMetaData
412+
*/
413+
final public function testApiShouldGuessMimeTypeCorrectlyWhenGivenPathIsDirectory()
414+
{
415+
$api = $this->api;
416+
417+
$expected = $api::MIME_TYPE_DIRECTORY;
418+
419+
$mockVendor = 'vendor';
420+
$mockPackage = 'package';
421+
$mockReference = 'reference';
422+
423+
$this->prepareMockSettings([
424+
'getVendor' => $mockVendor,
425+
'getPackage' => $mockPackage,
426+
'getReference' => $mockReference,
427+
]);
428+
429+
$this->prepareMockApi(
430+
'show',
431+
$api::API_REPO,
432+
[$mockVendor, $mockPackage, self::MOCK_FOLDER_PATH, $mockReference],
433+
[0 => [$api::KEY_TYPE => $api::MIME_TYPE_DIRECTORY]]
434+
);
435+
436+
$actual = $api->guessMimeType(self::MOCK_FOLDER_PATH);
437+
438+
self::assertEquals($expected, $actual);
439+
}
440+
406441
/**
407442
* @uses Potherca\Flysystem\Github\Api::exists
408443
*/

0 commit comments

Comments
 (0)