Skip to content

Commit 1607ef0

Browse files
committed
refactor ExceptionTest and add a couple more test cases
1 parent 404d778 commit 1607ef0

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

tests/ExceptionTest.php

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,60 @@ public function setUp() {
77
$this->scss = new scssc();
88
}
99

10-
public function compile($str) {
11-
return trim($this->scss->compile($str));
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);
1226
}
1327

14-
public function testMixinUnusedArgs() {
15-
try {
16-
$output = $this->compile(<<<END_OF_SCSS
28+
/**
29+
* @return array
30+
*/
31+
public function provideScss() {
32+
return array(
33+
array(<<<END_OF_SCSS
34+
.test {
35+
@include foo();
36+
}
37+
END_OF_SCSS
38+
,
39+
'Undefined mixin foo'
40+
),
41+
array(<<<END_OF_SCSS
1742
@mixin do-nothing() {
1843
}
1944
2045
.test {
2146
@include do-nothing(\$a: "hello");
2247
}
2348
END_OF_SCSS
24-
);
25-
} catch (Exception $e) {
26-
if (strpos($e->getMessage(), 'Mixin or function doesn\'t have an argument named $a.') !== false) {
27-
return;
28-
};
29-
}
49+
,
50+
'Mixin or function doesn\'t have an argument named $a.'
51+
),
52+
array(<<<END_OF_SCSS
53+
div {
54+
color: darken(cobaltgreen, 10%);
55+
}
56+
END_OF_SCSS
57+
,
58+
'expecting color'
59+
),
60+
);
61+
}
3062

31-
$this->fail('Expected exception to be raised');
63+
private function compile($str) {
64+
return trim($this->scss->compile($str));
3265
}
3366
}

0 commit comments

Comments
 (0)