Permalink
Browse files

Merge pull request #22 from tedivm/testing

Refactoring the Test Suite
  • Loading branch information...
2 parents 86cd69c + ac6d652 commit 4b48e3d051cf0ab145db9df20d3292d91485bb60 @tedivm committed Jan 14, 2014
Showing with 121 additions and 85 deletions.
  1. +9 −3 .travis.yml
  2. +15 −0 phpunit.xml.dist
  3. +0 −82 tests/JShrink.php
  4. +69 −0 tests/JShrink/Test/JShrinkTest.php
  5. 0 tests/{minify → Resources}/jshrink/expect/preserve-strings.js
  6. 0 tests/{minify → Resources}/jshrink/test/preserve-strings.js
  7. 0 tests/{minify → Resources}/requests/expect/ifreturn.js
  8. 0 tests/{minify → Resources}/requests/expect/whitespace.js
  9. 0 tests/{minify → Resources}/requests/test/ifreturn.js
  10. 0 tests/{minify → Resources}/requests/test/whitespace.js
  11. 0 tests/{minify → Resources}/uglify/README
  12. 0 tests/{minify → Resources}/uglify/expect/array1.js
  13. 0 tests/{minify → Resources}/uglify/expect/array2.js
  14. 0 tests/{minify → Resources}/uglify/expect/array3.js
  15. 0 tests/{minify → Resources}/uglify/expect/array4.js
  16. 0 tests/{minify → Resources}/uglify/expect/assignment.js
  17. 0 tests/{minify → Resources}/uglify/expect/concatstring.js
  18. 0 tests/{minify → Resources}/uglify/expect/empty-blocks.js
  19. 0 tests/{minify → Resources}/uglify/expect/forstatement.js
  20. 0 tests/{minify → Resources}/uglify/expect/if.js
  21. 0 tests/{minify → Resources}/uglify/expect/ifreturn2.js
  22. 0 tests/{minify → Resources}/uglify/expect/null_string.js
  23. 0 tests/{minify → Resources}/uglify/expect/strict-equals.js
  24. 0 tests/{minify → Resources}/uglify/expect/var.js
  25. 0 tests/{minify → Resources}/uglify/expect/with.js
  26. 0 tests/{minify → Resources}/uglify/test/array1.js
  27. 0 tests/{minify → Resources}/uglify/test/array2.js
  28. 0 tests/{minify → Resources}/uglify/test/array3.js
  29. 0 tests/{minify → Resources}/uglify/test/array4.js
  30. 0 tests/{minify → Resources}/uglify/test/assignment.js
  31. 0 tests/{minify → Resources}/uglify/test/concatstring.js
  32. 0 tests/{minify → Resources}/uglify/test/empty-blocks.js
  33. 0 tests/{minify → Resources}/uglify/test/forstatement.js
  34. 0 tests/{minify → Resources}/uglify/test/if.js
  35. 0 tests/{minify → Resources}/uglify/test/ifreturn2.js
  36. 0 tests/{minify → Resources}/uglify/test/null_string.js
  37. 0 tests/{minify → Resources}/uglify/test/strict-equals.js
  38. 0 tests/{minify → Resources}/uglify/test/var.js
  39. 0 tests/{minify → Resources}/uglify/test/with.js
  40. +28 −0 tests/bootstrap.php
View
@@ -1,5 +1,11 @@
language: php
+
php:
- - 5.3
- - 5.4
-script: phpunit tests/*
+ - 5.3
+ - 5.4
+ - 5.5
+ - hhvm
+
+before_script: composer install --dev
+
+script: phpunit --verbose --coverage-text
View
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit bootstrap="./tests/bootstrap.php" colors="true">
+ <testsuites>
+ <testsuite name="JShrink Test Suite">
+ <directory suffix="Test.php">./tests/JShrink/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory suffix=".php">./src/JShrink/</directory>
+ </whitelist>
+ </filter>
+</phpunit>
View
@@ -1,82 +0,0 @@
-<?php
-
-class JSIterator implements Iterator {
- private $data = array();
- private $key = 0;
- private $test_files = array();
-
- public function __construct($directory, $expectFiles = TRUE) {
- $root_dir = realpath('tests/'.$directory);
- $test_dir = $root_dir.'/test/';
- if($expectFiles) {
- $expect_dir = $root_dir.'/expect/';
- }
-
- $test_contents = scandir($test_dir);
- foreach($test_contents as $possible_file) {
- $test_file = $test_dir.$possible_file;
- if($expectFiles) {
- $expect_file = $expect_dir.$possible_file;
- if(is_file($test_file) && is_file($expect_file)) {
- $this->test_files[] = array($test_file, $expect_file);
- }
- } else {
- if(is_file($test_file)) {
- $this->test_files[] = array($test_file);
- }
- }
- }
- }
-
- public function current() {
- $ret = array();
- foreach($this->test_files[$this->key] as $file) {
- $ret[] = file_get_contents($file);
- }
- return $ret;
- }
-
- public function key() {
- return $this->key;
- }
-
- public function rewind() {
- reset($this->test_files);
- $this->data = array();
- $this->key = 0;
- }
-
- public function valid() {
- return $this->key < count($this->test_files);
- }
-
- public function next() {
- ++$this->key;
- }
-}
-
-class JShrinkTest extends PHPUnit_Framework_TestCase {
- /**
- * @dataProvider JShrinkProvider
- */
- public function testJShrink($unminified, $minified) {
- require_once('src/JShrink/Minifier.php');
- $this->assertEquals(JShrink\Minifier::minify($unminified), $minified);
- }
-
- public function JShrinkProvider() {
- return new JSIterator('minify/jshrink');
- }
-
- /**
- * @dataProvider uglifyProvider
- */
- public function testUglify($unminified, $minified) {
- require_once('src/JShrink/Minifier.php');
- $this->assertEquals(JShrink\Minifier::minify($unminified), $minified);
- }
-
- public function uglifyProvider() {
- return new JSIterator('minify/uglify');
- }
-}
@@ -0,0 +1,69 @@
+<?php
+
+/*
+ * This file is part of the JShrink package.
+ *
+ * (c) Robert Hafner <tedivm@tedivm.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace JShrink\Test;
+
+use JShrink\Minifier;
+
+
+class JShrinkTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @dataProvider JShrinkProvider
+ */
+ public function testJShrink($testName, $unminified, $minified) {
+ $this->assertEquals(\JShrink\Minifier::minify($unminified), $minified, 'Running JShrink Test: ' . $testName);
+ }
+
+ /**
+ * @dataProvider uglifyProvider
+ */
+ public function testUglify($testName, $unminified, $minified) {
+ $this->assertEquals(\JShrink\Minifier::minify($unminified), $minified, 'Running Uglify Test: ' . $testName);
+ }
+
+
+ public function getExampleFiles($group)
+ {
+ $baseDir = __DIR__ . '/../../Resources/' . $group . '/';
+ $testDir = $baseDir . 'test/';
+ $expectDir = $baseDir . 'expect/';
+
+ $returnData = array();
+
+
+ $testFiles = scandir($testDir);
+ foreach($testFiles as $testFile)
+ {
+ if(!file_exists(($expectDir . $testFile)))
+ continue;
+
+ $testContents = file_get_contents($testDir . $testFile);
+ $testResults = file_get_contents($expectDir . $testFile);
+
+ $returnData[] = array($testFile, $testContents, $testResults);
+ }
+
+ return $returnData;
+ }
+
+
+ public function uglifyProvider() {
+ return $this->getExampleFiles('uglify');
+ }
+
+ public function JShrinkProvider() {
+ return $this->getExampleFiles('jshrink');
+ }
+
+
+
+}
File renamed without changes.
View
@@ -0,0 +1,28 @@
+<?php
+
+/*
+ * This file is part of the JShrink package.
+ *
+ * (c) Robert Hafner <tedivm@tedivm.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+define('TESTING', true);//
+error_reporting(-1);
+
+date_default_timezone_set('UTC');
+
+$filename = __DIR__ .'/../vendor/autoload.php';
+
+if (!file_exists($filename)) {
+ echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" . PHP_EOL;
+ echo " You need to execute `composer install` before running the tests. " . PHP_EOL;
+ echo " Vendors are required for complete test execution. " . PHP_EOL;
+ echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" . PHP_EOL . PHP_EOL;
+ $filename = __DIR__ .'/../autoload.php';
+}
+
+$loader = require $filename;
+$loader->add('JShrink\\Test', __DIR__);

0 comments on commit 4b48e3d

Please sign in to comment.