Skip to content

Allow glide 3 and update testsuite #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
php-version: [8.1, 8.2, 8.3, 8.4]
symfony-version: [^5, ^6, ^7]
glide-version: [^2, ^3]
dependencies: [lowest, stable]
exclude:
- php-version: 8.1
symfony-version: ^7
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: ${{ matrix.php-version }}
- name: Install dependencies
run: composer install --no-interaction --no-ansi
run: |
composer require "symfony/http-foundation:${{ matrix.symfony-version }}" "league/glide:${{ matrix.glide-version }}" --no-interaction --no-update
composer update --prefer-${{ matrix.dependencies }} --prefer-dist --no-interaction --no-suggest --with-all-dependencies
- name: PHPUnit
run: php vendor/bin/phpunit
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
}
],
"require": {
"league/glide": "^2.0",
"symfony/http-foundation": "^2.3|^3.0|^4.0|^5.0|^6.0|^7.0"
"php": "^8.1",
"league/glide": "^2.0|^3.0",
"symfony/http-foundation": "^5|^6|^7"
},
"require-dev": {
"mockery/mockery": "^1.3.3",
"phpunit/phpunit": "^8.5|^9.4"
"phpunit/phpunit": "^10.5"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 4 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@
<directory suffix="Test.php">tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<source>
<include>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion src/Responses/SymfonyResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SymfonyResponseFactory implements ResponseFactoryInterface
* Create SymfonyResponseFactory instance.
* @param Request|null $request Request object to check "is not modified".
*/
public function __construct(Request $request = null)
public function __construct(?Request $request = null)
{
$this->request = $request;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Responses/SymfonyResponseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use League\Glide\Responses\SymfonyResponseFactory;
use Mockery;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;

class SymfonyResponseFactoryTest extends TestCase
{
Expand Down Expand Up @@ -38,4 +39,24 @@ public function testCreate(): void
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'));
}

public function testCreateWithRequest(): void
{
$cache = Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) {
$mock->shouldReceive('mimeType')->andReturn('image/jpeg')->once();
$mock->shouldReceive('fileSize')->andReturn(0)->once();
$mock->shouldReceive('readStream');
$mock->shouldReceive('lastModified')->andReturn(strtotime('2025-01-01'));
});

$factory = new SymfonyResponseFactory(new Request());
$response = $factory->create($cache, '');

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'));
self::assertEquals('Wed, 01 Jan 2025 00:00:00 GMT', $response->headers->get('Last-Modified'));
}
}