Skip to content
Snippets Groups Projects
Commit 8126828b authored by Daniel Siepmann's avatar Daniel Siepmann
Browse files

Merge remote-tracking branch 'origin/develop' into feature/allow-phpcs-30

parents 3f981716 d13e6797
1 merge request!39TASK: Allow PHP Code Sniffer 3.0 to be required
Pipeline #330 passed with stage
in 5 minutes and 13 seconds
......@@ -57,8 +57,8 @@ class Standard implements StandardInterface
);
}
$this->path = realpath($path);
$this->name = basename($this->path);
$this->ruleSetXmlPath = $path . DIRECTORY_SEPARATOR . static::RULESET_FILENAME;
$this->name = $this->getNameFromRuleSet($this->ruleSetXmlPath);
if (!is_readable($this->ruleSetXmlPath)) {
throw new InvalidStandardException(
......@@ -67,6 +67,28 @@ class Standard implements StandardInterface
}
}
/**
* Fetch PHPCodeSniffer standard name from ruleset.xml.
*
* @param string $ruleSetXmlPath The absolute path to ruleset.xml.
* @return string The name of the PHPCodeSniffer standard.
*/
protected function getNameFromRuleSet($ruleSetXmlPath)
{
try {
$ruleSet = new \SimpleXMLElement(file_get_contents($ruleSetXmlPath));
$attributes = $ruleSet->attributes();
$name = trim($attributes['name']);
if ($name !== '') {
return $name;
}
} catch (\Exception $e) {
// Nothing todo, use folder name.
}
return basename(dirname($ruleSetXmlPath));
}
/**
* Get the name of the PHPCodeSniffer standard.
*
......
<?xml version="1.0"?>
<ruleset name="CustomStandard">
</ruleset>
<?xml version="1.0"?>
<ruleset name="">
</ruleset>
......@@ -42,13 +42,11 @@ class FinderTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
parent::setUp();
$this->standardsFactoryMock = $this->getMock(
'Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Factory',
array(),
array(),
'',
false
);
$this->standardsFactoryMock = $this->getMockBuilder(
'Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Factory'
)
->disableOriginalConstructor()
->getMock();
$this->fixture = new Finder(null, $this->standardsFactoryMock);
}
......@@ -66,6 +64,8 @@ class FinderTest extends \PHPUnit_Framework_TestCase
$path . DIRECTORY_SEPARATOR . 'Standard1',
$path . DIRECTORY_SEPARATOR . 'Standard2',
$path . DIRECTORY_SEPARATOR . 'Standard3',
$path . DIRECTORY_SEPARATOR . 'standard_with_ruleset',
$path . DIRECTORY_SEPARATOR . 'standard_with_ruleset_without_name',
);
$this->standardsFactoryMock
......
......@@ -54,20 +54,18 @@ class FinderTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
parent::setUp();
$this->symfonyFinderFactoryMock = $this->getMock(
$this->symfonyFinderFactoryMock = $this->getMockBuilder(
'Higidi\ComposerPhpCSStandardsPlugin\Symfony\Finder\Factory'
);
$this->symfonyFinderMock = $this->getMock('Symfony\Component\Finder\Finder');
)->getMock();
$this->symfonyFinderMock = $this->getMockBuilder('Symfony\Component\Finder\Finder')->getMock();
$this->symfonyFinderFactoryMock
->method('create')
->willReturn($this->symfonyFinderMock);
$this->standardsFactoryMock = $this->getMock(
'Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Factory',
array(),
array(),
'',
false
);
$this->standardsFactoryMock = $this->getMockBuilder(
'Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Factory'
)
->disableOriginalConstructor()
->getMock();
$this->classUnderTesting = new Finder($this->symfonyFinderFactoryMock, $this->standardsFactoryMock);
}
......@@ -91,11 +89,9 @@ class FinderTest extends \PHPUnit_Framework_TestCase
->willReturn($this->symfonyFinderMock);
}
$splFileInfoMock = $this->getMock(
'Symfony\Component\Finder\SplFileInfo',
array(),
array(null, null, null)
);
$splFileInfoMock = $this->getMockBuilder('Symfony\Component\Finder\SplFileInfo')
->setConstructorArgs(array(null, null, null))
->getMock();
$splFileInfoMock
->expects($this->once())
->method('getPath')
......
......@@ -23,6 +23,7 @@ namespace Higidi\ComposerPhpCSStandardsPlugin\Tests\Unit\PHPCodeSniffer\Standard
use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Factory;
use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Factory as StandardFactory;
use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Standard;
/**
* Test case for class \Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\StandardsFactory
......@@ -42,19 +43,15 @@ class FactoryTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
parent::setUp();
$this->standardFactoryMock = $this->getMock(
$this->standardFactoryMock = $this->getMockBuilder(
'Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Factory'
);
)->getMock();
$this->standardFactoryMock
->method('create')
->willReturn(
$this->getMock(
'Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Standard',
array(),
array(),
'',
false
)
$this->getMockBuilder('Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Standard')
->disableOriginalConstructor()
->getMock()
);
$this->classUnderTesting = new Factory($this->standardFactoryMock);
......
......@@ -53,6 +53,9 @@ class FactoryTest extends \PHPUnit_Framework_TestCase
);
$standard = $this->classUnderTesting->create($path);
$this->assertInstanceOf('Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Standard', $standard);
$this->assertInstanceOf(
'Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Standard',
$standard
);
}
}
......@@ -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 array(
'No Ruleset' => array(
'Standard1',
'Standard1',
),
'Ruleset with name' => array(
'standard_with_ruleset',
'CustomStandard',
),
'Ruleset without name' => array(
'standard_with_ruleset_without_name',
'standard_with_ruleset_without_name',
),
);
}
/**
* @expectedException \Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Exception\StandardPathAccessDeniedException
*/
......
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