8000 refactor file container and add more tests · learn-symfony/css-compiler@1e008b5 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

8000
Appearance settings

Commit 1e008b5

Browse files
refactor file container and add more tests
1 parent d08b3bd commit 1e008b5

File tree

4 files changed

+144
-115
lines changed

4 files changed

+144
-115
lines changed

src/Container/File.php renamed to src/Container/FileContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use EM\CssCompiler\Exception\FileException;
66

7-
class File
7+
class FileContainer
88
{
99
const TYPE_UNKNOWN = 'unknown';
1010
const TYPE_COMPASS = 'compass';

src/Processor/Processor.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace EM\CssCompiler\Processor;
44

55
use Composer\IO\IOInterface;
6-
use EM\CssCompiler\Container\File;
6+
use EM\CssCompiler\Container\FileContainer;
77
use EM\CssCompiler\Exception\CompilerException;
88
use Leafo\ScssPhp\Compiler as SASSCompiler;
99
use lessc as LESSCompiler;
@@ -28,7 +28,7 @@ class Processor
2828
*/
2929
private $io;
3030
/**
31-
* @var File[]
31+
* @var FileContainer[]
3232
*/
3333
private $files = [];
3434
/**
@@ -70,14 +70,14 @@ public function attachFiles($inputPath, $outputPath)
7070
$this->attachFiles("$inputPath/$file", $outputPath);
7171
}
7272
} else if (is_file($inputPath)) {
73-
$this->files[] = new File($inputPath, $outputPath);
73+
$this->files[] = new FileContainer($inputPath, $outputPath);
7474
} else {
7575
throw new \Exception("file doesn't exists");
7676
}
7777
}
7878

7979
/**
80-
* @return File[]
80+
* @return FileContainer[]
8181
*/
8282
public function getFiles()
8383
{
@@ -146,14 +146,14 @@ public function processFiles($formatter)
146146
* @return File
147147
* @throws CompilerException
148148
*/
149-
public function processFile(File $file)
149+
public function processFile(FileContainer $file)
150150
{
151151
switch ($file->getType()) {
152-
case File::TYPE_COMPASS:
153-
case File::TYPE_SCSS:
154-
case File::TYPE_SASS:
152+
case FileContainer::TYPE_COMPASS:
153+
case FileContainer::TYPE_SCSS:
154+
case FileContainer::TYPE_SASS:
155155
return $file->setParsedContent($this->sass->compile($file->getSourceContent()));
156-
case File::TYPE_LESS:
156+
case FileContainer::TYPE_LESS:
157157
return $file->setParsedContent($this->less->compile($file->getSourceContent()));
158158
}
159159

tests/phpunit/ProcessorTest.php

Lines changed: 0 additions & 105 deletions
This file was deleted.

tests/phpunit/ScriptHandlerTest.php

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
3+
namespace EM\Tests\PHPUnit;
4+
5+
use EM\CssCompiler\ScriptHandler;
6+
use EM\Tests\Environment\IntegrationTestSuite;
7+
8+
/**
9+
* @see ScriptHandler
10+
*/
11+
class ScriptHandlerTest extends IntegrationTestSuite
12+
{
13+
/*** *************************** CONFIGURATION VALIDATION *************************** ***/
14+
/**
15+
* @see ScriptHandler::validateConfiguration
16+
* @test
17+
*
18+
* @expectedException \InvalidArgumentException
19+
*/
20+
function validateConfigurationExpectedExceptionOnNotExistingKey()
21+
{
22+
$this->invokeMethod(new ScriptHandler(), 'validateConfiguration', [[]]);
23+
}
24+
25+
/**
26+
* @see ScriptHandler::validateConfiguration
27+
* @test
28+
*
29+
* @expectedException \InvalidArgumentException
30+
*/
31+
function validateConfigurationExpectedExceptionOnNotArray()
32+
{
33+
$this->invokeMethod(new ScriptHandler(), 'validateConfiguration', [[ScriptHandler::CONFIG_MAIN_KEY]]);
34+
}
35+
36+
/**
37+
* @see ScriptHandler::validateConfiguration
38+
* @test
39+
*
40+
* @expectedException \InvalidArgumentException
41+
*/
42+
function validateConfigurationExpectedExceptionOptionIsNotArray()
43+
{
44+
$arr = [
45+
ScriptHandler::CONFIG_MAIN_KEY => [
46+
'string'
47+
]
48+
];
49+
$this->invokeMethod(new ScriptHandler(), 'validateConfiguration', [$arr]);
50+
}
51+
52+
/**
53+
* @see ScriptHandler::validateConfiguration
54+
* @test
55+
*/
56+
function validateConfigurationOnValid()
57+
{
58+
$arr = [
59+
ScriptHandler::CONFIG_MAIN_KEY => [
60+
[
61+
ScriptHandler::OPTION_KEY_INPUT => ['string'],
62+
ScriptHandler::OPTION_KEY_OUTPUT => 'string'
63+
]
64+
]
65+
];
66+
$result = $this->invokeMethod(new ScriptHandler(), 'validateConfiguration', [$arr]);
67+
$this->assertTrue($result);
68+
}
69+
70+
/*** *************************** OPTIONS VALIDATION *************************** ***/
71+
/**
72+
* @see ScriptHandler::validateOptions
73+
* @test
74+
*
75+
* @expectedException \InvalidArgumentException
76+
*/
77+
function validateOptionsExpectedExceptionOnMissingInput()
78+
{
79+
$this->invokeMethod(new ScriptHandler(), 'validateOptions', [[ScriptHandler::OPTION_KEY_OUTPUT]]);
80+
}
81+
82+
/**
83+
* @see ScriptHandler::validateOptions
84+
* @test
85+
*
86+
* @expectedException \InvalidArgumentException
87+
*/
88+
function validateOptionsExpectedExceptionOnMissingOutput()
89+
{
90+
$this->invokeMethod(new ScriptHandler(), 'validateOptions', [[ScriptHandler::OPTION_KEY_INPUT]]);
91+
}
92+
93+
/**
94+
* @see ScriptHandler::validateOptions
95+
* @test
96+
*
97+
* @expectedException \InvalidArgumentException
98+
*/
99+
function validateOptionsExpectedExceptionOnInputNotArray()
100+
{
101+
$this->invokeMethod(new ScriptHandler(), 'validateOptions', [[
102+
ScriptHandler::OPTION_KEY_INPUT => 'string',
103+
ScriptHandler::OPTION_KEY_OUTPUT => 'string'
104+
]]);
105+
}
106+
107+
/**
108+
* @see ScriptHandler::validateOptions
109+
* @test
110+
*
111+
* @expectedException \InvalidArgumentException
112+
*/
113+
function validateOptionsExpectedExceptionOnOutputNotString()
114+
{
115+
$this->invokeMethod(new ScriptHandler(), 'validateOptions', [[
116+
ScriptHandler::OPTION_KEY_INPUT => ['string'],
117+
ScriptHandler::OPTION_KEY_OUTPUT => ['string']
118+
]]);
119+
}
120+
121+
/**
122+
* @see ScriptHandler::validateOptions
123+
* @test
124+
*/
125+
function validateOptionsOnValid()
126+
{
127+
$result = $this->invokeMethod(new ScriptHandler(), 'validateOptions', [[
128+
ScriptHandler::OPTION_KEY_INPUT => ['string'],
129+
ScriptHandler::OPTION_KEY_OUTPUT => 'string'
130+
]]);
131+
132+
$this->assertTrue($result);
133+
}
134+
}

0 commit comments

Comments
 (0)
0