8000 RC6 - first tests by eugene-matvejev · Pull Request #47 · learn-symfony/css-compiler · GitHub
[go: up one dir, main page]

Skip to content

RC6 - first tests #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions .scrutinizer.yml
10000
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ build:
environment:
php:
version: "7.0.4"
# tests:
# override:
# -
# command: "php bin/phpunit -c phpunit.xml --colors=always --verbose --coverage-clover=coverage.xml"
# coverage:
# file: "coverage.xml"
# format: "php-clover"
tests:
override:
-
command: "composer validate"
override:
-
command: "php bin/phpunit -c phpunit.xml --colors=always --verbose --coverage-clover=coverage.xml"
coverage:
file: "coverage.xml"
format: "php-clover"
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
},
"autoload-dev": {
"psr-4": {
"EM\\Tests\\CssCompiler\\": "tests/"
}
"EM\\Tests\\PHPUnit\\": "tests/phpunit"
},
"classmap": [
"tests/shared-enviroment/IntegrationTestSuite.php"
]
},
"config": {
"bin-dir": "bin/"
Expand Down
4 changes: 2 additions & 2 deletions src/Container/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class File
const TYPE_SASS = 'sass';
const TYPE_SCSS = 'scss';
const TYPE_LESS = 'less';
const SUPPORTED_TYPES = [
static $supportedTypes = [
self::TYPE_COMPASS,
self::TYPE_SASS,
self::TYPE_SCSS,
Expand Down Expand Up @@ -179,7 +179,7 @@ protected function detectSourceTypeFromPath($path)
{
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));

return in_array($extension, static::SUPPORTED_TYPES)
return in_array($extension, static::$supportedTypes)
? $extension
: static::TYPE_UNKNOWN;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Processor/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Processor
const FORMATTER_EXPANDED = 'expanded';
const FORMATTER_NESTED = 'nested';
const FORMATTER_COMPACT = 'compact';
const SUPPORTED_FORMATTERS = [
static $supportedFormatters = [
self::FORMATTER_COMPRESSED,
self::FORMATTER_CRUNCHED,
self::FORMATTER_EXPANDED,
Expand Down Expand Up @@ -167,8 +167,8 @@ public function processFile(File $file)
*/
protected function getFormatterClass($formatter)
{
if (!in_array($formatter, static::SUPPORTED_FORMATTERS)) {
throw new \InvalidArgumentException('unknown formatter, available options are: ' . print_r(static::SUPPORTED_FORMATTERS, true));
if (!in_array($formatter, static::$supportedFormatters)) {
throw new \InvalidArgumentException('unknown formatter, available options are: ' . print_r(static::$supportedFormatters, true));
}

return 'Leafo\\ScssPhp\\Formatter\\' . ucfirst($formatter);
Expand Down
105 changes: 105 additions & 0 deletions tests/phpunit/ProcessorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace EM\Tests\PHPUnit;

use Composer\IO\IOInterface;
use EM\CssCompiler\Container\File;
use EM\CssCompiler\Processor\Processor;
use EM\Tests\Environment\IntegrationTestSuite;

/**
* @see Processor
*/
class ProcessorTest extends IntegrationTestSuite
{
protected $event;
protected $io;
protected $package;

protected function setUp()
{
$this->io = $this->getMockBuilder(IOInterface::class)->getMock();
}

/**
* @see Processor::attachFiles
* @test
*/
public function attachFiles()
{
$paths = [
static::getSharedFixturesDirectory() . '/sass',
static::getSharedFixturesDirectory() . '/compass'
];
$cacheDir = dirname(dirname(__DIR__)) . '/var/cache';

foreach ($paths as $path) {
$processor = new Processor($this->io);
$processor->attachFiles($path, $cacheDir);

$this->assertCount(2, $processor->getFiles());
}
}

/**
* @see Processor::attachFiles
* @test
*
* @expectedException \Exception
*/
public function attachFilesExpectedException()
{
$path = static::getSharedFixturesDirectory() . '/do-not-exists';
$cacheDir = dirname(dirname(__DIR__)) . '/var/cache';

$processor = new Processor($this->io);
$processor->attachFiles($path, $cacheDir);

$this->assertCount(2, $processor->getFiles());
}

/**
* @see Processor::processFile
* @test
*/
public function processFileSASS()
{
$file = (new File(static::getSharedFixturesDirectory() . '/compass/sass/layout.scss', ''))
->setSourceContentFromSourcePath();

(new Processor($this->io))->processFile($file);

$this->assertNotEquals($file->getParsedContent(), $file->getSourceContent());
}

/**
* @see Processor::processFile
* @test
*
* @expectedException \EM\CssCompiler\Exception\CompilerException
*/
public function processFileExpectedException()
{
$file = (new File(static::getSharedFixturesDirectory() . '/compass/sass/', ''))
->setSourceContentFromSourcePath()
->setType(File::TYPE_UNKNOWN);

(new Processor($this->io))->processFile($file);
}

/**
* @see Processor::getFormatterClass
* @test
*/
public function getFormatterClass()
{
foreach (Processor::$supportedFormatters as $formatter) {
$expected = 'Leafo\\ScssPhp\\Formatter\\' . ucfirst($formatter);

$this->assertEquals(
$expected,
$this->invokeMethod(new Processor($this->io), 'getFormatterClass', [$formatter])
);
}
}
}
57 changes: 57 additions & 0 deletions tests/shared-enviroment/IntegrationTestSuite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace EM\Tests\Environment;

/**
* @since 0.1
*/
abstract class IntegrationTestSuite extends \PHPUnit_Framework_TestCase
{
/**
* able to invoke any non-static of object and return the result and throws exceptions if so
*
* useful to used to invoke non-public method of the class
*
* @param mixed $object
* @param string $methodName
* @param array $methodArguments
*
* @return mixed
* @throws \Exception
*/
protected function invokeMethod($object, $methodName, array $methodArguments = [])
{
$method = (new \ReflectionClass(get_class($object)))->getMethod($methodName);
$method->setAccessible(true);

return $method->invokeArgs($object, $methodArguments);
}

/**
* @return string
*/
public static function getRootDirectory()
{
return dirname(__DIR__);
}

/**
* @return string
*/
public static function getSharedFixturesDirectory()
{
return static::getRootDirectory() . '/shared-fixtures';
}

/**
* return content of the file in located in tests/shared-fixtures directory
*
* @param string $filename
*
* @return string
*/
public static function getSharedFixtureContent(string $filename)
{
return file_get_contents(static::getSharedFixturesDirectory() . "/$filename");
}
}
35 changes: 35 additions & 0 deletions tests/shared-fixtures/composer.phpunit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "eugene-matvejev/css-compiler",
"description": "compiles SASS and LESS assets on composer's callback",
"type": "lib",
"license": "MIT",
"authors": [
{
"name": "Eugene Matvejev",
"email": "eugene.matvejev@gmail.com"
}
],
"autoload": {
"psr-4": {
"EM\\CssCompiler\\": "src/"
},
"classmap": [
"ScriptHandler.php"
]
},
"autoload-dev": {
"psr-4": {
"EM\\Tests\\CssCompiler\\": "tests/"
}
},
"require": {
"php": ">= 5.6",
"leafo/lessphp": "^0.5",
"leafo/scssphp": "@dev",
"leafo/scssphp-compass": "@dev"
},
"require-dev": {
"composer/composer": "^1.1",
"phpunit/phpunit": "^5.3"
}
}
0