diff --git a/composer.json b/composer.json index 3344b85..3393400 100644 --- a/composer.json +++ b/composer.json @@ -8,8 +8,10 @@ "symplify/easy-coding-standard": "9.3.12" }, "require-dev": { + "composer/composer": "2.*", "jetbrains/phpstorm-attributes": "^1.0", - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5", + "symfony/console": "^5.3" }, "authors": [ { @@ -29,6 +31,10 @@ "scripts": { "ecs": "./vendor/bin/ecs check", "ecsf": "./vendor/bin/ecs check --fix", - "test": "./vendor/bin/phpunit tests --colors always" + "test": "./vendor/bin/phpunit tests --colors always", + "unit": "./vendor/bin/phpunit tests/unit --colors always", + "e2e": "./vendor/bin/phpunit tests/codestyle --colors always", + "ecs-tmp": "./vendor/bin/ecs check --config ./tests/codestyle/config.php", + "ecsf-tmp": "./vendor/bin/ecs check --config ./tests/codestyle/config.php --fix" } } diff --git a/ecs.php b/ecs.php index d0629d2..17db614 100644 --- a/ecs.php +++ b/ecs.php @@ -6,7 +6,7 @@ use Blumilk\Codestyle\Configuration\Defaults\Paths; $config = new Config( - paths: new Paths("examples", "src", "tests") + paths: new Paths("src", "tests/unit", "tests/codestyle/CodestyleTest.php") ); return $config->config(); diff --git a/examples/arrow_functions.php b/examples/arrow_functions.php deleted file mode 100644 index 0ac0a35..0000000 --- a/examples/arrow_functions.php +++ /dev/null @@ -1,5 +0,0 @@ - $i % 2 === 0); diff --git a/tests/codestyle/CodestyleTest.php b/tests/codestyle/CodestyleTest.php new file mode 100644 index 0000000..0c3d63d --- /dev/null +++ b/tests/codestyle/CodestyleTest.php @@ -0,0 +1,64 @@ +clearTempDirectory(); + } + + protected function tearDown(): void + { + $this->clearTempDirectory(); + } + + /** + * @throws Exception + */ + public function testFixtures(): void + { + $fixtures = scandir(__DIR__ . "/fixtures"); + $fixtures = array_filter($fixtures, fn(string $dir): bool => !str_contains($dir, ".")); + + foreach ($fixtures as $fixture) { + $this->testFixture($fixture); + } + } + + /** + * @throws Exception + */ + protected function runComposerEcsCommand(bool $fix = false): bool + { + $command = $fix ? "ecsf-tmp" : "ecs-tmp"; + $result = 0; + $output = null; + + exec("./vendor/bin/composer " . $command, $output, $result); + + return $result === 0; + } + + /** + * @throws Exception + */ + protected function testFixture(string $name): void + { + copy(__DIR__ . "/fixtures/${name}/actual.php", __DIR__ . "/tmp/${name}.php"); + $this->assertFalse($this->runComposerEcsCommand()); + $this->assertTrue($this->runComposerEcsCommand(true)); + $this->assertFileEquals(__DIR__ . "/fixtures/${name}/expected.php", __DIR__ . "/tmp/${name}.php"); + } + + protected function clearTempDirectory(): void + { + $files = glob(__DIR__ . "/tmp/*.php"); + foreach ($files as $file) { + unlink($file); + } + } +} diff --git a/tests/codestyle/config.php b/tests/codestyle/config.php new file mode 100644 index 0000000..4f813b4 --- /dev/null +++ b/tests/codestyle/config.php @@ -0,0 +1,12 @@ +config(); diff --git a/tests/codestyle/fixtures/singleQuotes/actual.php b/tests/codestyle/fixtures/singleQuotes/actual.php new file mode 100644 index 0000000..1fdae36 --- /dev/null +++ b/tests/codestyle/fixtures/singleQuotes/actual.php @@ -0,0 +1,8 @@ +