Skip to content
This repository has been archived by the owner on Sep 28, 2018. It is now read-only.

Commit

Permalink
Tests are now done functionaly instead of invoking robo again.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Jones committed Mar 15, 2017
1 parent 57c418d commit 67ae9fa
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 165 deletions.
103 changes: 0 additions & 103 deletions robo
Original file line number Diff line number Diff line change
Expand Up @@ -33,109 +33,6 @@ class RoboFile extends \Robo\Tasks
->run()->getExitCode()
);
}

/*
* The following tasks are about testing the functionality of Gears\Asset.
* Some of the compiled assets that these create will not actually work
* inside a browser.
*/

public function testSingleJsAsset()
{
$this->taskBuildAsset('./tests/output/single.js')
->source('./vendor/bower/jquery/dist/jquery.js')
->run();
}

public function testFolderJsAsset()
{
$this->taskBuildAsset('./tests/output/folder.js')
->source('./vendor/bower/bootstrap/js')
->run();
}

public function testSingleCssAsset()
{
$this->taskBuildAsset('./tests/output/single.css')
->source('./vendor/bower/bootstrap/dist/css/bootstrap.css')
->run();
}

public function testFolderCssAsset()
{
$this->taskBuildAsset('./tests/output/folder.css')
->source('./vendor/bower/pure')
->run();
}

public function testLessAsset()
{
$this->taskBuildAsset('./tests/output/less.css')
->source('./vendor/bower/bootstrap/less/bootstrap.less')
->run();
}

public function testScssAsset()
{
$this->taskBuildAsset('./tests/output/scss.css')
->source('./vendor/bower/bootstrap-sass/assets/stylesheets/_bootstrap.scss')
->run();
}

public function testManyAssets()
{
$this->taskBuildAsset('./tests/output/many.css')
->source
([
'./vendor/bower/pure',
'./vendor/bower/bootstrap/less/bootstrap.less',
'./vendor/bower/bootstrap-sass/assets/stylesheets/_bootstrap.scss'
])
->run();
}

public function testFinderAsset()
{
$finder = new Symfony\Component\Finder\Finder();
$finder->files()->in('./vendor/bower/pure')->name('*.css')->sortByName();
$this->taskBuildAsset('./tests/output/finder.css')->source($finder)->run();
}

public function testTemplate()
{
$this->taskWriteToFile('./tests/output/template.html')
->line('<script src="./template.js"></script>')
->run();

$this->taskBuildAsset('./tests/output/template.js')
->source('./vendor/bower/jquery/dist/jquery.js')
->template('./tests/output/template.html')
->run();
}

public function testGz()
{
$this->taskBuildAsset('./tests/output/gzipped.js')
->source('./vendor/bower/jquery/dist/jquery.js')
->gz(true)
->run();
}

public function testDebug()
{
$this->taskBuildAsset('./tests/output/debug.js')
->source('./vendor/bower/jquery/dist/jquery.js')
->debug(true)
->run();
}

public function testCssPathReplacement()
{
$this->taskBuildAsset('./tests/output/css-path-replacement.css')
->source('./tests/input/css-path-replacement.css')
->debug(true)
->run();
}
}

exit(\Robo\Robo::run($_SERVER['argv'], RoboFile::class));
139 changes: 77 additions & 62 deletions tests/AssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,43 @@

namespace Gears\Tests;

use Robo;
use Gears\Asset;
use League\Container;
use Symfony\Component\Console;
use PHPUnit\Framework\TestCase;

class AssetTest extends TestCase
class AssetTest extends TestCase implements Container\ContainerAwareInterface
{
public function testSingleJsAsset()
use Asset\loadTasks;
use Robo\TaskAccessor;
use Robo\Task\File\loadTasks;
use Container\ContainerAwareTrait;

public function setUp()
{
$results = $this->callRoboTask('test:single-js-asset');
$this->setContainer
(
Robo\Robo::createDefaultContainer
(
null, new Console\Output\NullOutput
)
);
}

$this->assertEmpty($results['stderr']);
public function collectionBuilder()
{
$tasks = new \Robo\Tasks();
$builder = $this->getContainer()->get('collectionBuilder', [$tasks]);
$tasks->setBuilder($builder);
return $builder;
}

public function testSingleJsAsset()
{
$this->taskBuildAsset('./tests/output/single.js')
->source('./vendor/bower/jquery/dist/jquery.js')
->run();

$this->assertFileExists('./tests/output/single.js');

Expand All @@ -34,9 +62,9 @@ public function testSingleJsAsset()

public function testFolderJsAsset()
{
$results = $this->callRoboTask('test:folder-js-asset');

$this->assertEmpty($results['stderr']);
$this->taskBuildAsset('./tests/output/folder.js')
->source('./vendor/bower/bootstrap/js')
->run();

$this->assertFileExists('./tests/output/folder.js');

Expand All @@ -49,9 +77,9 @@ public function testFolderJsAsset()

public function testSingleCssAsset()
{
$results = $this->callRoboTask('test:single-css-asset');

$this->assertEmpty($results['stderr']);
$this->taskBuildAsset('./tests/output/single.css')
->source('./vendor/bower/bootstrap/dist/css/bootstrap.css')
->run();

$this->assertFileExists('./tests/output/single.css');

Expand All @@ -64,9 +92,9 @@ public function testSingleCssAsset()

public function testFolderCssAsset()
{
$results = $this->callRoboTask('test:folder-css-asset');

$this->assertEmpty($results['stderr']);
$this->taskBuildAsset('./tests/output/folder.css')
->source('./vendor/bower/pure')
->run();

$this->assertFileExists('./tests/output/folder.css');

Expand All @@ -79,9 +107,9 @@ public function testFolderCssAsset()

public function testLessAsset()
{
$results = $this->callRoboTask('test:less-asset');

$this->assertEmpty($results['stderr']);
$this->taskBuildAsset('./tests/output/less.css')
->source('./vendor/bower/bootstrap/less/bootstrap.less')
->run();

$this->assertFileExists('./tests/output/less.css');

Expand All @@ -94,9 +122,9 @@ public function testLessAsset()

public function testScssAsset()
{
$results = $this->callRoboTask('test:scss-asset');

$this->assertEmpty($results['stderr']);
$this->taskBuildAsset('./tests/output/scss.css')
->source('./vendor/bower/bootstrap-sass/assets/stylesheets/_bootstrap.scss')
->run();

$this->assertFileExists('./tests/output/scss.css');

Expand All @@ -109,9 +137,14 @@ public function testScssAsset()

public function testManyAssets()
{
$results = $this->callRoboTask('test:many-assets');

$this->assertEmpty($results['stderr']);
$this->taskBuildAsset('./tests/output/many.css')
->source
([
'./vendor/bower/pure',
'./vendor/bower/bootstrap/less/bootstrap.less',
'./vendor/bower/bootstrap-sass/assets/stylesheets/_bootstrap.scss'
])
->run();

$this->assertFileExists('./tests/output/many.css');

Expand All @@ -124,9 +157,9 @@ public function testManyAssets()

public function testFinderAsset()
{
$results = $this->callRoboTask('test:finder-asset');

$this->assertEmpty($results['stderr']);
$finder = new \Symfony\Component\Finder\Finder();
$finder->files()->in('./vendor/bower/pure')->name('*.css')->sortByName();
$this->taskBuildAsset('./tests/output/finder.css')->source($finder)->run();

$this->assertFileExists('./tests/output/finder.css');

Expand All @@ -139,9 +172,14 @@ public function testFinderAsset()

public function testTemplate()
{
$results = $this->callRoboTask('test:template');
$this->taskWriteToFile('./tests/output/template.html')
->line('<script src="./template.js"></script>')
->run();

$this->assertEmpty($results['stderr']);
$this->taskBuildAsset('./tests/output/template.js')
->source('./vendor/bower/jquery/dist/jquery.js')
->template('./tests/output/template.html')
->run();

$this->assertFileExists('./tests/output/template.html');

Expand All @@ -159,9 +197,10 @@ public function testTemplate()

public function testGz()
{
$results = $this->callRoboTask('test:gz');

$this->assertEmpty($results['stderr']);
$this->taskBuildAsset('./tests/output/gzipped.js')
->source('./vendor/bower/jquery/dist/jquery.js')
->gz(true)
->run();

$this->assertFileExists('./tests/output/gzipped.js');
$this->assertFileExists('./tests/output/gzipped.js.gz');
Expand All @@ -175,9 +214,10 @@ public function testGz()

public function testDebug()
{
$results = $this->callRoboTask('test:debug');

$this->assertEmpty($results['stderr']);
$this->taskBuildAsset('./tests/output/debug.js')
->source('./vendor/bower/jquery/dist/jquery.js')
->debug(true)
->run();

$this->assertFileExists('./tests/output/debug.js');

Expand All @@ -190,9 +230,10 @@ public function testDebug()

public function testCssPathReplacement()
{
$results = $this->callRoboTask('test:css-path-replacement');

$this->assertEmpty($results['stderr']);
$this->taskBuildAsset('./tests/output/css-path-replacement.css')
->source('./tests/input/css-path-replacement.css')
->debug(true)
->run();

$this->assertFileExists('./tests/output/css-path-replacement.css');

Expand All @@ -202,30 +243,4 @@ public function testCssPathReplacement()
'./tests/output/css-path-replacement.css'
);
}

private function callRoboTask($task)
{
$cmd = './robo '.$task;
$descriptorspec = [1 => ["pipe", "w"], 2 => ["pipe", "w"]];
$process = proc_open($cmd, $descriptorspec, $pipes);

if (is_resource($process))
{
$output = [];

$output['stdout'] = stream_get_contents($pipes[2]);
fclose($pipes[2]);

$output['stderr'] = stream_get_contents($pipes[1]);
fclose($pipes[1]);

proc_close($process);

return $output;
}
else
{
throw new \Exception('Failed to start process.');
}
}
}

0 comments on commit 67ae9fa

Please sign in to comment.