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