Skip to content

Commit a3acb83

Browse files
first tests
1 parent bce869a commit a3acb83

File tree

5 files changed

+206
-9
lines changed

5 files changed

+206
-9
lines changed

.scrutinizer.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ build:
1111
environment:
1212
php:
1313
version: "7.0.4"
14-
# tests:
15-
# override:
16-
# -
17-
# command: "php bin/phpunit -c phpunit.xml --colors=always --verbose --coverage-clover=coverage.xml"
18-
# coverage:
19-
# file: "coverage.xml"
20-
# format: "php-clover"
14+
tests:
15+
override:
16+
-
17+
command: "composer validate"
18+
override:
19+
-
20+
command: "php bin/phpunit -c phpunit.xml --colors=always --verbose --coverage-clover=coverage.xml"
21+
coverage:
22+
file: "coverage.xml"
23+
format: "php-clover"

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
},
2020
"autoload-dev": {
2121
"psr-4": {
22-
"EM\\Tests\\CssCompiler\\": "tests/"
23-
}
22+
"EM\\Tests\\PHPUnit\\": "tests/phpunit"
23+
},
24+
"classmap": [
25+
"tests/shared-enviroment/IntegrationTestSuite.php"
26+
]
2427
},
2528
"require": {
2629
"php": ">= 5.6.0 || 7.0.0 - 7.0.4 || >= 7.0.6",

tests/phpunit/ProcessorTest.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
namespace EM\Tests\PHPUnit;
4+
5+
use Composer\IO\IOInterface;
6+
use EM\CssCompiler\Container\File;
7+
use EM\CssCompiler\Processor\Processor;
8+
use EM\Tests\Environment\IntegrationTestSuite;
9+
10+
/**
11+
* @see Processor
12+
*/
13+
class ProcessorTest extends IntegrationTestSuite
14+
{
15+
protected $event;
16+
protected $io;
17+
protected $package;
18+
19+
protected function setUp()
20+
{
21+
$this->io = $this->getMockBuilder(IOInterface::class)->getMock();
22+
}
23+
24+
/**
25+
* @see Processor::attachFiles
26+
* @test
27+
*/
28+
public function attachFiles()
29+
{
30+
$paths = [
31+
static::getSharedFixturesDirectory() . '/sass',
32+
static::getSharedFixturesDirectory() . '/compass'
33+
];
34+
$cacheDir = dirname(dirname(__DIR__)) . '/var/cache';
35+
36+
foreach ($paths as $path) {
37+
$processor = new Processor($this->io);
38+
$processor->attachFiles($path, $cacheDir);
39+
40+
$this->assertCount(2, $processor->getFiles());
41+
}
42+
}
43+
44+
/**
45+
* @see Processor::attachFiles
46+
* @test
47+
*
48+
* @expectedException \Exception
49+
*/
50+
public function attachFilesExpectedException()
51+
{
52+
$path = static::getSharedFixturesDirectory() . '/do-not-exists';
53+
$cacheDir = dirname(dirname(__DIR__)) . '/var/cache';
54+
55+
$processor = new Processor($this->io);
56+
$processor->attachFiles($path, $cacheDir);
57+
58+
$this->assertCount(2, $processor->getFiles());
59+
}
60+
61+
/**
62+
* @see Processor::processFile
63+
* @test
64+
*/
65+
public function processFileSASS()
66+
{
67+
$file = (new File(static::getSharedFixturesDirectory() . '/compass/sass/layout.scss', ''))
68+
->setSourceContentFromSourcePath();
69+
70+
(new Processor($this->io))->processFile($file);
71+
72+
$this->assertNotEquals($file->getParsedContent(), $file->getSourceContent());
73+
}
74+
75+
/**
76+
* @see Processor::processFile
77+
* @test
78+
*
79+
* @expectedException \EM\CssCompiler\Exception\CompilerException
80+
*/
81+
public function processFileExpectedException()
82+
{
83+
$file = (new File(static::getSharedFixturesDirectory() . '/compass/sass/', ''))
84+
->setSourceContentFromSourcePath()
85+
->setType(File::TYPE_UNKNOWN);
86+
87+
(new Processor($this->io))->processFile($file);
88+
}
89+
90+
/**
91+
* @see Processor::getFormatterClass
92+
* @test
93+
*/
94+
public function getFormatterClass()
95+
{
96+
foreach (Processor::SUPPORTED_FORMATTERS as $formatter) {
97+
$expected = 'Leafo\\ScssPhp\\Formatter\\' . ucfirst($formatter);
98+
99+
$this->assertEquals(
100+
$expected,
101+
$this->invokeMethod(new Processor($this->io), 'getFormatterClass', [$formatter])
102+
);
103+
}
104+
}
105+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace EM\Tests\Environment;
4+
5+
/**
6+
* @since 0.1
7+
*/
8+
abstract class IntegrationTestSuite extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* able to invoke any non-static of object and return the result and throws exceptions if so
12+
*
13+
* useful to used to invoke non-public method of the class
14+
*
15+
* @param mixed $object
16+
* @param string $methodName
17+
* @param array $methodArguments
18+
*
19+
* @return mixed
20+
* @throws \Exception
21+
*/
22+
protected function invokeMethod($object, string $methodName, array $methodArguments = [])
23+
{
24+
$method = (new \ReflectionClass(get_class($object)))->getMethod($methodName);
25+
$method->setAccessible(true);
26+
27+
return $method->invokeArgs($object, $methodArguments);
28+
}
29+
30+
public static function getRootDirectory() : string
31+
{
32+
return dirname(__DIR__);
33+
}
34+
35+
public static function getSharedFixturesDirectory() : string
36+
{
37+
return static::getRootDirectory() . '/shared-fixtures';
38+
}
39+
40+
/**
41+
* return content of the file in located in tests/shared-fixtures directory
42+
*
43+
* @param string $filename
44+
*
45+
* @return string
46+
*/
47+
public static function getSharedFixtureContent(string $filename) : string
48+
{
49+
return file_get_contents(static::getSharedFixturesDirectory() . "/$filename");
50+
}
51+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "eugene-matvejev/css-compiler",
3+
"description": "compiles SASS and LESS assets on composer's callback",
4+
"type": "lib",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Eugene Matvejev",
9+
"email": "eugene.matvejev@gmail.com"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"EM\\CssCompiler\\": "src/"
15+
},
16+
"classmap": [
17+
"ScriptHandler.php"
18+
]
19+
},
20+
"autoload-dev": {
21+
"psr-4": {
22+
"EM\\Tests\\CssCompiler\\": "tests/"
23+
}
24+
},
25+
"require": {
26+
"php": ">= 5.6",
27+
"leafo/lessphp": "^0.5",
28+
"leafo/scssphp": "@dev",
29+
"leafo/scssphp-compass": "@dev"
30+
},
31+
"require-dev": {
32+
"composer/composer": "^1.1",
33+
"phpunit/phpunit": "^5.3"
34+
}
35+
}

0 commit comments

Comments
 (0)