diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml new file mode 100644 index 0000000..0d399e6 --- /dev/null +++ b/.github/workflows/unit-tests.yaml @@ -0,0 +1,24 @@ +name: "Unit Tests" + +on: + pull_request: + push: + workflow_dispatch: + +jobs: + unit-tests: + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: ['7.2', '7.3', '7.4', '8.0'] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + - name: Install dependencies + run: composer install --no-interaction --no-ansi + - name: PHPUnit + run: php vendor/bin/phpunit diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ea22c30..0000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: php - -php: - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - hhvm - -sudo: false - -env: - - COMPOSER_OPTS="" - - COMPOSER_OPTS="--prefer-lowest" - -before_script: - - travis_retry composer self-update - - travis_retry composer update $COMPOSER_OPTS - -script: - - php vendor/bin/phpunit \ No newline at end of file diff --git a/composer.json b/composer.json index 77443f3..d3b6ddb 100644 --- a/composer.json +++ b/composer.json @@ -11,12 +11,12 @@ } ], "require": { - "league/glide": "^1.0", + "league/glide": "^2.0", "symfony/http-foundation": "^2.3|^3.0|^4.0|^5.0" }, "require-dev": { - "mockery/mockery": "^0.9", - "phpunit/phpunit": "^4.0" + "mockery/mockery": "^1.3.3", + "phpunit/phpunit": "^8.5|^9.4" }, "autoload": { "psr-4": { diff --git a/src/Responses/SymfonyResponseFactory.php b/src/Responses/SymfonyResponseFactory.php index 5350af7..ca4c1c5 100644 --- a/src/Responses/SymfonyResponseFactory.php +++ b/src/Responses/SymfonyResponseFactory.php @@ -2,7 +2,7 @@ namespace League\Glide\Responses; -use League\Flysystem\FilesystemInterface; +use League\Flysystem\FilesystemOperator; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\StreamedResponse; @@ -25,23 +25,23 @@ public function __construct(Request $request = null) /** * Create the response. - * @param FilesystemInterface $cache The cache file system. + * @param FilesystemOperator $cache The cache file system. * @param string $path The cached file path. * @return StreamedResponse The response object. */ - public function create(FilesystemInterface $cache, $path) + public function create(FilesystemOperator $cache, $path) { $stream = $cache->readStream($path); $response = new StreamedResponse(); - $response->headers->set('Content-Type', $cache->getMimetype($path)); - $response->headers->set('Content-Length', $cache->getSize($path)); + $response->headers->set('Content-Type', $cache->mimeType($path)); + $response->headers->set('Content-Length', $cache->fileSize($path)); $response->setPublic(); $response->setMaxAge(31536000); $response->setExpires(date_create()->modify('+1 years')); if ($this->request) { - $response->setLastModified(date_create()->setTimestamp($cache->getTimestamp($path))); + $response->setLastModified(date_create()->setTimestamp($cache->lastModified($path))); $response->isNotModified($this->request); } diff --git a/tests/Responses/SymfonyResponseFactoryTest.php b/tests/Responses/SymfonyResponseFactoryTest.php index 6336a12..6250077 100644 --- a/tests/Responses/SymfonyResponseFactoryTest.php +++ b/tests/Responses/SymfonyResponseFactoryTest.php @@ -1,39 +1,41 @@ assertInstanceOf( + self::assertInstanceOf( 'League\Glide\Responses\SymfonyResponseFactory', new SymfonyResponseFactory() ); } - public function testCreate() + public function testCreate(): void { - $this->cache = Mockery::mock('League\Flysystem\FilesystemInterface', function ($mock) { - $mock->shouldReceive('getMimetype')->andReturn('image/jpeg')->once(); - $mock->shouldReceive('getSize')->andReturn(0)->once(); + $cache = Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $mock->shouldReceive('mimeType')->andReturn('image/jpeg')->once(); + $mock->shouldReceive('fileSize')->andReturn(0)->once(); $mock->shouldReceive('readStream'); }); $factory = new SymfonyResponseFactory(); - $response = $factory->create($this->cache, ''); + $response = $factory->create($cache, ''); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response); - $this->assertEquals('image/jpeg', $response->headers->get('Content-Type')); - $this->assertEquals('0', $response->headers->get('Content-Length')); - $this->assertContains(gmdate('D, d M Y H:i', strtotime('+1 years')), $response->headers->get('Expires')); - $this->assertEquals('max-age=31536000, public', $response->headers->get('Cache-Control')); + self::assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response); + self::assertEquals('image/jpeg', $response->headers->get('Content-Type')); + self::assertEquals('0', $response->headers->get('Content-Length')); + self::assertStringContainsString(gmdate('D, d M Y H:i', strtotime('+1 years')), $response->headers->get('Expires')); + self::assertEquals('max-age=31536000, public', $response->headers->get('Cache-Control')); } }