Skip to content

Commit

Permalink
Merge pull request shlinkio#69 from acelaya-forks/feature/endroid-qr-…
Browse files Browse the repository at this point in the history
…code-4

Updated to endroid/qr-code 4.0
  • Loading branch information
acelaya authored Feb 28, 2021
2 parents 9549092 + 0302da5 commit d8b110d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:

unit-tests:
runs-on: ubuntu-20.04
continue-on-error: ${{ matrix.php-version == '8.0' }}
strategy:
matrix:
php-version: ['7.4', '8.0']
Expand All @@ -70,7 +69,6 @@ jobs:
needs:
- unit-tests
runs-on: ubuntu-20.04
continue-on-error: ${{ matrix.php-version == '8.0' }}
strategy:
matrix:
php-version: ['7.4', '8.0']
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## [3.6.0] - 2021-02-28
### Added
* [#68](https://github.com/shlinkio/shlink-common/issues/68) Added support for `endroid/qr-code` 4.0.

### Changed
* *Nothing*

### Deprecated
* *Nothing*

### Removed
* [#68](https://github.com/shlinkio/shlink-common/issues/68) Dropped support for `endroid/qr-code` 3.*.

### Fixed
* *Nothing*


## [3.5.0] - 2021-02-12
### Added
* [#60](https://github.com/shlinkio/shlink-common/issues/60) Added support for `pagerfanta/core` as a pagination system.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"akrabat/ip-address-middleware": "^2.0",
"cakephp/chronos": "^2.0",
"doctrine/orm": "^2.8.1",
"endroid/qr-code": "^3.6",
"endroid/qr-code": "^4.0",
"fig/http-message-util": "^1.1",
"guzzlehttp/guzzle": "^7.0",
"laminas/laminas-config": "^3.3",
Expand Down
10 changes: 5 additions & 5 deletions src/Response/QrCodeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Shlinkio\Shlink\Common\Response;

use Endroid\QrCode\QrCodeInterface;
use Endroid\QrCode\Writer\Result\ResultInterface;
use Fig\Http\Message\StatusCodeInterface as StatusCode;
use Laminas\Diactoros\Response;
use Laminas\Diactoros\Stream;
Expand All @@ -14,19 +14,19 @@ class QrCodeResponse extends Response
{
use Response\InjectContentTypeTrait;

public function __construct(QrCodeInterface $qrCode, int $status = StatusCode::STATUS_OK, array $headers = [])
public function __construct(ResultInterface $qrCode, int $status = StatusCode::STATUS_OK, array $headers = [])
{
parent::__construct(
$this->createBody($qrCode),
$status,
$this->injectContentType($qrCode->getContentType(), $headers),
$this->injectContentType($qrCode->getMimeType(), $headers),
);
}

private function createBody(QrCodeInterface $qrCode): StreamInterface
private function createBody(ResultInterface $qrCode): StreamInterface
{
$body = new Stream('php://temp', 'wb+');
$body->write($qrCode->writeString());
$body->write($qrCode->getString());
$body->rewind();
return $body;
}
Expand Down
8 changes: 4 additions & 4 deletions test/Response/QrCodeResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ShlinkioTest\Shlink\Common\Response;

use Endroid\QrCode\QrCode;
use Endroid\QrCode\Builder\Builder;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Common\Response\QrCodeResponse;

Expand All @@ -13,10 +13,10 @@ class QrCodeResponseTest extends TestCase
/** @test */
public function providedQrCodeIsSetAsBody(): void
{
$qrCode = new QrCode('Hello');
$qrCode = Builder::create()->data('Hello')->build();
$resp = new QrCodeResponse($qrCode);

self::assertEquals($qrCode->getContentType(), $resp->getHeaderLine('Content-Type'));
self::assertEquals($qrCode->writeString(), (string) $resp->getBody());
self::assertEquals($qrCode->getMimeType(), $resp->getHeaderLine('Content-Type'));
self::assertEquals($qrCode->getString(), (string) $resp->getBody());
}
}

0 comments on commit d8b110d

Please sign in to comment.