forked from leafo/scssphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputTest.php
More file actions
98 lines (78 loc) · 2.41 KB
/
InputTest.php
File metadata and controls
98 lines (78 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace Leafo\ScssPhp\Tests;
use Leafo\ScssPhp\Compiler;
// Runs all the tests in inputs/ and compares their output to ouputs/
function _dump($value)
{
fwrite(STDOUT, print_r($value, true));
}
function _quote($str)
{
return preg_quote($str, '/');
}
class InputTest extends \PHPUnit_Framework_TestCase
{
protected static $inputDir = 'inputs';
protected static $outputDir = 'outputs';
public function setUp()
{
$this->scss = new Compiler();
$this->scss->addImportPath(__DIR__ . '/' . self::$inputDir);
}
/**
* @dataProvider fileNameProvider
*/
public function testInputFile($inFname, $outFname)
{
if (getenv('BUILD')) {
return $this->buildInput($inFname, $outFname);
}
if (!is_readable($outFname)) {
$this->fail("$outFname is missing, consider building tests with BUILD=true");
}
$input = file_get_contents($inFname);
$output = file_get_contents($outFname);
$this->assertEquals($output, $this->scss->compile($input));
}
public function fileNameProvider()
{
return array_map(
function ($a) {
return array($a, InputTest::outputNameFor($a));
},
self::findInputNames()
);
}
// only run when env is set
public function buildInput($inFname, $outFname)
{
$css = $this->scss->compile(file_get_contents($inFname));
file_put_contents($outFname, $css);
}
public static function findInputNames($pattern = '*')
{
$files = glob(__DIR__ . '/' . self::$inputDir . '/' . $pattern);
$files = array_filter($files, 'is_file');
if ($pattern = getenv('MATCH')) {
$files = array_filter($files, function ($fname) use ($pattern) {
return preg_match("/$pattern/", $fname);
});
}
return $files;
}
public static function outputNameFor($input)
{
$front = _quote(__DIR__ . '/');
$out = preg_replace("/^$front/", '', $input);
$in = _quote(self::$inputDir . '/');
$out = preg_replace("/$in/", self::$outputDir . '/', $out);
$out = preg_replace("/.scss$/", '.css', $out);
return __DIR__ . '/' . $out;
}
public static function buildTests($pattern)
{
$files = self::findInputNames($pattern);
foreach ($files as $file) {
}
}
}