Skip to content
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

Port atoum tests to PHPUnit #300

Merged
merged 12 commits into from
Jun 4, 2020
Merged
60 changes: 0 additions & 60 deletions .atoum.php

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/coverage/*
/samples/*
/vendor/*
/test*
/xdebug/*
/composer.phar
/composer
Expand Down
4 changes: 3 additions & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ return PhpCsFixer\Config::create()
->files()
->in(__DIR__ . '/samples')
->in(__DIR__ . '/src')
->in(__DIR__ . '/test')
->in(__DIR__ . '/tests')
->name('*.php')
);
);
11 changes: 11 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# For more information about code coverage
# See: https://scrutinizer-ci.com/docs/build/code_coverage
build:
nodes:
coverage:
tests:
override:
- command: vendor/bin/phpunit --coverage-clover coverage/clover.xml
coverage:
file: coverage/clover.xml
format: clover
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ jobs:
include:
- php: 7.2
env: COMPOSER_FLAGS="--prefer-lowest"
- php: 7.4
env: COVERAGE_FLAGS="--coverage-clover coverage/clover.xml"

install:
- composer self-update
- composer update --prefer-dist --no-progress --no-suggest --optimize-autoloader $COMPOSER_FLAGS

script: ./vendor/bin/atoum -d src/Smalot/PdfParser/Tests/ -ncc
script: vendor/bin/phpunit $COVERAGE_FLAGS
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@
"tecnickcom/tcpdf": "^6.2.22"
},
"require-dev": {
"atoum/atoum": "^3.1",
"phpunit/phpunit": "^5.7.27|^6",
"friendsofphp/php-cs-fixer": "^2.16.3"
},
"autoload": {
"psr-0": {
"Smalot\\PdfParser\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Test\\Smalot\\PdfParser\\": "test/",
"Tests\\Smalot\\PdfParser\\": "tests/"
k00ni marked this conversation as resolved.
Show resolved Hide resolved
}
},
"config": {
"process-timeout": 1200
}
Expand Down
35 changes: 35 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true"
>
<php>
<ini name="error_reporting" value="-1" />
<ini name="zend.enable_gc" value="0"/>
<ini name="error_reporting" value="-1"/>
<ini name="intl.error_level" value="0"/>
<ini name="display_errors" value="On"/>
</php>

<testsuites>
<testsuite name="all">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
</phpunit>
3 changes: 0 additions & 3 deletions src/Smalot/PdfParser/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ class Element
*/
protected $document = null;

/**
* @var mixed
*/
protected $value = null;

/**
Expand Down
42 changes: 16 additions & 26 deletions src/Smalot/PdfParser/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
use Smalot\PdfParser\Element\ElementNull;
use Smalot\PdfParser\Element\ElementXRef;

/**
* Class Page
*/
class Page extends PDFObject
{
/**
Expand Down Expand Up @@ -272,16 +269,13 @@ public function getTextArray(self $page = null)
return [];
}

/*
/**
* Gets all the text data with its internal representation of the page.
*
* @return array An array with the data and the internal representation
*
*/

public function extractRawData()
{
$text = $this->getText();
/*
* Now you can get the complete content of the object with the text on it
*/
Expand Down Expand Up @@ -313,14 +307,13 @@ public function extractRawData()
return $extractedData;
}

/*
/**
* Gets all the decoded text data with it internal representation from a page.
*
* @param array $extractedRawData the extracted data return by extractRawData or
* null if extractRawData should be called
*
* @return array An array with the data and the internal representation
*
*/
public function extractDecodedRawData($extractedRawData = null)
{
Expand All @@ -331,14 +324,13 @@ public function extractDecodedRawData($extractedRawData = null)
$currentFont = null;
foreach ($extractedRawData as &$command) {
if ('Tj' == $command['o'] or 'TJ' == $command['o']) {
$text = [];
$data = $command['c'];
if (!\is_array($data)) {
if (isset($currentFont)) {
$tmpText = $currentFont->decodeOctal($data);
//$tmpText = $currentFont->decodeHexadecimal($tmpText, false);
}
$tmpText = $tjText = str_replace(
$tmpText = str_replace(
['\\\\', '\(', '\)', '\n', '\r', '\t', '\ '],
['\\', '(', ')', "\n", "\r", "\t", ' '],
$tmpText
Expand All @@ -360,7 +352,7 @@ public function extractDecodedRawData($extractedRawData = null)
$decodedText = $currentFont->decodeOctal($tmpText);
//$tmpText = $currentFont->decodeHexadecimal($tmpText, false);
}
$decodedText = $tjText = str_replace(
$decodedText = str_replace(
['\\\\', '\(', '\)', '\n', '\r', '\t', '\ '],
['\\', '(', ')', "\n", "\r", "\t", ' '],
$decodedText
Expand All @@ -382,18 +374,17 @@ public function extractDecodedRawData($extractedRawData = null)
return $extractedRawData;
}

/*
/**
* Gets just the Text commands that are involved in text positions and
* Text Matrix (Tm)
*
* It extract just the PDF commands that are involved with text positions, and
* the Text Matrix (Tm). These are: BT, ET, TL, Td, TD, Tm, T*, Tj, ', ", and TJ
*
* @param array $extractedDecodedRawData The data extracted by extractDecodeRawData
if it is null, the method extractDecodeRawData is called.
k00ni marked this conversation as resolved.
Show resolved Hide resolved
* @param array $extractedDecodedRawData The data extracted by extractDecodeRawData.
* If it is null, the method extractDecodeRawData is called.
*
* @return array An array with the text command of the page
*
*/
public function getDataCommands($extractedDecodedRawData = null)
{
Expand Down Expand Up @@ -527,7 +518,7 @@ public function getDataCommands($extractedDecodedRawData = null)
return $extractedData;
}

/*
/**
* Gets the Text Matrix of the text in the page
*
* Return an array where every item is an array where the first item is the
Expand All @@ -536,12 +527,11 @@ public function getDataCommands($extractedDecodedRawData = null)
* text. The first 4 numbers has to be with Scalation, Rotation and Skew of the text.
*
* @param array $dataCommands the data extracted by getDataCommands
* if null getDataCommands is called.
* if null getDataCommands is called
*
* @return array An array with the data of the page including the Tm information
* of any text in the page.
* @return array an array with the data of the page including the Tm information
* of any text in the page
*/

public function getDataTm($dataCommands = null)
{
if (!isset($dataCommands) or !$dataCommands) {
Expand Down Expand Up @@ -731,17 +721,17 @@ public function getDataTm($dataCommands = null)
return $extractedData;
}

/*
/**
* Gets text data that are around the given coordinates (X,Y)
*
* If the text is in near the given coordinates (X,Y) (or the TM info),
* the text is returned. The extractedData return by getDataTm, could be use to see
* where is the coordinates of a given text, using the TM info for it.
*
* @param float $x The X value of the coordinate to search for. if null
* just the Y value is considered (same Row)
* @param float $y The Y value of the coordinate to search for
* just the X value is considered (same column)
* @param float $x The X value of the coordinate to search for. if null
* just the Y value is considered (same Row)
* @param float $y The Y value of the coordinate to search for
* just the X value is considered (same column)
* @param float $xError The value less or more to consider an X to be "near"
* @param float $yError The value less or more to consider an Y to be "near"
*
Expand Down
Loading