Skip to content

Commit

Permalink
Add feature tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hanneskod committed Nov 11, 2018
1 parent a54f783 commit c1382a2
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 68 deletions.
1 change: 0 additions & 1 deletion .gitignore
@@ -1,4 +1,3 @@
/vendor
/composer.phar
/composer.lock
*.tmp.pdf
3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -13,6 +13,5 @@ install:
- bob install_dev_tools

script:

TODO:
- phpunit
- behat
5 changes: 2 additions & 3 deletions bob_config.php
Expand Up @@ -15,9 +15,8 @@

desc('Run behat feature tests');
task('behat', function() {
println('SKIPPED Behat feature tests!!');
#shell('behat --stop-on-failure');
#println('Behat feature tests passed');
shell('behat --stop-on-failure');
println('Behat feature tests passed');
});

desc('Run statical analysis using phpstan');
Expand Down
103 changes: 103 additions & 0 deletions features/bootstrap/FeatureContext.php
@@ -0,0 +1,103 @@
<?php

declare(strict_types = 1);

use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\Behat\Tester\Exception\PendingException;
use iio\libmergepdf\Merger;
use iio\libmergepdf\Pages;
use setasign\Fpdi\Tcpdf\Fpdi;
use setasign\Fpdi\PdfParser\StreamReader;

final class FeatureContext implements Context
{
/**
* @var Merger
*/
private $merger;

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

/**
* @var Fpdi
*/
private $fpdi;

public function __construct()
{
$this->fpdi = new Fpdi;
}

/**
* @Given the :driver driver
*/
public function theDriver(string $driver)
{
$driverClass = "iio\libmergepdf\Driver\\$driver";
$this->merger = new Merger(new $driverClass);
}

/**
* @Given a pdf
*/
public function aPdf()
{
$this->aPdfOfVersion('1.4');
}

/**
* @Given a pdf with pages :pages
*/
public function aPdfWithPages($pages)
{
$this->aPdfOfVersionWithPages('1.4', $pages);
}

/**
* @Given a pdf of version :version
*/
public function aPdfOfVersion(string $version)
{
$this->aPdfOfVersionWithPages($version, '');
}

/**
* @Given a pdf of version :version with pages :pages
*/
public function aPdfOfVersionWithPages(string $version, string $pages)
{
$this->merger->addFile(__DIR__ . "/../files/$version.pdf", new Pages($pages));
}

/**
* @When I merge
*/
public function iMerge()
{
$this->generatedPdf = $this->merger->merge();
}

/**
* @Then a pdf is generated
*/
public function aPdfIsGenerated()
{
$this->fpdi->setSourceFile(StreamReader::createByString($this->generatedPdf));
}

/**
* @Then a pdf with :expectedCount pages is generated
*/
public function aPdfWithPagesIsGenerated(string $expectedCount)
{
$pageCount = $this->fpdi->setSourceFile(StreamReader::createByString($this->generatedPdf));
if ($pageCount != $expectedCount) {
throw new Exception("A pdf with $pageCount pages was created, expected $expectedCount pages.");
}
}
}
Binary file added features/files/1.4.pdf
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
41 changes: 41 additions & 0 deletions features/merge.feature
@@ -0,0 +1,41 @@
Feature: Mergeing pdfs
In order to use lib
As a user
I need to be able to merge pdfs

Scenario: I merge two pdfs using the fpdi driver
Given the "Fpdi2Driver" driver
And a pdf
And a pdf
When I merge
Then a pdf is generated

Scenario: I merge selected pages using the fpdi driver
Given the "Fpdi2Driver" driver
And a pdf with pages "1"
And a pdf with pages "1-2"
When I merge
Then a pdf with "3" pages is generated

Scenario: I merge two pdfs using the tcpdi driver
Given the "TcpdiDriver" driver
And a pdf
And a pdf
When I merge
Then a pdf is generated

Scenario: I merge selected pages using the tcpdi driver
Given the "TcpdiDriver" driver
And a pdf with pages "1"
And a pdf with pages "1-2"
When I merge
Then a pdf with "3" pages is generated

Scenario: I merge pdfs of versions later than 1.4
Given the "TcpdiDriver" driver
And a pdf of version "1.4" with pages "1"
And a pdf of version "1.5" with pages "1"
And a pdf of version "1.6" with pages "1"
And a pdf of version "1.7" with pages "1"
When I merge
Then a pdf with "4" pages is generated
File renamed without changes.
3 changes: 3 additions & 0 deletions src/Driver/TcpdiDriver.php
Expand Up @@ -16,6 +16,9 @@ final class TcpdiDriver implements DriverInterface

public function __construct(\TCPDI $tcpdi = null)
{
// TODO A stupid hack to hide deprecation notice
@each($arr = []);

$this->tcpdi = $tcpdi ?: new \TCPDI;
}

Expand Down
Binary file removed tests/A.pdf
Binary file not shown.
62 changes: 0 additions & 62 deletions tests/IntegrationTest.php

This file was deleted.

0 comments on commit c1382a2

Please sign in to comment.