-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathInputTest.php
More file actions
112 lines (92 loc) · 2.66 KB
/
InputTest.php
File metadata and controls
112 lines (92 loc) · 2.66 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* SCSSPHP
*
* @copyright 2012-2020 Leaf Corcoran
*
* @license http://opensource.org/licenses/MIT MIT
*
* @link http://scssphp.github.io/scssphp
*/
namespace ScssPhp\ScssPhp\Tests;
use PHPUnit\Framework\TestCase;
use ScssPhp\ScssPhp\Compiler;
use ScssPhp\ScssPhp\Logger\QuietLogger;
/**
* Input test - runs all the tests in inputs/ and compares their output to outputs/
*
* @author Leaf Corcoran <leafot@gmail.com>
*/
class InputTest extends TestCase
{
/**
* @var Compiler
*/
private $scss;
private static $inputDir = 'inputs';
private static $outputDir = 'outputs';
/**
* @dataProvider fileNameProvider
* @param string $inFname
* @param string $outFname
*/
public function testInputFile($inFname, $outFname)
{
chdir(__DIR__);
$this->scss = new Compiler();
$this->scss->addImportPath(self::$inputDir);
$this->scss->setLogger(new QuietLogger());
if (getenv('BUILD')) {
$this->buildInput($inFname, $outFname);
$this->assertNull(null);
return;
}
if (! is_readable($outFname)) {
$this->fail("$outFname is missing, consider building tests with \"make rebuild-outputs\".");
}
$output = file_get_contents($outFname);
$css = $this->scss->compileFile($inFname)->getCss();
$this->assertEquals(trim($output), trim($css));
}
public static function fileNameProvider()
{
return array_map(
function ($a) {
return [$a, InputTest::outputNameFor($a)];
},
self::findInputNames()
);
}
/**
* @param string $inFname
* @param string $outFname
*
* @return void
*/
private function buildInput($inFname, $outFname)
{
$css = $this->scss->compileFile($inFname)->getCss();
file_put_contents($outFname, $css . "\n");
}
private static function findInputNames()
{
$files = glob(__DIR__ . '/' . self::$inputDir . '/*');
$files = array_filter($files, 'is_file');
$filesKeys = array_map(
function ($a) {
return substr($a, strlen(__DIR__) + 1);
},
$files
);
return array_combine($filesKeys, $files);
}
public static function outputNameFor($input)
{
$front = preg_quote(__DIR__ . '/', '/');
$out = preg_replace("/^$front/", '', $input);
$in = preg_quote(self::$inputDir . '/', '/');
$out = preg_replace("/$in/", self::$outputDir . '/', $out);
$out = preg_replace('/.scss$/', '.css', $out);
return __DIR__ . '/' . $out;
}
}