-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,826 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
cacheResultFile=".tmp/PHPUnit/.phpunit.result.cache" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Unit"> | ||
<directory suffix="Test.php">./tests/Codestyle</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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,90 @@ | ||
<?php | ||
|
||
namespace Realodix\Relax\Tests\Codestyle; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Input\StringInput; | ||
|
||
abstract class CodestyleTestCase extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$this->clearTempDirectory(); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
$this->clearTempDirectory(); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
protected function testFixture(string $name, ?string $suffix = null): void | ||
{ | ||
$fileName = $name; | ||
|
||
if (! is_null($suffix)) { | ||
$fileName = $fileName.'-'.$suffix; | ||
} | ||
|
||
copy(__DIR__."/../Fixtures/Ruleset/{$fileName}_actual.php", __DIR__."/tmp/{$fileName}.php"); | ||
|
||
$this->assertTrue( | ||
file_exists(__DIR__."/tmp/{$fileName}.php"), | ||
"Fixture fixtures/{$fileName} does not exist.", | ||
); | ||
|
||
$this->assertTrue( | ||
is_writable(__DIR__."/tmp/{$fileName}.php"), | ||
"Fixture fixtures/{$fileName} is not writable.", | ||
); | ||
|
||
$this->assertFalse( | ||
$this->runFixer($name), | ||
"Fixture fixtures/{$fileName} returned invalid true result.", | ||
); | ||
|
||
$this->assertTrue( | ||
$this->runFixer($name, true), | ||
"Fixture fixtures/{$fileName} was not proceeded properly.", | ||
); | ||
|
||
$this->assertFileEquals( | ||
__DIR__."/../Fixtures/Ruleset/{$fileName}_expected.php", | ||
__DIR__."/tmp/{$fileName}.php", | ||
"Result of proceeded fixture fixtures/{$fileName} is not equal to expected.", | ||
); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
protected function runFixer(string $name, bool $fix = false): bool | ||
{ | ||
$dryRun = $fix ? '' : '--dry-run'; | ||
|
||
$application = new \PhpCsFixer\Console\Application; | ||
$application->setAutoExit(false); | ||
|
||
$output = new \Symfony\Component\Console\Output\BufferedOutput; | ||
$config = "tests/Codestyle/Config/config_{$name}.php"; | ||
$result = $application->run(new StringInput("fix {$dryRun} --diff --config={$config} --quiet"), $output); | ||
|
||
return $result === 0; | ||
} | ||
|
||
protected function clearTempDirectory(): void | ||
{ | ||
$files = glob(__DIR__.'/tmp/*.php'); | ||
|
||
foreach ($files as $file) { | ||
unlink($file); | ||
} | ||
} | ||
|
||
protected function getConfigPath(): string | ||
{ | ||
return 'tests/codestyle/config/config_relax.php'; | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
use PhpCsFixer\Finder; | ||
use Realodix\Relax\Config; | ||
|
||
$finder = (new Finder)->in('./tests/Codestyle/tmp'); | ||
|
||
return Config::create('relax') | ||
->setFinder($finder) | ||
->setUsingCache(false); |
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,21 @@ | ||
<?php | ||
|
||
namespace Realodix\Relax\Tests\Codestyle; | ||
|
||
class RelaxRulesetTest extends CodestyleTestCase | ||
{ | ||
public function testRelaxRuleset(): void | ||
{ | ||
$this->testFixture('relax'); | ||
} | ||
|
||
public function testRelaxCustom(): void | ||
{ | ||
$this->testFixture('relax', 'custom'); | ||
} | ||
|
||
public function testRelaxCleanup(): void | ||
{ | ||
$this->testFixture('relax', 'deprecated'); | ||
} | ||
} |
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,2 @@ | ||
* | ||
!.gitignore |
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,50 @@ | ||
<?php | ||
namespace Realodix\Relax; | ||
|
||
use DateTime; | ||
|
||
/** | ||
* FooRepository | ||
* | ||
* This class was generated by the Doctrine ORM. Add your own custom | ||
* repository methods below. | ||
*/ | ||
class RelaxCustom | ||
{ | ||
/** | ||
* @var RelaxCustom PhpdocSelfAccessorFixer | ||
*/ | ||
private $instance; | ||
|
||
/** | ||
* @var array<int,string> | ||
*/ | ||
private $phpdocTypesCommaSpacesFixer; | ||
|
||
/** Hello | ||
* World! | ||
*/ | ||
public function multilineCommentOpeningClosingAloneFixer() {} | ||
|
||
public function noImportFromGlobalNamespaceFixer(DateTime $dateTime) {} | ||
|
||
/** | ||
* Created by PhpStorm. | ||
* User: root * Date: 01.01.70 | ||
* Time: 12:00 | ||
*/ | ||
public function noPhpStormGeneratedCommentFixer() {} | ||
|
||
/** | ||
* @param bool $b | ||
* @param int $i | ||
* @param string $s this is string | ||
* @param string $s duplicated | ||
*/ | ||
public function phpdocNoSuperfluousParamFixer() {} | ||
|
||
/** | ||
* @param null | string $x | ||
*/ | ||
public function phpdocTypesTrimFixer($x) {} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Realodix\Relax; | ||
|
||
class RelaxCustom | ||
{ | ||
/** | ||
* @var self PhpdocSelfAccessorFixer | ||
*/ | ||
private $instance; | ||
|
||
/** | ||
* @var array<int, string> | ||
*/ | ||
private $phpdocTypesCommaSpacesFixer; | ||
|
||
/** | ||
* Hello | ||
* World! | ||
*/ | ||
public function multilineCommentOpeningClosingAloneFixer() {} | ||
|
||
public function noImportFromGlobalNamespaceFixer(\DateTime $dateTime) {} | ||
|
||
public function noPhpStormGeneratedCommentFixer() {} | ||
|
||
public function phpdocNoSuperfluousParamFixer() {} | ||
|
||
/** | ||
* @param null|string $x | ||
*/ | ||
public function phpdocTypesTrimFixer($x) {} | ||
} |
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,23 @@ | ||
<?php | ||
namespace Realodix\Relax; | ||
|
||
class RelaxDeprecatedSets extends Config | ||
{ | ||
public function cast_notation() | ||
{ | ||
$b = 2; | ||
|
||
// no_unset_cast | ||
$a = (unset) $b; | ||
} | ||
|
||
public function string_notation__simple_to_complex_string_variable() | ||
{ | ||
$name = 'World'; | ||
|
||
echo "Hello ${name}!"; | ||
echo <<<TEST | ||
-Hello ${name}! | ||
TEST; | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace Realodix\Relax; | ||
|
||
class RelaxDeprecatedSets extends Config | ||
{ | ||
public function cast_notation() | ||
{ | ||
$b = 2; | ||
|
||
// no_unset_cast | ||
$a = null; | ||
} | ||
|
||
public function string_notation__simple_to_complex_string_variable() | ||
{ | ||
$name = 'World'; | ||
|
||
echo "Hello {$name}!"; | ||
echo <<<TEST | ||
-Hello {$name}! | ||
TEST; | ||
} | ||
} |
Oops, something went wrong.