Add lint-clean and cleanup code linting

This commit is contained in:
Damian Mooyman 2017-05-12 15:17:23 +12:00 committed by Sam Minnée
parent 3da1587289
commit 7a8dfd2785
3 changed files with 608 additions and 634 deletions

View File

@ -84,7 +84,8 @@
"thirdparty/"
],
"scripts": {
"lint": "phpcs --standard=tests/phpcs/ruleset.xml src/ tests/php",
"lint": "phpcs src/ tests/php",
"lint-clean": "phpcbf src/ tests/php",
"php-peg": "php thirdparty/php-peg/cli.php src/View/SSTemplateParser.peg > src/View/SSTemplateParser.php"
},
"minimum-stability": "dev",

View File

@ -2,6 +2,7 @@
namespace SilverStripe\View\Tests;
use PHPUnit_Framework_MockObject_MockObject;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Control\ContentNegotiator;
@ -80,12 +81,7 @@ class SSViewerTest extends SapphireTest
*/
public function testTemplateWithoutHeadRenders()
{
$data = new ArrayData(
array(
'Var' => 'var value'
)
);
$data = new ArrayData([ 'Var' => 'var value' ]);
$result = $data->renderWith("SSViewerTestPartialTemplate");
$this->assertEquals('Test partial template: var value', trim(preg_replace("/<!--.*-->/U", '', $result)));
}
@ -121,54 +117,46 @@ class SSViewerTest extends SapphireTest
public function testIncludeTruthyness()
{
$data = new ArrayData(
array(
$data = new ArrayData([
'Title' => 'TruthyTest',
'Items' => new ArrayList(
array(
new ArrayData(array('Title' => 'Item 1')),
new ArrayData(array('Title' => '')),
new ArrayData(array('Title' => true)),
new ArrayData(array('Title' => false)),
new ArrayData(array('Title' => null)),
new ArrayData(array('Title' => 0)),
new ArrayData(array('Title' => 7))
)
)
)
);
'Items' => new ArrayList([
new ArrayData(['Title' => 'Item 1']),
new ArrayData(['Title' => '']),
new ArrayData(['Title' => true]),
new ArrayData(['Title' => false]),
new ArrayData(['Title' => null]),
new ArrayData(['Title' => 0]),
new ArrayData(['Title' => 7])
])
]);
$result = $data->renderWith('SSViewerTestIncludeScopeInheritanceWithArgs');
// We should not end up with empty values appearing as empty
$expected = array(
$expected = [
'Item 1 _ Item 1 - First-ODD top:Item 1',
'Untitled - EVEN top:',
'1 _ 1 - ODD top:1',
'Untitled - EVEN top:',
'Untitled - ODD top:',
'Untitled - EVEN top:0',
'7 _ 7 - Last-ODD top:7'
);
'7 _ 7 - Last-ODD top:7',
];
$this->assertExpectedStrings($result, $expected);
}
private function getScopeInheritanceTestData()
{
return new ArrayData(
array(
return new ArrayData([
'Title' => 'TopTitleValue',
'Items' => new ArrayList(
array(
new ArrayData(array('Title' => 'Item 1')),
new ArrayData(array('Title' => 'Item 2')),
new ArrayData(array('Title' => 'Item 3')),
new ArrayData(array('Title' => 'Item 4')),
new ArrayData(array('Title' => 'Item 5')),
new ArrayData(array('Title' => 'Item 6'))
)
)
)
);
'Items' => new ArrayList([
new ArrayData(['Title' => 'Item 1']),
new ArrayData(['Title' => 'Item 2']),
new ArrayData(['Title' => 'Item 3']),
new ArrayData(['Title' => 'Item 4']),
new ArrayData(['Title' => 'Item 5']),
new ArrayData(['Title' => 'Item 6'])
])
]);
}
private function assertExpectedStrings($result, $expected)
@ -200,7 +188,10 @@ class SSViewerTest extends SapphireTest
public function testRequirements()
{
$requirements = $this->getMockBuilder(Requirements_Backend::class)->setMethods(array("javascript", "css"))
/** @var Requirements_Backend|PHPUnit_Framework_MockObject_MockObject $requirements */
$requirements = $this
->getMockBuilder(Requirements_Backend::class)
->setMethods(array("javascript", "css"))
->getMock();
$jsFile = FRAMEWORK_DIR . '/tests/forms/a.js';
$cssFile = FRAMEWORK_DIR . '/tests/forms/a.js';
@ -285,8 +276,7 @@ class SSViewerTest extends SapphireTest
public function testComments()
{
$output = $this->render(
<<<SS
$input = <<<SS
This is my template<%-- this is a comment --%>This is some content<%-- this is another comment --%>Final content
<%-- Alone multi
line comment --%>
@ -294,8 +284,8 @@ Some more content
Mixing content and <%-- multi
line comment --%> Final final
content
SS
);
SS;
$output = $this->render($input);
$shouldbe = <<<SS
This is my templateThis is some contentFinal content
@ -303,7 +293,6 @@ Some more content
Mixing content and Final final
content
SS;
$this->assertEquals($shouldbe, $output);
}
@ -479,11 +468,9 @@ SS;
public function testLocalFunctionsTakePriorityOverGlobals()
{
$data = new ArrayData(
array(
$data = new ArrayData([
'Page' => new SSViewerTest\TestObject()
)
);
]);
//call method with lots of arguments
$result = $this->render(
@ -512,38 +499,24 @@ SS;
public function testCurrentScopeLoopWith()
{
// Data to run the loop tests on - one sequence of three items, each with a subitem
$data = new ArrayData(
array(
'Foo' => new ArrayList(
array(
'Subocean' => new ArrayData(
array(
$data = new ArrayData([
'Foo' => new ArrayList([
'Subocean' => new ArrayData([
'Name' => 'Higher'
)
),
new ArrayData(
array(
'Sub' => new ArrayData(
array(
]),
new ArrayData([
'Sub' => new ArrayData([
'Name' => 'SubKid1'
)
)
)
),
new ArrayData(
array(
'Sub' => new ArrayData(
array(
])
]),
new ArrayData([
'Sub' => new ArrayData([
'Name' => 'SubKid2'
)
)
)
),
])
]),
new SSViewerTest\TestObject('Number6')
)
)
)
);
])
]);
$result = $this->render(
'<% loop Foo %>$Number<% if Sub %><% with Sub %>$Name<% end_with %><% end_if %><% end_loop %>',