Skip to content

Commit df18f4a

Browse files
committedDec 28, 2019
Add tests/travis
1 parent 6a756a9 commit df18f4a

8 files changed

+211
-6
lines changed
 

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
composer.phar
33
composer.lock
44
.DS_Store
5-
/.idea
5+
/.idea
6+
.phpunit.result.cache

‎.travis.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
language: php
2+
3+
matrix:
4+
include:
5+
- php: 7.1
6+
env: LARAVEL='5.8.*' TESTBENCH='3.8.*' COMPOSER_FLAGS='--prefer-lowest'
7+
- php: 7.1
8+
env: LARAVEL='5.8.*' TESTBENCH='3.8.*' COMPOSER_FLAGS='--prefer-stable'
9+
- php: 7.2
10+
env: LARAVEL='5.8.*' TESTBENCH='3.8.*' COMPOSER_FLAGS='--prefer-lowest'
11+
- php: 7.2
12+
env: LARAVEL='5.8.*' TESTBENCH='3.8.*' COMPOSER_FLAGS='--prefer-stable'
13+
- php: 7.3
14+
env: LARAVEL='5.8.*' TESTBENCH='3.8.*' COMPOSER_FLAGS='--prefer-lowest'
15+
- php: 7.3
16+
env: LARAVEL='5.8.*' TESTBENCH='3.8.*' COMPOSER_FLAGS='--prefer-stable'
17+
- php: 7.4
18+
env: LARAVEL='5.8.*' TESTBENCH='3.8.*' COMPOSER_FLAGS='--prefer-lowest'
19+
- php: 7.4
20+
env: LARAVEL='5.8.*' TESTBENCH='3.8.*' COMPOSER_FLAGS='--prefer-stable'
21+
- php: 7.2
22+
env: LARAVEL='6.*' TESTBENCH='4.*' COMPOSER_FLAGS='--prefer-lowest'
23+
- php: 7.2
24+
env: LARAVEL='6.*' TESTBENCH='4.*' COMPOSER_FLAGS='--prefer-stable'
25+
- php: 7.3
26+
env: LARAVEL='6.*' TESTBENCH='4.*' COMPOSER_FLAGS='--prefer-lowest'
27+
- php: 7.3
28+
env: LARAVEL='6.*' TESTBENCH='4.*' COMPOSER_FLAGS='--prefer-stable'
29+
- php: 7.4
30+
env: LARAVEL='6.*' TESTBENCH='4.*' COMPOSER_FLAGS='--prefer-lowest'
31+
- php: 7.4
32+
env: LARAVEL='6.*' TESTBENCH='4.*' COMPOSER_FLAGS='--prefer-stable'
33+
- php: 7.2
34+
env: LARAVEL='7.*' TESTBENCH='5.*' COMPOSER_FLAGS='--prefer-lowest'
35+
- php: 7.2
36+
env: LARAVEL='7.*' TESTBENCH='5.*' COMPOSER_FLAGS='--prefer-stable'
37+
- php: 7.3
38+
env: LARAVEL='7.*' TESTBENCH='5.*' COMPOSER_FLAGS='--prefer-lowest'
39+
- php: 7.3
40+
env: LARAVEL='7.*' TESTBENCH='5.*' COMPOSER_FLAGS='--prefer-stable'
41+
- php: 7.4
42+
env: LARAVEL='7.*' TESTBENCH='5.*' COMPOSER_FLAGS='--prefer-lowest'
43+
- php: 7.4
44+
env: LARAVEL='7.*' TESTBENCH='5.*' COMPOSER_FLAGS='--prefer-stable'
45+
fast_finish: true
46+
47+
cache:
48+
directories:
49+
- $HOME/.composer/cache
50+
51+
before_script:
52+
- phpenv config-rm xdebug.ini || true
53+
54+
before_install:
55+
- travis_retry composer require "laravel/framework:${LARAVEL}" "orchestra/testbench:${TESTBENCH}" --no-interaction --no-update
56+
57+
install:
58+
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction --no-suggest
59+
60+
script:
61+
- vendor/bin/phpunit
62+
- vendor/bin/phpcs --standard=psr12 src/

‎composer.json

+20-5
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,28 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=7",
13+
"php": ">=7.1",
1414
"illuminate/support": "^5.5|^6",
15-
"dompdf/dompdf": "^0.8"
15+
"dompdf/dompdf": "^0.8.3"
16+
},
17+
"require-dev": {
18+
"orchestra/testbench": "^4",
19+
"squizlabs/php_codesniffer": "^3.5",
20+
"phpro/grumphp": "^0.16|^0.17"
1621
},
17-
1822
"autoload": {
1923
"psr-4": {
2024
"Barryvdh\\DomPDF\\": "src"
2125
}
2226
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"Barryvdh\\DomPDF\\Tests\\": "tests"
30+
}
31+
},
2332
"extra": {
2433
"branch-alias": {
25-
"dev-master": "0.8-dev"
34+
"dev-master": "1.0-dev"
2635
},
2736
"laravel": {
2837
"providers": [
@@ -33,5 +42,11 @@
3342
}
3443
}
3544
},
36-
"minimum-stability": "dev"
45+
"scripts": {
46+
"test": "phpunit",
47+
"check-style": "phpcs -p --standard=psr12 src/",
48+
"fix-style": "phpcbf -p --standard=psr12 src/"
49+
},
50+
"minimum-stability": "dev",
51+
"prefer-stable": true
3752
}

‎grumphp.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
parameters:
2+
git_dir: .
3+
bin_dir: vendor/bin
4+
tasks:
5+
phpunit:
6+
config_file: ~
7+
testsuite: ~
8+
group: []
9+
always_execute: false
10+
phpcs:
11+
standard: PSR12
12+
warning_severity: ~
13+
ignore_patterns:
14+
- tests/
15+
triggered_by: [php]

‎phpunit.xml.dist

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnError="false"
11+
stopOnFailure="false"
12+
verbose="true"
13+
>
14+
<testsuites>
15+
<testsuite name="Test Suite">
16+
<directory>./tests/</directory>
17+
</testsuite>
18+
</testsuites>
19+
<filter>
20+
<whitelist>
21+
<directory>./src</directory>
22+
</whitelist>
23+
</filter>
24+
</phpunit>

‎tests/PdfTest.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Barryvdh\DomPDF\Tests;
4+
5+
use Barryvdh\DomPDF\Facade;
6+
use Illuminate\Http\Response;
7+
8+
class PdfTest extends TestCase
9+
{
10+
public function testAlias()
11+
{
12+
$pdf = \PDF::loadHtml('<h1>Test</h1>');
13+
/** @var Response $response */
14+
$response = $pdf->download('test.pdf');
15+
16+
$this->assertInstanceOf(Response::class, $response);
17+
$this->assertNotEmpty($response->getContent());
18+
$this->assertEquals('application/pdf', $response->headers->get('Content-Type'));
19+
$this->assertEquals('attachment; filename="test.pdf"', $response->headers->get('Content-Disposition'));
20+
}
21+
22+
public function testDownload()
23+
{
24+
$pdf = Facade::loadHtml('<h1>Test</h1>');
25+
/** @var Response $response */
26+
$response = $pdf->download('test.pdf');
27+
28+
$this->assertInstanceOf(Response::class, $response);
29+
$this->assertNotEmpty($response->getContent());
30+
$this->assertEquals('application/pdf', $response->headers->get('Content-Type'));
31+
$this->assertEquals('attachment; filename="test.pdf"', $response->headers->get('Content-Disposition'));
32+
}
33+
34+
public function testStream()
35+
{
36+
$pdf = Facade::loadHtml('<h1>Test</h1>');
37+
/** @var Response $response */
38+
$response = $pdf->stream('test.pdf');
39+
40+
$this->assertInstanceOf(Response::class, $response);
41+
$this->assertNotEmpty($response->getContent());
42+
$this->assertEquals('application/pdf', $response->headers->get('Content-Type'));
43+
$this->assertEquals('inline; filename="test.pdf"', $response->headers->get('Content-Disposition'));
44+
}
45+
46+
public function testView()
47+
{
48+
$pdf = Facade::loadView('test');
49+
/** @var Response $response */
50+
$response = $pdf->download('test.pdf');
51+
52+
$this->assertInstanceOf(Response::class, $response);
53+
$this->assertNotEmpty($response->getContent());
54+
$this->assertEquals('application/pdf', $response->headers->get('Content-Type'));
55+
$this->assertEquals('attachment; filename="test.pdf"', $response->headers->get('Content-Disposition'));
56+
}
57+
58+
}

‎tests/TestCase.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Barryvdh\DomPDF\Tests;
4+
5+
use Barryvdh\DomPDF\Facade;
6+
use Barryvdh\DomPDF\ServiceProvider;
7+
use Illuminate\Support\Facades\View;
8+
9+
abstract class TestCase extends \Orchestra\Testbench\TestCase
10+
{
11+
protected function setUp() : void
12+
{
13+
parent::setUp();
14+
15+
View::addLocation(__DIR__.'/views');
16+
}
17+
18+
protected function getPackageProviders($app)
19+
{
20+
return [ServiceProvider::class];
21+
}
22+
23+
protected function getPackageAliases($app)
24+
{
25+
return [
26+
'PDF' => Facade::class,
27+
];
28+
}
29+
}

‎tests/views/test.blade.php

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Test</h1>

0 commit comments

Comments
 (0)
Please sign in to comment.