Skip to content

Commit 3a2561d

Browse files
authored
Merge pull request #5079 from magento-engcom/coding-standard-update
ENGCOM-6317: Bump coding standard version
2 parents e99537f + a5d0522 commit 3a2561d

File tree

6 files changed

+107
-35
lines changed

6 files changed

+107
-35
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
8888
"friendsofphp/php-cs-fixer": "~2.14.0",
8989
"lusitanian/oauth": "~0.8.10",
90-
"magento/magento-coding-standard": "~4.0.0",
90+
"magento/magento-coding-standard": "*",
9191
"magento/magento2-functional-testing-framework": "2.5.3",
9292
"pdepend/pdepend": "2.5.2",
9393
"phpcompatibility/php-compatibility": "^9.3",

composer.lock

Lines changed: 23 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\TestFramework\CodingStandard\Tool\CodeSniffer;
9+
10+
/**
11+
* Add GraphQl files extension to config.
12+
*/
13+
class GraphQlWrapper extends Wrapper
14+
{
15+
const FILE_EXTENSION = 'graphqls';
16+
17+
private const TOKENIZER = 'GraphQL';
18+
19+
/**
20+
* @inheritDoc
21+
*/
22+
public function init()
23+
{
24+
parent::init();
25+
26+
$this->config->extensions += [self::FILE_EXTENSION => self::TOKENIZER];
27+
}
28+
}

dev/tests/static/framework/Magento/ruleset.xml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,4 @@
1515
<exclude-pattern>*/Test/*</exclude-pattern>
1616
<exclude-pattern>*Test.php</exclude-pattern>
1717
</rule>
18-
<rule ref="Magento2.Files.LineLength.MaxExceeded">
19-
<exclude-pattern>*.phtml</exclude-pattern>
20-
</rule>
21-
<rule ref="Squiz.Operators.IncrementDecrementUsage">
22-
<exclude-pattern>*.phtml</exclude-pattern>
23-
</rule>
24-
<rule ref="PEAR.ControlStructures.ControlSignature">
25-
<exclude-pattern>*.phtml</exclude-pattern>
26-
</rule>
27-
<rule ref="Squiz.WhiteSpace.ScopeClosingBrace">
28-
<exclude-pattern>*.phtml</exclude-pattern>
29-
</rule>
30-
<rule ref="PEAR.Functions.FunctionCallSignature">
31-
<exclude-pattern>*.phtml</exclude-pattern>
32-
</rule>
33-
<rule ref="Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace">
34-
<exclude-pattern>*.phtml</exclude-pattern>
35-
</rule>
36-
<rule ref="Magento2.Security.LanguageConstruct.DirectOutput">
37-
<exclude-pattern>*.phtml</exclude-pattern>
38-
</rule>
3918
</ruleset>

dev/tests/static/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
<testsuite name="HTML Static Code Analysis">
2222
<file>testsuite/Magento/Test/Html/LiveCodeTest.php</file>
2323
</testsuite>
24+
<testsuite name="GraphQL Static Code Analysis">
25+
<file>testsuite/Magento/Test/GraphQl/LiveCodeTest.php</file>
26+
</testsuite>
2427
<testsuite name="PHP Coding Standard Verification">
2528
<file>testsuite/Magento/Test/Php/LiveCodeTest.php</file>
2629
</testsuite>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Test\GraphQl;
9+
10+
use Magento\TestFramework\CodingStandard\Tool\CodeSniffer;
11+
use Magento\TestFramework\CodingStandard\Tool\CodeSniffer\Wrapper;
12+
use Magento\Test\Php\LiveCodeTest as PHPCodeTest;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* Set of tests for static code style
17+
*/
18+
class LiveCodeTest extends TestCase
19+
{
20+
/**
21+
* @var string
22+
*/
23+
private static $reportDir = '';
24+
25+
/**
26+
* Setup basics for all tests
27+
*/
28+
public static function setUpBeforeClass(): void
29+
{
30+
self::$reportDir = BP . '/dev/tests/static/report';
31+
if (!is_dir(self::$reportDir)) {
32+
mkdir(self::$reportDir, 0770);
33+
}
34+
}
35+
36+
/**
37+
* Test GraphQL schema files code style using phpcs
38+
*/
39+
public function testCodeStyle(): void
40+
{
41+
$reportFile = self::$reportDir . '/graphql_phpcs_report.txt';
42+
$codeSniffer = new CodeSniffer('Magento', $reportFile, new Wrapper());
43+
$codeSniffer->setExtensions([CodeSniffer\GraphQlWrapper::FILE_EXTENSION]);
44+
$result = $codeSniffer->run(PHPCodeTest::getWhitelist([CodeSniffer\GraphQlWrapper::FILE_EXTENSION]));
45+
$report = file_exists($reportFile) ? file_get_contents($reportFile) : '';
46+
$this->assertEquals(
47+
0,
48+
$result,
49+
"PHP Code Sniffer detected {$result} violation(s): " . PHP_EOL . $report
50+
);
51+
}
52+
}

0 commit comments

Comments
 (0)