Skip to content

Commit c44b649

Browse files
author
emilien.escalle
committed
Improve phpunit tests
1 parent 1ec02e9 commit c44b649

File tree

3 files changed

+72
-24
lines changed

3 files changed

+72
-24
lines changed

src/CssLint/Linter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function lintString($sString)
8787
}
8888

8989
if (!$this->assertContext(null)) {
90-
$this->addError('Error : untermined "' . $this->context . '" (Start : ' . json_encode($this->getContextContent()) . ')');
90+
$this->addError('Unterminated "' . $this->context . '"');
9191
}
9292

9393
return !$this->getErrors();
@@ -134,7 +134,7 @@ public function lintFile($sFilePath)
134134
fclose($rFileHandle);
135135

136136
if (!$this->assertContext(null)) {
137-
$this->addError('Error : untermined "' . $this->context . '" (Start : ' . json_encode($this->getContextContent()) . ')');
137+
$this->addError('Unterminated "' . $this->context . '"');
138138
}
139139

140140
return !$this->getErrors();

tests/TestSuite/LinterTest.php

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,7 @@ public function setUp()
1515
$this->linter = new \CssLint\Linter();
1616
}
1717

18-
public function testLintBootstrapCssFile()
19-
{
20-
$this->assertTrue($this->linter->lintFile(getcwd() . DIRECTORY_SEPARATOR . '_files/bootstrap.css'), print_r($this->linter->getErrors(), true));
21-
}
22-
23-
public function testLintFoundationCssFile()
24-
{
25-
$this->assertTrue($this->linter->lintFile(getcwd() . DIRECTORY_SEPARATOR . '_files/foundation.css'), print_r($this->linter->getErrors(), true));
26-
}
27-
28-
public function testLintNotValidCssFile()
29-
{
30-
$this->assertFalse($this->linter->lintFile(getcwd() . DIRECTORY_SEPARATOR . '_files/not_valid.css'));
31-
$this->assertSame(array(
32-
'Unknown CSS property "bordr-top-style" (line: 8, char: 20)',
33-
'Unexpected char ":" (line: 15, char: 5)'
34-
), $this->linter->getErrors());
35-
}
36-
37-
public function testLintString()
18+
public function testLintValidString()
3819
{
3920
$this->assertTrue($this->linter->lintString('.button.dropdown::after {
4021
display: block;
@@ -55,4 +36,71 @@ public function testLintString()
5536
float: none;
5637
margin-left: 0; }'));
5738
}
39+
40+
public function testLintNotValidString()
41+
{
42+
$this->assertFalse($this->linter->lintString('.button.dropdown::after {
43+
displady: block;
44+
width: 0;
45+
:
46+
'));
47+
$this->assertSame(array(
48+
'Unknown CSS property "displady" (line: 2, char: 22)',
49+
'Unexpected char ":" (line: 4, char: 5)',
50+
), $this->linter->getErrors());
51+
}
52+
53+
public function testLintStringWithUnterminatedContext()
54+
{
55+
$this->assertFalse($this->linter->lintString('* {'));
56+
$this->assertSame(array(
57+
'Unterminated "selector content" (line: 1, char: 3)'
58+
), $this->linter->getErrors());
59+
}
60+
61+
/**
62+
* @expectedException \InvalidArgumentException
63+
* @expectedExceptionMessage Argument "$sString" expects a string, "boolean" given
64+
*/
65+
public function testLintStringWithWrongTypeParam()
66+
{
67+
$this->linter->lintString(false);
68+
}
69+
70+
/**
71+
* @expectedException \InvalidArgumentException
72+
* @expectedExceptionMessage Argument "$sFilePath" expects a string, "boolean" given
73+
*/
74+
public function testLintFileWithWrongTypeParam()
75+
{
76+
$this->linter->lintFile(false);
77+
}
78+
79+
/**
80+
* @expectedException \InvalidArgumentException
81+
* @expectedExceptionMessage Argument "$sFilePath" "wrong" is not an existing file path
82+
*/
83+
public function testLintFileWithUnkownFilePathParam()
84+
{
85+
$this->linter->lintFile('wrong');
86+
}
87+
88+
public function testLintBootstrapCssFile()
89+
{
90+
$this->assertTrue($this->linter->lintFile(getcwd() . DIRECTORY_SEPARATOR . '_files/bootstrap.css'), print_r($this->linter->getErrors(), true));
91+
}
92+
93+
public function testLintFoundationCssFile()
94+
{
95+
$this->assertTrue($this->linter->lintFile(getcwd() . DIRECTORY_SEPARATOR . '_files/foundation.css'), print_r($this->linter->getErrors(), true));
96+
}
97+
98+
public function testLintNotValidCssFile()
99+
{
100+
$this->assertFalse($this->linter->lintFile(getcwd() . DIRECTORY_SEPARATOR . '_files/not_valid.css'));
101+
$this->assertSame(array(
102+
'Unknown CSS property "bordr-top-style" (line: 8, char: 20)',
103+
'Unterminated "selector content" (line: 17, char: 0)'
104+
), $this->linter->getErrors());
105+
}
58106
}

tests/_files/not_valid.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
display: inline-block;
1313
float: right;
1414
margin-left: 1em;
15-
:
16-
}
15+
16+

0 commit comments

Comments
 (0)