| 1 |
<?php |
| 2 |
|
| 3 |
namespace Leafo\ScssPhp\Tests; |
| 4 |
|
| 5 |
use Leafo\ScssPhp\Compiler; |
| 6 |
|
| 7 |
class ExceptionTest extends \PHPUnit_Framework_TestCase |
| 8 |
{ |
| 9 |
public function setUp() |
| 10 |
{ |
| 11 |
$this->scss = new Compiler(); |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* @param string $scss |
| 16 |
* @param string $expectedExceptionMessage |
| 17 |
* |
| 18 |
* @dataProvider provideScss |
| 19 |
*/ |
| 20 |
public function testThrowError($scss, $expectedExceptionMessage) |
| 21 |
{ |
| 22 |
try { |
| 23 |
$this->compile($scss); |
| 24 |
} catch (\Exception $e) { |
| 25 |
if (strpos($e->getMessage(), $expectedExceptionMessage) !== false) { |
| 26 |
return; |
| 27 |
}; |
| 28 |
} |
| 29 |
|
| 30 |
$this->fail('Expected exception to be raised: ' . $expectedExceptionMessage); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* @return array |
| 35 |
*/ |
| 36 |
public function provideScss() |
| 37 |
{ |
| 38 |
return array( |
| 39 |
array(<<<END_OF_SCSS |
| 40 |
.test { |
| 41 |
foo : bar; |
| 42 |
END_OF_SCSS |
| 43 |
, |
| 44 |
'unclosed block' |
| 45 |
), |
| 46 |
array(<<<END_OF_SCSS |
| 47 |
.test { |
| 48 |
}} |
| 49 |
END_OF_SCSS |
| 50 |
, |
| 51 |
'unexpected }' |
| 52 |
), |
| 53 |
array(<<<END_OF_SCSS |
| 54 |
.test { color: #fff / 0; } |
| 55 |
END_OF_SCSS |
| 56 |
, |
| 57 |
'color: Can\'t divide by zero' |
| 58 |
), |
| 59 |
array(<<<END_OF_SCSS |
| 60 |
.test { |
| 61 |
@include foo(); |
| 62 |
} |
| 63 |
END_OF_SCSS |
| 64 |
, |
| 65 |
'Undefined mixin foo' |
| 66 |
), |
| 67 |
array(<<<END_OF_SCSS |
| 68 |
@mixin do-nothing() { |
| 69 |
} |
| 70 |
|
| 71 |
.test { |
| 72 |
@include do-nothing(\$a: "hello"); |
| 73 |
} |
| 74 |
END_OF_SCSS |
| 75 |
, |
| 76 |
'Mixin or function doesn\'t have an argument named $a.' |
| 77 |
), |
| 78 |
array(<<<END_OF_SCSS |
| 79 |
div { |
| 80 |
color: darken(cobaltgreen, 10%); |
| 81 |
} |
| 82 |
END_OF_SCSS |
| 83 |
, |
| 84 |
'expecting color' |
| 85 |
), |
| 86 |
); |
| 87 |
} |
| 88 |
|
| 89 |
private function compile($str) |
| 90 |
{ |
| 91 |
return trim($this->scss->compile($str)); |
| 92 |
} |
| 93 |
} |
| 94 |
|