Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
Merge bd64ce0 into 120fc00
Browse files Browse the repository at this point in the history
  • Loading branch information
rodnaph committed Dec 28, 2020
2 parents 120fc00 + bd64ce0 commit 085be1f
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 35 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: "Continuous Integration"

on:
pull_request:
pull_request_target:
push:
branches:
- master

jobs:
ci:
name: "Run Build"
runs-on: ubuntu-latest

strategy:
matrix:
php-version:
- 7.1

services:
gotenberg:
image: thecodingmachine/gotenberg:6
ports:
- 3000:3000

steps:
- name: "Checkout"
uses: actions/checkout@v2

- name: "Install PHP"
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: ${{ matrix.php-version }}
tools: composer:v2

- name: "Install Dependencies"
run: composer install

- name: "Run csfix"
run: composer run csfix

- name: "Run cscheck"
run: composer run cscheck

- name: "Run phpstan"
run: composer run phpstan

- name: "Run Tests"
run: composer run phpunit
env:
GOTENBERG_API_URL: 'localhost:3000'
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@
"php-http/httplug": ">=1.0",
"php-http/discovery": "^1.0",
"guzzlehttp/psr7": "^1.4.2",
"php-http/message": "^1.0",
"thecodingmachine/safe": "^1.0"
"php-http/message": "^1.0"
},
"require-dev" : {
"phpunit/phpunit": "^7",
"squizlabs/php_codesniffer": "^3.2",
"phpstan/phpstan": "^0.12.7",
"thecodingmachine/phpstan-safe-rule": "^1.0",
"thecodingmachine/phpstan-strict-rules": "^0.12.0",
"php-http/mock-client": "^1.0",
"php-http/guzzle6-adapter": "^1.1",
Expand Down
3 changes: 1 addition & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
includes:
- vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
- vendor/thecodingmachine/phpstan-safe-rule/phpstan-safe-rule.neon
- vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
11 changes: 6 additions & 5 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
use Http\Discovery\MessageFactoryDiscovery;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Safe\Exceptions\FilesystemException;
use function Safe\fclose;
use function Safe\fopen;
use function Safe\fwrite;
use function assert;
use function fclose;
use function fopen;
use function fwrite;
use function is_resource;

final class Client
{
Expand Down Expand Up @@ -47,7 +48,6 @@ public function post(GotenbergRequestInterface $request): ResponseInterface
* @throws ClientException
* @throws RequestException
* @throws Exception
* @throws FilesystemException
*/
public function store(GotenbergRequestInterface $request, string $destination): void
{
Expand All @@ -57,6 +57,7 @@ public function store(GotenbergRequestInterface $request, string $destination):
$response = $this->handleResponse($this->client->sendRequest($this->makeMultipartFormDataRequest($request)));
$fileStream = $response->getBody();
$fp = fopen($destination, 'w');
assert(is_resource($fp));
fwrite($fp, $fileStream->getContents());
fclose($fp);
}
Expand Down
11 changes: 5 additions & 6 deletions src/DocumentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

use GuzzleHttp\Psr7\LazyOpenStream;
use Psr\Http\Message\StreamInterface;
use Safe\Exceptions\FilesystemException;
use function assert;
use function fopen;
use function fwrite;
use function GuzzleHttp\Psr7\stream_for;
use function Safe\fopen;
use function Safe\fwrite;
use function is_resource;

final class DocumentFactory
{
Expand All @@ -23,12 +24,10 @@ public static function makeFromStream(string $fileName, StreamInterface $fileStr
return new Document($fileName, $fileStream);
}

/**
* @throws FilesystemException
*/
public static function makeFromString(string $fileName, string $string): Document
{
$fileStream = fopen('php://memory', 'rb+');
assert(is_resource($fileStream));
fwrite($fileStream, $string);

return new Document($fileName, stream_for($fileStream));
Expand Down
18 changes: 10 additions & 8 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

use HTTP\Client\Exception;
use PHPUnit\Framework\TestCase;
use Safe\Exceptions\FilesystemException;
use function getenv;

final class ClientTest extends TestCase
{
public const API_URL = 'gotenberg:3000';

/** @var HTMLRequest */
private $HTMLRequest;

Expand All @@ -27,6 +25,9 @@ final class ClientTest extends TestCase
/** @var MergeRequest */
private $mergeRequest;

/** @var string */
private $apiUrl;

/**
* @throws RequestException
*/
Expand All @@ -37,6 +38,7 @@ public function setUp(): void
$this->markdownRequest = $this->createMarkdownRequest();
$this->officeRequest = $this->createOfficeRequest();
$this->mergeRequest = $this->createMergeRequest();
$this->apiUrl = getenv('GOTENBERG_API_URL') ?: 'gotenberg:3000';
}

/**
Expand Down Expand Up @@ -151,7 +153,7 @@ public function createMergeRequest(): MergeRequest
*/
public function testPost(): void
{
$client = new Client(self::API_URL, new \Http\Adapter\Guzzle6\Client());
$client = new Client($this->apiUrl, new \Http\Adapter\Guzzle6\Client());
// case 1: HTML.
$response = $client->post($this->HTMLRequest);
$this->assertEquals($response->getHeaderLine('Content-Type'), 'application/pdf');
Expand Down Expand Up @@ -181,7 +183,7 @@ public function testPost(): void
*/
public function testStore(): void
{
$client = new Client(self::API_URL);
$client = new Client($this->apiUrl);
// case 1: HTML.
$filePath = __DIR__ . '/store/resultHTML.pdf';
$client->store($this->HTMLRequest, $filePath);
Expand Down Expand Up @@ -210,7 +212,7 @@ public function testStore(): void
*/
public function testPageRanges(): void
{
$client = new Client(self::API_URL, new \Http\Adapter\Guzzle6\Client());
$client = new Client($this->apiUrl, new \Http\Adapter\Guzzle6\Client());
// case 1: HTML.
$request = $this->createHTMLRequest();
$request->setPageRanges('1-1');
Expand Down Expand Up @@ -242,7 +244,7 @@ public function testPageRanges(): void
*/
public function testWebhook(): void
{
$client = new Client(self::API_URL, new \Http\Adapter\Guzzle6\Client());
$client = new Client($this->apiUrl, new \Http\Adapter\Guzzle6\Client());
$request = $this->createMergeRequest();
$request->setWebhookURL('https://google.com');
$request->setWebhookURLTimeout(5.0);
Expand All @@ -257,7 +259,7 @@ public function testWebhook(): void
*/
public function testRemoteURLHTTPHeader(): void
{
$client = new Client(self::API_URL, new \Http\Adapter\Guzzle6\Client());
$client = new Client($this->apiUrl, new \Http\Adapter\Guzzle6\Client());
$request = $this->createURLRequest();
$request->addRemoteURLHTTPHeader('A-Header', 'Foo');
$response = $client->post($request);
Expand Down
1 change: 0 additions & 1 deletion tests/DocumentFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use GuzzleHttp\Psr7\LazyOpenStream;
use PHPUnit\Framework\TestCase;
use Safe\Exceptions\FilesystemException;

final class DocumentFactoryTest extends TestCase
{
Expand Down

0 comments on commit 085be1f

Please sign in to comment.