-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #24 - testing configured ECS behavior * #24 - ecsf * Update tests/codestyle/CodestyleTest.php Co-authored-by: Jacek Sawoszczuk <jacek.sawoszczuk@gmail.com> * #24 - after-cr changes Co-authored-by: Jacek Sawoszczuk <jacek.sawoszczuk@gmail.com>
- Loading branch information
1 parent
494cbdb
commit e4868bc
Showing
17 changed files
with
127 additions
and
12 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 was deleted.
Oops, something went wrong.
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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class CodestyleTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$this->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); | ||
} | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Blumilk\Codestyle\Config; | ||
use Blumilk\Codestyle\Configuration\Defaults\Paths; | ||
|
||
$config = new Config( | ||
paths: new Paths("./tests/codestyle/tmp") | ||
); | ||
|
||
return $config->config(); |
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,8 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
echo 'Test'; | ||
|
||
$array = []; | ||
$array['test'] = '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,8 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
echo "Test"; | ||
|
||
$array = []; | ||
$array["test"] = "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,5 @@ | ||
<?php | ||
|
||
class StrictTypesExample | ||
{ | ||
} |
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,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
class StrictTypesExample | ||
{ | ||
} |
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,11 @@ | ||
<?php | ||
|
||
class UnionTypesExample | ||
{ | ||
public int|string $something; | ||
|
||
public function do(): void { | ||
$i = 1+1; | ||
json_encode([$i], JSON_THROW_ON_ERROR|JSON_UNESCAPED_SLASHES); | ||
} | ||
} |
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,2 @@ | ||
* | ||
!.gitignore |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.