Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dkreuer authored Apr 3, 2020
1 parent 5925232 commit ab32456
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 83 deletions.
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: php
php:
- "5.4"
- "5.3"
env:
- COMPOSER_COMMAND=install
- COMPOSER_COMMAND=update
install: composer $COMPOSER_COMMAND
- "7.4"
- "7.3"
- "7.2"
install: composer install
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
}
],
"require": {
"php": ">=5.3.10",
"metasyntactical/mime": "1.0.x",
"symfony/http-foundation": "^2.8.52|^3.4.34|~4.2.12|~4.3.8|^4.4|^5.0"
"php": "~7.2|~7.3|~7.4|~8.0",
"metasyntactical/mime": "^2.1.0",
"symfony/filesystem": "~4.4.0|~5.0",
"symfony/http-foundation": "^2.8.52|^3.4.34|~4.2.12|~4.3.8|^4.4|^5.0",
"symfony/mime": "~4.4.0|~5.0"
},
"autoload": {
"psr-0": {
Expand Down
27 changes: 0 additions & 27 deletions composer.lock

This file was deleted.

1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="autoload.php.dist"
>
<php>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace MetaSyntactical\Symfony\Component\HttpFoundation\File\MimeType;

use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
use Symfony\Component\Mime\MimeTypeGuesserInterface;
use Symfony\Component\Mime\Exception\InvalidArgumentException;
use Symfony\Component\Mime\Exception\LogicException;

use MetaSyntactical\Mime\Magic;

Expand All @@ -15,44 +15,22 @@
*/
class PhpMimeTypeGuesser implements MimeTypeGuesserInterface
{
/**
* Returns whether this guesser is supported on the current OS/PHP setup
*
* @return Boolean
*/
public static function isSupported()
public function isGuesserSupported(): bool
{
return class_exists('MetaSyntactical\\Mime\\Magic');
return class_exists(Magic::class);
}

/**
* {@inheritdoc}
*/
public function guess($path)
public function guessMimeType(string $path): ?string
{
if (!is_file($path)) {
throw new FileNotFoundException($path);
if (!is_file($path) || !is_readable($path)) {
throw new InvalidArgumentException(sprintf('The "%s" file does not exist or is not readable.', $path));
}

if (!is_readable($path)) {
// @codeCoverageIgnoreStart
throw new AccessDeniedException($path);
if (!$this->isGuesserSupported()) {
throw new LogicException(sprintf('The "%s" guesser is not supported.', __CLASS__));
}
// @codeCoverageIgnoreEnd

if (!self::isSupported()) {
// @codeCoverageIgnoreStart
return null;
}
// @codeCoverageIgnoreEnd

if (!$magic = new Magic()) {
// @codeCoverageIgnoreStart
return null;
}
// @codeCoverageIgnoreEnd

return $magic->getMimeType($path);
return (new Magic())->getMimeType($path);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
namespace MetaSyntactical\Symfony\Tests\Component\HttpFoundation\File\MimeType;

use MetaSyntactical\Symfony\Component\HttpFoundation\File\MimeType\PhpMimeTypeGuesser;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Mime\Exception\InvalidArgumentException;

/**
* Generated by PHPUnit_SkeletonGenerator on 2012-08-29 at 21:22:39.
*/
class PhpMimeTypeGuesserTest extends \PHPUnit_Framework_TestCase
class PhpMimeTypeGuesserTest extends TestCase
{
/**
* @var PhpMimeTypeGuesser
Expand All @@ -18,7 +20,7 @@ class PhpMimeTypeGuesserTest extends \PHPUnit_Framework_TestCase
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
protected function setUp(): void
{
$this->object = new PhpMimeTypeGuesser;
}
Expand All @@ -27,36 +29,35 @@ protected function setUp()
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
protected function tearDown(): void
{
}

/**
* @covers MetaSyntactical\Symfony\Component\HttpFoundation\File\MimeType\PhpMimeTypeGuesser::isSupported
*/
public function testGuesserIsSupported()
public function testGuesserIsSupported(): void
{
self::assertTrue(PhpMimeTypeGuesser::isSupported());
self::assertTrue((new PhpMimeTypeGuesser)->isGuesserSupported());
}

/**
* @covers MetaSyntactical\Symfony\Component\HttpFoundation\File\MimeType\PhpMimeTypeGuesser::guess
*/
public function testGuessingMimeTypeReturnsExpectedType()
public function testGuessingMimeTypeReturnsExpectedType(): void
{
$guess = $this->object->guess(__DIR__ . '/_Data/Fireworks_Australia_Day_11_-_2_(Public_Domain).jpg');
$guess = $this->object->guessMimeType(__DIR__ . '/_Data/Fireworks_Australia_Day_11_-_2_(Public_Domain).jpg');
self::assertEquals('image/jpeg', $guess);
}

/**
* @covers MetaSyntactical\Symfony\Component\HttpFoundation\File\MimeType\PhpMimeTypeGuesser::guess
*/
public function testGuessingMimeTypeOfNonExistingFileResultsInException()
public function testGuessingMimeTypeOfNonExistingFileResultsInException(): void
{
$this->setExpectedException(
'Symfony\\Component\\HttpFoundation\\File\\Exception\\FileNotFoundException',
'does not exist'
);
$this->object->guess(__DIR__ . '/_Data/NonExisting.jpg');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('file does not exist');

$this->object->guessMimeType(__DIR__ . '/_Data/NonExisting.jpg');
}
}

0 comments on commit ab32456

Please sign in to comment.