-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from inpsyde/feat/e2e-tests
- Loading branch information
Showing
45 changed files
with
173 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Inpsyde\CodingStandard\Tests; | ||
|
||
use RuntimeException; | ||
|
||
class E2eTest extends TestCase | ||
{ | ||
private string $testPackagePath = ''; | ||
private string $phpCsBinary = ''; | ||
|
||
protected function setUp(): void | ||
{ | ||
$libPath = (string) getenv('LIB_PATH'); | ||
$this->testPackagePath = $libPath . '/tests/e2e/fixtures/test-package'; | ||
$this->phpCsBinary = $libPath . '/vendor/bin/phpcs'; | ||
} | ||
|
||
public function testInpsydeAndTemplatesRulesets(): void | ||
{ | ||
$output = []; | ||
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_exec | ||
exec( | ||
sprintf( | ||
'cd %s && %s', | ||
$this->testPackagePath, | ||
$this->phpCsBinary | ||
), | ||
$output | ||
); | ||
|
||
/** @var array<string> $output> */ | ||
if ($output[0] !== 'EE 2 / 2 (100%)') { | ||
throw new RuntimeException(implode("\n", $output)); | ||
} | ||
|
||
$json = end($output); | ||
|
||
// phpcs:disable Inpsyde.CodeQuality.LineLength.TooLong | ||
$expectedMessages = [ | ||
'index.php' => [ | ||
[ | ||
'source' => 'Inpsyde.CodeQuality.NoElse.ElseFound', | ||
'line' => 12, | ||
], | ||
[ | ||
'source' => 'WordPress.Security.EscapeOutput.OutputNotEscaped', | ||
'line' => 13, | ||
], | ||
], | ||
'template.php' => [ | ||
|
||
[ | ||
'source' => 'WordPress.Security.EscapeOutput.OutputNotEscaped', | ||
'line' => 12, | ||
], | ||
[ | ||
'source' => 'InpsydeTemplates.Formatting.TrailingSemicolon.Found', | ||
'line' => 12, | ||
], | ||
[ | ||
'source' => 'Inpsyde.CodeQuality.DisableCallUserFunc.call_user_func_call_user_func', | ||
'line' => 15, | ||
], | ||
|
||
], | ||
]; | ||
// phpcs:enable Inpsyde.CodeQuality.LineLength.TooLong | ||
|
||
self::assertSame($expectedMessages, $this->phpCsMessages($json)); | ||
} | ||
|
||
/** | ||
* @psalm-return array<string, list<array{source: string, line: positive-int}>> | ||
*/ | ||
private function phpCsMessages(string $json): array | ||
{ | ||
/** @var array{ | ||
* files: array<string, array{ | ||
* messages: list<array{ | ||
* source: string, | ||
* line: positive-int, | ||
* ... | ||
* }> | ||
* }> | ||
* } $data */ | ||
$data = json_decode($json, true, 512, JSON_THROW_ON_ERROR); | ||
|
||
$result = []; | ||
foreach ($data['files'] as $fileName => $fileData) { | ||
$baseName = basename($fileName); | ||
$result[$baseName] = []; | ||
foreach ($fileData['messages'] as ['source' => $source, 'line' => $line]) { | ||
$result[$baseName][] = ['source' => $source, 'line' => $line]; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
$value = rand(0, 1); | ||
|
||
$successMessage = 'Success!'; | ||
$errorMessage = 'Error!'; | ||
|
||
if ($value > 0.5) { | ||
echo esc_html($successMessage); | ||
} else { | ||
echo $errorMessage; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="Coding Standard Test"> | ||
|
||
<file>./index.php</file> | ||
<file>./templates</file> | ||
|
||
<arg value="sp"/> | ||
<arg name="report" value="json"/> | ||
|
||
<rule ref="Inpsyde"/> | ||
|
||
<rule ref="Inpsyde.CodeQuality.NoElse"> | ||
<exclude-pattern>*/templates/*</exclude-pattern> | ||
</rule> | ||
|
||
<rule ref="InpsydeTemplates"> | ||
<include-pattern>*/templates/*</include-pattern> | ||
</rule> | ||
|
||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
$value = rand(0, 1); | ||
$successMessage = 'Success!'; | ||
$errorMessage = 'Error!' ?> | ||
|
||
<?php if ($value > 0.5) : ?> | ||
<?= esc_html($successMessage) ?> | ||
<?php else : ?> | ||
<?= $errorMessage; ?> | ||
<?php endif; | ||
|
||
call_user_func('strtolower', 'foo'); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.