Skip to content

Commit

Permalink
Added Util::readConfigFile() method to enable easier configration s…
Browse files Browse the repository at this point in the history
…haring between different workflows; e.g. command-line and server.
  • Loading branch information
peteboere committed Jun 11, 2014
1 parent c14837f commit 6bea9c1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/CssCrush/Util.php
Expand Up @@ -222,6 +222,12 @@ public static function parseIni($path, $sections = false)
return $result;
}

public static function readConfigFile($path)
{
require_once $path;
return Options::filter(get_defined_vars());
}

/*
* Encode integer to Base64 VLQ.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/functions.php
Expand Up @@ -90,7 +90,7 @@ function csscrush_string($string, $options = array()) {

Crush::$process = new CssCrush\Process($options, array('type' => 'filter', 'data' => $string));

return Crush::$process->compile()->__toString();
return Crush::$process->compile();
}


Expand Down
4 changes: 2 additions & 2 deletions tests/unit/CssCrush/OptionsTest.php
Expand Up @@ -42,8 +42,8 @@ public function testBoilerplate()
'newlines' => 'unix',
));

$this->assertContains(' * ' . csscrush_version(), $result);
$this->assertContains(" * Line breaks\n * preserved\n *", $result);
$this->assertContains(' * ' . csscrush_version(), (string) $result);
$this->assertContains(" * Line breaks\n * preserved\n *", (string) $result);
}

public function testFormatters()
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/CssCrush/UtilTest.php
Expand Up @@ -89,4 +89,20 @@ public function testFilePutContents()
$test_file = sys_get_temp_dir() . '/' . str_replace('\\', '_', __CLASS__);
$this->assertTrue(Util::filePutContents($test_file, 'Hello Mum'));
}

public function testReadConfigFile()
{
$contents = <<<'NOW_DOC'
<?php
$enable = array('svg', 'px2em');
$boilerplate = true;
$unrecognised_option = true;
NOW_DOC;

$options = Util::readConfigFile(temp_file($contents));
$this->assertArrayHasKey('enable', $options);
$this->assertArrayNotHasKey('unrecognised_option', $options);
}
}

0 comments on commit 6bea9c1

Please sign in to comment.