Skip to content

Commit

Permalink
Applied PHP-CS
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkyle committed Aug 10, 2024
1 parent 3a3f216 commit 6d618f5
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 33 deletions.
21 changes: 21 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
$header = <<<EOF
This file is part of tomkyle/find-run-test
EOF;

$finder = PhpCsFixer\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests'
]);

return (new PhpCsFixer\Config())->setRules([
'@PER-CS' => true,

'header_comment' => [
'comment_type' => 'PHPDoc',
'header' => $header,
'location' => 'after_open',
'separate' => 'both',
]
])->setFinder($finder);
12 changes: 8 additions & 4 deletions src/ConfigurableTestRunnerInterface.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<?php

/**
* This file is part of tomkyle/find-run-test
*/

namespace tomkyle\FindRunTest;

interface ConfigurableTestRunnerInterface extends TestRunnerInterface
{
public function setCommand(string $cmd) : self;
public function setCommand(string $cmd): self;

public function setConfig(string $config) : self;
public function setConfig(string $config): self;

public function setTestsDirectory(string $dir) : self;
public function setTestsDirectory(string $dir): self;

public function useColors(bool $colors = null) : self|bool;
public function useColors(bool $colors = null): self|bool;
}
27 changes: 16 additions & 11 deletions src/PhpUnitRunner.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/**
* This file is part of tomkyle/find-run-test
*/

namespace tomkyle\FindRunTest;

use Symfony\Component\Finder\Finder;
Expand All @@ -8,7 +12,6 @@

class PhpUnitRunner implements ConfigurableTestRunnerInterface
{

/**
* @var string
*/
Expand Down Expand Up @@ -48,7 +51,8 @@ public function __construct(string $config = null, string $tests = null, string
* @throws ProcessFailedException on Process error.
*/
#[\Override]
public function __invoke(string $file) : int {
public function __invoke(string $file): int
{
// Construct the expected name of the test file
$file_basename = pathinfo($file, PATHINFO_FILENAME);
$test_file = $file_basename . 'Test';
Expand Down Expand Up @@ -86,14 +90,15 @@ public function __invoke(string $file) : int {
* @param string $unit_test Example: `MyClassTest.php`
*/
#[\Override]
public function runTest(string $unit_test) : self {
public function runTest(string $unit_test): self
{

$process_args = array_filter([
$this->phpunit_cmd,
$this->phpunit_config ? '--configuration' : null,
$this->phpunit_config ?: null,
'--filter',
$unit_test
$unit_test,
]);

$process = (new Process($process_args))
Expand All @@ -114,7 +119,7 @@ public function runTest(string $unit_test) : self {
* Sets the tests directory
*/
#[\Override]
public function setTestsDirectory(string $dir) : self
public function setTestsDirectory(string $dir): self
{
$this->tests_directory = $dir;
return $this;
Expand All @@ -123,15 +128,15 @@ public function setTestsDirectory(string $dir) : self
/**
* Returns the tests directory
*/
public function getTestsDirectory() : string
public function getTestsDirectory(): string
{
return $this->tests_directory;
}

/**
* Returns the PhpUnit executable.
*/
public function getCommand() : string
public function getCommand(): string
{
return $this->phpunit_cmd;
}
Expand All @@ -141,7 +146,7 @@ public function getCommand() : string
* @param string $cmd Path to PhpUnit executable
*/
#[\Override]
public function setCommand(string $cmd) : self
public function setCommand(string $cmd): self
{
$this->phpunit_cmd = $cmd;
return $this;
Expand All @@ -152,7 +157,7 @@ public function setCommand(string $cmd) : self
/**
* Returns the PhpUnit config file.
*/
public function getConfig() : string
public function getConfig(): string
{
return $this->phpunit_config;
}
Expand All @@ -162,7 +167,7 @@ public function getConfig() : string
* @param string $config PhpUnit configuration file
*/
#[\Override]
public function setConfig(string $config) : self
public function setConfig(string $config): self
{
$this->phpunit_config = $config;
return $this;
Expand All @@ -173,7 +178,7 @@ public function setConfig(string $config) : self
* @param bool|boolean|null $colors Flag
*/
#[\Override]
public function useColors(bool $colors = null) : self|bool
public function useColors(bool $colors = null): self|bool
{
if (is_null($colors)) {
return $this->use_colors;
Expand Down
15 changes: 8 additions & 7 deletions src/SymfonyConsoleWrapper.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<?php

/**
* This file is part of tomkyle/find-run-test
*/

namespace tomkyle\FindRunTest;

use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Process\Process;

class SymfonyConsoleWrapper
{
public function __construct(protected TestRunnerInterface $testRunner) {}

class SymfonyConsoleWrapper {

public function __construct(protected TestRunnerInterface $testRunner)
public function __invoke(InputInterface $input, OutputInterface $output): int
{

}

public function __invoke(InputInterface $input, OutputInterface $output) : int {

$config = $input->getOption('config');
if ($config) {
$this->testRunner->setConfig($config);
Expand Down
8 changes: 6 additions & 2 deletions src/TestRunnerInterface.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php

/**
* This file is part of tomkyle/find-run-test
*/

namespace tomkyle\FindRunTest;

interface TestRunnerInterface
{
public function __invoke(string $src_file) : int;
public function __invoke(string $src_file): int;

public function runTest(string $unit_test) : self;
public function runTest(string $unit_test): self;
}
11 changes: 7 additions & 4 deletions tests/Unit/PhpUnitRunnerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/**
* This file is part of tomkyle/find-run-test
*/

namespace tests\Unit;

use PHPUnit\Framework\Attributes\DataProvider;
Expand Down Expand Up @@ -85,7 +89,7 @@ public function testExceptionOnProcessFailureWhenInvoked(): void

// Mock a changed source file and the matching test file
$src_mock = tempnam($this->temporaryDirectory->path(), 'file');
$test_mock = $src_mock.'Test.php';
$test_mock = $src_mock . 'Test.php';
copy($src_mock, $test_mock);

$phpUnitRunner->__invoke($src_mock);
Expand All @@ -108,14 +112,14 @@ public function testExceptionOnProcessFailureWithRunTestMethod(): void

// Mock a changed source file and the matching test file
$src_mock = tempnam($this->temporaryDirectory->path(), 'file');
$test_mock = $src_mock.'Test.php';
$test_mock = $src_mock . 'Test.php';
copy($src_mock, $test_mock);

$phpUnitRunner->runTest($test_mock);
}


public function testUseColorsInterceptor() : void
public function testUseColorsInterceptor(): void
{
$phpUnitRunner = new PhpUnitRunner();
$phpUnitRunner->useColors(true);
Expand All @@ -126,4 +130,3 @@ public function testUseColorsInterceptor() : void
}

}

6 changes: 1 addition & 5 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<?php

/**
* PHP Slim4 Web App Boilerplate (https://github.com/tomkyle/webapp-boilerplate)
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
* This file is part of tomkyle/find-run-test
*/

$root_path = dirname(__DIR__);
$autoloader = $root_path . '/vendor/autoload.php';
if (!is_readable($autoloader)) {
die(sprintf("\nMissing Composer's Autoloader '%s'; Install Composer dependencies first.\n\n", $autoloader));
}

0 comments on commit 6d618f5

Please sign in to comment.