Skip to content
This repository has been archived by the owner on Jun 6, 2020. It is now read-only.

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
mgufrone committed Apr 27, 2016
1 parent e4e1e93 commit ebd678b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
14 changes: 8 additions & 6 deletions src/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public function __construct($file, $options=array())
}
public function getInfo()
{
if($this->info == null)
$this->info($this->file);
$this->checkInfo();
return $this->info;
}
protected function info()
Expand All @@ -37,16 +36,19 @@ protected function info()
}
public function html()
{
if($this->info == null)
$this->info($this->file);
$this->checkInfo();
return new Html($this->file);
}
public function getPages()
{
if($this->info == null)
$this->info($this->file);
$this->checkInfo();
return $this->info['pages'];
}

private function checkInfo(){
if($this->info == null)
$this->info();
}
public function bin()
{
return Config::get('pdfinfo.bin', '/usr/bin/pdfinfo');
Expand Down
5 changes: 4 additions & 1 deletion tests/HtmlParseTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php
use Gufy\PdfToHtml\Html;
use Gufy\PdfToHtml\Html,
Gufy\PdfToHtml\Config;
class HtmlParseTest extends PHPUnit_Framework_TestCase
{
public function testConvertAndCatch()
{
Config::set('pdfinfo.bin', '/usr/local/bin/pdfinfo');
Config::set('pdftohtml.bin', '/usr/local/bin/pdftohtml');
$pdf = dirname(__FILE__).'/source/test.pdf';
$html = new Html($pdf);
$this->assertInstanceOf('PHPHtmlParser\\Dom', $html);
Expand Down
2 changes: 2 additions & 0 deletions tests/PdfBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ class PdfBaseTest extends PHPUnit_Framework_TestCase
public function testConfiguration()
{
$pdf = new Base;
Config::set('pdftohtml.bin', '/usr/bin/pdftohtml');
$this->assertEquals('/usr/bin/pdftohtml', $pdf->bin());
Config::set('pdftohtml.bin', '/usr/local/bin/pdftohtml');
$this->assertEquals('/usr/local/bin/pdftohtml', $pdf->bin());
Config::set('pdftohtml.bin', '/usr/bin/pdftohtml');
}
public function testInfoConfiguration()
{
Config::set('pdfinfo.bin', '/usr/bin/pdfinfo');
$pdf = new Pdf(dirname(__FILE__).'/source/test.pdf');
$this->assertEquals('/usr/bin/pdfinfo', $pdf->bin());
Config::set('pdfinfo.bin', '/usr/local/bin/pdfinfo');
Expand Down
9 changes: 8 additions & 1 deletion tests/PdfInfoTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<?php
use Gufy\PdfToHtml\Pdf;
use Gufy\PdfToHtml\Pdf,
Gufy\PdfToHtml\Config;

class PdfInfoTest extends PHPUnit_Framework_TestCase
{
public function setUp(){
parent::setUp();

Config::set('pdfinfo.bin', '/usr/local/bin/pdfinfo');
Config::set('pdftohtml.bin', '/usr/local/bin/pdftohtml');
}
public function testGetOptions()
{
$file = dirname(__FILE__).'/source/test.pdf';
Expand Down
13 changes: 11 additions & 2 deletions tests/PdfToHtmlTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<?php

use Gufy\PdfToHtml\Base as PdfToHtml;
use Gufy\PdfToHtml\Base as PdfToHtml,
Gufy\PdfToHtml\Config;

class PdfToHtmlTest extends \PHPUnit_Framework_TestCase
{
public $bin;
public function setUp()
{
parent::setUp();
$this->bin = new PdfToHtml;

Config::set('pdfinfo.bin', '/usr/local/bin/pdfinfo');
Config::set('pdftohtml.bin', '/usr/local/bin/pdftohtml');
}
public function testOpen()
{
Expand Down Expand Up @@ -40,4 +45,8 @@ public function testGenerateSinglePage()
$this->assertTrue(count(scandir(__DIR__.'/results'))>=3);

$this->bin->clearOutputDirectory();
}}
}
public function getRawHtml(){

}
}

0 comments on commit ebd678b

Please sign in to comment.