Skip to content

Commit 4b48e3d

Browse files
committed
Merge pull request #22 from tedivm/testing
Refactoring the Test Suite
2 parents 86cd69c + ac6d652 commit 4b48e3d

40 files changed

+121
-85
lines changed

.travis.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
language: php
2+
23
php:
3-
- 5.3
4-
- 5.4
5-
script: phpunit tests/*
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
- hhvm
8+
9+
before_script: composer install --dev
10+
11+
script: phpunit --verbose --coverage-text

phpunit.xml.dist

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit bootstrap="./tests/bootstrap.php" colors="true">
4+
<testsuites>
5+
<testsuite name="JShrink Test Suite">
6+
<directory suffix="Test.php">./tests/JShrink/</directory>
7+
</testsuite>
8+
</testsuites>
9+
10+
<filter>
11+
<whitelist>
12+
<directory suffix=".php">./src/JShrink/</directory>
13+
</whitelist>
14+
</filter>
15+
</phpunit>

tests/JShrink.php

-82
This file was deleted.

tests/JShrink/Test/JShrinkTest.php

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the JShrink package.
5+
*
6+
* (c) Robert Hafner <tedivm@tedivm.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace JShrink\Test;
13+
14+
use JShrink\Minifier;
15+
16+
17+
class JShrinkTest extends \PHPUnit_Framework_TestCase
18+
{
19+
/**
20+
* @dataProvider JShrinkProvider
21+
*/
22+
public function testJShrink($testName, $unminified, $minified) {
23+
$this->assertEquals(\JShrink\Minifier::minify($unminified), $minified, 'Running JShrink Test: ' . $testName);
24+
}
25+
26+
/**
27+
* @dataProvider uglifyProvider
28+
*/
29+
public function testUglify($testName, $unminified, $minified) {
30+
$this->assertEquals(\JShrink\Minifier::minify($unminified), $minified, 'Running Uglify Test: ' . $testName);
31+
}
32+
33+
34+
public function getExampleFiles($group)
35+
{
36+
$baseDir = __DIR__ . '/../../Resources/' . $group . '/';
37+
$testDir = $baseDir . 'test/';
38+
$expectDir = $baseDir . 'expect/';
39+
40+
$returnData = array();
41+
42+
43+
$testFiles = scandir($testDir);
44+
foreach($testFiles as $testFile)
45+
{
46+
if(!file_exists(($expectDir . $testFile)))
47+
continue;
48+
49+
$testContents = file_get_contents($testDir . $testFile);
50+
$testResults = file_get_contents($expectDir . $testFile);
51+
52+
$returnData[] = array($testFile, $testContents, $testResults);
53+
}
54+
55+
return $returnData;
56+
}
57+
58+
59+
public function uglifyProvider() {
60+
return $this->getExampleFiles('uglify');
61+
}
62+
63+
public function JShrinkProvider() {
64+
return $this->getExampleFiles('jshrink');
65+
}
66+
67+
68+
69+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/bootstrap.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the JShrink package.
5+
*
6+
* (c) Robert Hafner <tedivm@tedivm.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
define('TESTING', true);//
13+
error_reporting(-1);
14+
15+
date_default_timezone_set('UTC');
16+
17+
$filename = __DIR__ .'/../vendor/autoload.php';
18+
19+
if (!file_exists($filename)) {
20+
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" . PHP_EOL;
21+
echo " You need to execute `composer install` before running the tests. " . PHP_EOL;
22+
echo " Vendors are required for complete test execution. " . PHP_EOL;
23+
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" . PHP_EOL . PHP_EOL;
24+
$filename = __DIR__ .'/../autoload.php';
25+
}
26+
27+
$loader = require $filename;
28+
$loader->add('JShrink\\Test', __DIR__);

0 commit comments

Comments
 (0)