Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 6 additions & 6 deletions src/Responses/SymfonyResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

Expand Down
32 changes: 17 additions & 15 deletions tests/Responses/SymfonyResponseFactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
<?php

namespace League\Glide\Responses;
namespace Responses;

use League\Glide\Responses\SymfonyResponseFactory;
use Mockery;
use PHPUnit\Framework\TestCase;

class SymfonyResponseFactoryTest extends \PHPUnit_Framework_TestCase
class SymfonyResponseFactoryTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
Mockery::close();
}

public function testCreateInstance()
public function testCreateInstance(): void
{
$this->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'));
}
}