Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Use a dataprovider for tests. #322

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 34 additions & 49 deletions test/phpunit/FixturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@

class phpunit_FixturesTest extends phpunit_bootstrap{


/**
* Test the contents of the files in /test/Fixtures/lessjs/expected
*
*/
function testLessJs(){

echo "\nBegin Tests";

public function filelistProvider() {
$filelist = array();
$css_dir = $this->fixtures_dir.'/lessjs/expected';
$files = scandir($css_dir);

foreach($files as $file){
foreach($files as $file){
if( $file == '.' || $file == '..' ){
continue;
}
Expand All @@ -25,14 +18,26 @@ function testLessJs(){
if( is_dir($expected_file) ){
continue;
}

$this->CompareFile( $expected_file );
$filelist[$file] = array($expected_file);
}

echo "\n";
return $filelist;
}

/**
* Test the contents of the files in /test/Fixtures/lessjs/expected without any cache.
*
* @dataProvider filelistProvider
*/
function testLessJsWithoutCache($expected_file){
$less_file = $this->TranslateFile( $expected_file );
$expected_css = trim(file_get_contents($expected_file));

$parser = new Less_Parser();
$parser->parseFile($less_file);
$css = $parser->getCss();
$css = trim($css);
$this->assertEquals( $expected_css, $css );
}

/**
* Change a css file name to a less file name
Expand All @@ -52,49 +57,29 @@ function TranslateFile( $file_css, $dir = 'less', $type = 'less' ){
/**
* Compare the parser results with the expected css
*
* @dataProvider filelistProvider
*/
function CompareFile( $expected_file ){
function testLessJsWithCache($expected_file){

if (!$this->cache_dir) {
$this->MarkTestSkipped('No cache folder available');
}
$less_file = $this->TranslateFile( $expected_file );
$expected_css = trim(file_get_contents($expected_file));

$options = array('cache_dir'=>$this->cache_dir);
$files = array( $less_file => '' );

// Check with standard parser
echo "\n ".basename($expected_file);
echo "\n - Standard Compiler";

$parser = new Less_Parser();
$parser->parseFile($less_file);
$css = $parser->getCss();
$css_file_name = Less_Cache::Regen( $files, $options );
$css = file_get_contents($this->cache_dir.'/'.$css_file_name);
$css = trim($css);
$this->assertEquals( $expected_css, $css );


// Check with cache
if( $this->cache_dir ){

$options = array('cache_dir'=>$this->cache_dir);
$files = array( $less_file => '' );

echo "\n - Regenerating Cache";
$css_file_name = Less_Cache::Regen( $files, $options );
$css = file_get_contents($this->cache_dir.'/'.$css_file_name);
$css = trim($css);
$this->assertEquals( $expected_css, $css );



// Check using the cached data
echo "\n - Using Cache";
$css_file_name = Less_Cache::Get( $files, $options );
$css = file_get_contents($this->cache_dir.'/'.$css_file_name);
$css = trim($css);
$this->assertEquals( $expected_css, $css );

}

$this->assertEquals( $expected_css, $css, 'CSS must be equal when generating the cache and producing output');

$css_file_name = Less_Cache::Get( $files, $options );
$css = file_get_contents($this->cache_dir.'/'.$css_file_name);
$css = trim($css);
$this->assertEquals( $expected_css, $css, 'CSS must be equal when constructing it directly from cache');
}


}
}
4 changes: 1 addition & 3 deletions test/phpunit/FunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class phpunit_FunctionTest extends phpunit_bootstrap{
* Test
*/
public function testFunction() {
echo "\nBegin Tests";

$less_file = $this->fixtures_dir.'/functions/less/f1.less';
$expected_css = file_get_contents( $this->fixtures_dir.'/functions/css/f1.css' );

Expand All @@ -26,4 +24,4 @@ public static function reverse( $arg ) {
return $arg;
}
}
}
}
4 changes: 1 addition & 3 deletions test/phpunit/MapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ class phpunit_MapTest extends phpunit_bootstrap{
* Test
*/
public function testMap(){
echo "\nBegin Tests";

$less_file = $this->fixtures_dir.'/bootstrap3-sourcemap/less/bootstrap.less';
$map_file = $this->fixtures_dir.'/bootstrap3-sourcemap/expected/bootstrap.map';
$map_destination = $this->cache_dir.'/bootstrap.map';
Expand All @@ -31,4 +29,4 @@ public function testMap(){

}

}
}
14 changes: 3 additions & 11 deletions test/phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@ class phpunit_bootstrap extends PHPUnit_Framework_TestCase{
public $fixtures_dir;
public $cache_dir;

function setUp(){
echo "\nSet-Up: ".get_class($this);

public function __construct($name = NULL, array $data = array(), $dataName = '') {
$root_directory = dirname(dirname(dirname(__FILE__)));

require_once( $root_directory . '/lib/Less/Autoloader.php' );
Less_Autoloader::register();

$this->fixtures_dir = $root_directory.'/test/Fixtures';
echo "\n fixtures_dir: ".$this->fixtures_dir;

$this->cache_dir = $root_directory.'/test/phpunit/_cache/';
$this->CheckCacheDirectory();


echo "\n\n";
parent::__construct($name, $data, $dataName);
}

/**
Expand All @@ -31,16 +27,12 @@ function setUp(){
function CheckCacheDirectory(){

if( !file_exists($this->cache_dir) && !mkdir($this->cache_dir) ){
echo "\n cache_dir could not be created: ".$this->cache_dir;
return false;
}

if( !is_writable($this->cache_dir) ){
echo "\n cache_dir not writable: ".$this->cache_dir;
return false;
}

echo "\n cache_dir: ".$this->cache_dir;
}

}
}