Skip to content
Permalink
Browse files

Adding Unit Testing

  • Loading branch information...
nyamsprod committed Jun 8, 2015
1 parent 125053b commit 7230a4de73ae5d369c5115936a889c51327caf77
Showing with 137 additions and 18 deletions.
  1. +3 −0 .gitattributes
  2. +3 −0 .gitignore
  3. +33 −0 phpunit.xml
  4. +9 −4 src/Converter.php
  5. +89 −0 test/ConverterTest.php
  6. BIN test/red-nose.gif
  7. +0 −14 test/test.php
@@ -0,0 +1,3 @@
/test export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
@@ -0,0 +1,3 @@
vendor
build
docs
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">

<testsuites>
<testsuite name="Px2svg Test suite">
<directory>test</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/clover.xml"/>
</logging>
</phpunit>
@@ -58,7 +58,7 @@ class Converter
*
* @return float Current threshold value
*/
public function getThreshold($threshold)
public function getThreshold()
{
return $this->threshold;
}
@@ -70,6 +70,11 @@ public function getThreshold($threshold)
*/
public function setThreshold($threshold)
{
if ($threshold <= 0 || $threshold > 255) {
throw new InvalidArgumentException(
'the submitted threshold is invalid, value must be between > 0 and < 255'
);
}
$this->threshold = $threshold;
return $this;
@@ -96,12 +101,12 @@ public function loadImage($path)
return $this;
}
public function getPath()
public function getCurrentImagePath()
{
return $this->path;
}
public function __close()
public function __destruct()
{
if (! is_null($this->image)) {
imagedestroy($this->image);
@@ -252,7 +257,7 @@ private function generateHorizontalSVG()
while (($x + $number_of_consecutive_pixels < $this->width) &&
($color_at_position == imagecolorat($this->image, ($x + $number_of_consecutive_pixels), $y))
) {
$number_of_consecutive_pixels++;
++$number_of_consecutive_pixels;
}
$rgb = imagecolorsforindex($this->image, $color_at_position);
@@ -0,0 +1,89 @@
<?php
namespace Px2svg\Test;
use PHPUnit_Framework_TestCase;
use Px2svg\Converter;
/**
* @group components
*/
class ConverterTest extends PHPUnit_Framework_TestCase
{
private $converter;
public function setUp()
{
$this->converter = new Converter();
}
public function tearDown()
{
$file = __DIR__.'/res.svg';
if (file_exists($file)) {
unlink($file);
}
}
public function testLoadImage()
{
$expected = __DIR__.'/gmail-bozo-tag.gif';
$this->converter->loadImage($expected);
$this->assertSame($expected, $this->converter->getCurrentImagePath());
}
/**
* @expectedException InvalidArgumentException
*/
public function testLoadImageFailed()
{
$this->converter->loadImage('/fsdfqds/fsd');
}
public function testThreshold()
{
$expected = 28.9;
$this->assertSame(0, $this->converter->getThreshold());
$this->converter->setThreshold($expected);
$this->assertSame($expected, $this->converter->getThreshold());
}
/**
* @expectedException InvalidArgumentException
*/
public function testThresholdFailed()
{
$this->converter->setThreshold(-1);
}
public function testToXML()
{
$this->converter->loadImage(__DIR__.'/test-vertical.png');
$res = $this->converter->toXML();
$this->assertInstanceOf('\DOMDocument', $res);
$this->converter = null;
}
/**
* @expectedException InvalidArgumentException
*/
public function testToFailed()
{
$res = $this->converter->toXML();
$this->assertInstanceOf('\DOMDocument', $res);
}
public function testGenerateSVGOutput()
{
$this->converter->loadImage(__DIR__.'/test-vertical.png');
$res = $this->converter->generateSVG();
$this->assertContains('<svg xmlns="http://www.w3.org/2000/svg" shape-rendering="crispEdges">', $res);
}
public function testSaveSvg()
{
$this->converter->loadImage(__DIR__.'/red-nose.gif');
$res = $this->converter->saveSVG(__DIR__.'/res.svg');
$this->assertInternalType('int', $res);
}
}
BIN +119 Bytes test/red-nose.gif
Binary file not shown.

This file was deleted.

0 comments on commit 7230a4d

Please sign in to comment.
You can’t perform that action at this time.