Commit e1865790 authored by Daniel Siepmann's avatar Daniel Siepmann

TASK: Add tests

parent 9349d803
......@@ -77,10 +77,15 @@ class Standard implements StandardInterface
{
try {
$ruleSet = new \SimpleXMLElement(file_get_contents($ruleSetXmlPath));
return (string) $ruleSet->attributes()['name'];
$name = trim($ruleSet->attributes()['name']);
if ($name !== '') {
return $name;
}
} catch (\Exception $e) {
return basename(dirname($ruleSetXmlPath));
// Nothing todo, use folder name.
}
return basename(dirname($ruleSetXmlPath));
}
/**
......
<?xml version="1.0"?>
<ruleset name="CustomStandard">
</ruleset>
<?xml version="1.0"?>
<ruleset name="">
</ruleset>
......@@ -28,18 +28,24 @@ use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Standa
*/
class StandardTest extends \PHPUnit_Framework_TestCase
{
public function testStandard()
/**
* @dataProvider differentStandards
*/
public function testStandard($standardName, $expectedName)
{
$name = 'Standard1';
$path = implode(
DIRECTORY_SEPARATOR,
array(__DIR__, '..', '..', '..', '..', '..', 'Fixtures', 'Standards', $name)
array(__DIR__, '..', '..', '..', '..', '..', 'Fixtures', 'Standards', $standardName)
);
$ruleSetXmlPath = $path . DIRECTORY_SEPARATOR . 'ruleset.xml';
$standard = new Standard($path);
$this->assertSame($name, $standard->getName(), 'The standard instance did not return the expected name.');
$this->assertSame(
$expectedName,
$standard->getName(),
'The standard instance did not return the expected name.'
);
$this->assertSame(
realpath($path),
$standard->getPath(),
......@@ -52,6 +58,24 @@ class StandardTest extends \PHPUnit_Framework_TestCase
);
}
public function differentStandards()
{
return [
'No Ruleset' => [
'Standard1',
'Standard1',
],
'Ruleset with name' => [
'standard_with_ruleset',
'CustomStandard',
],
'Ruleset without name' => [
'standard_with_ruleset_without_name',
'standard_with_ruleset_without_name',
],
];
}
/**
* @expectedException \Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Exception\StandardPathAccessDeniedException
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment