Skip to content

Commit

Permalink
Added major PHP-CS-Fixer rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk committed Jul 4, 2017
1 parent e546fc5 commit 6d2202e
Show file tree
Hide file tree
Showing 74 changed files with 1,131 additions and 852 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ composer.lock
test/fixtures/small-tests/*Test.php
test/fixtures/generated-tests
nbproject
.php_cs
.php_cs.cache
44 changes: 44 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP70Migration' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_unsets' => true,
'concat_space' => ['spacing' => 'one'],
'heredoc_to_nowdoc' => true,
'list_syntax' => ['syntax' => 'long'],
'method_argument_space' => true,
'no_extra_consecutive_blank_lines' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'],
'no_php4_constructor' => true,
'no_short_echo_tag' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => array(
'use_trait',
'constant',
'property',
'construct',
'destruct',
'magic',
'phpunit',
'method',
),
'ordered_imports' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'semicolon_after_instruction' => true,
'simplified_null_return' => true,
'strict_comparison' => true,
'strict_param' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('test/fixtures')
->in(__DIR__)
)
;
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ env:
- PHPUNIT_VERSION='*@dev'

before_script:
- composer self-update
- composer require --no-update phpunit/phpunit=$PHPUNIT_VERSION
- composer install --prefer-dist

script:
- vendor/bin/phpunit --coverage-clover=coverage.clover
- if [[ $TRAVIS_PHP_VERSION == "7.0" && $PHPUNIT_VERSION == '6.*@stable' ]]; then vendor/bin/php-cs-fixer fix --diff --dry-run --verbose ; fi

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,7 @@ You can run all tests at once by running phpunit from the project directory.
ParaTest can run its own test suite by running it from the `bin` directory.
`bin/paratest`

Before creating a Pull Request be sure to run `vendor/bin/php-cs-fixer fix` and
commit the eventual changes.

For an example of ParaTest out in the wild check out the [example](https://github.com/brianium/paratest-selenium).
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@
"psr-4": {
"ParaTest\\": "test/unit/"
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.3"
}
}
15 changes: 9 additions & 6 deletions src/Console/Commands/ParaTestCommand.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php namespace ParaTest\Console\Commands;
<?php

namespace ParaTest\Console\Commands;

use Composer\Semver\Comparator;
use ParaTest\Console\Testers\Tester;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use ParaTest\Console\Testers\Tester;

class ParaTestCommand extends Command
{
Expand All @@ -30,7 +32,7 @@ public static function isWhitelistSupported()
}

/**
* Ubiquitous configuration options for ParaTest
* Ubiquitous configuration options for ParaTest.
*/
protected function configure()
{
Expand All @@ -51,10 +53,11 @@ protected function configure()
}

/**
* Executes the specified tester
* Executes the specified tester.
*
* @param InputInterface $input
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|mixed|null
*/
public function execute(InputInterface $input, OutputInterface $output)
Expand Down
18 changes: 11 additions & 7 deletions src/Console/ParaTestApplication.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php namespace ParaTest\Console;
<?php

namespace ParaTest\Console;

use ParaTest\Console\Commands\ParaTestCommand;
use ParaTest\Console\Testers\PHPUnit;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use ParaTest\Console\Commands\ParaTestCommand;
use ParaTest\Console\Testers\PHPUnit;

class ParaTestApplication extends Application
{
Expand All @@ -19,31 +21,33 @@ public function __construct()
}

/**
* Instantiates the specific Tester and runs it via the ParaTestCommand
* Instantiates the specific Tester and runs it via the ParaTestCommand.
*
* @todo for now paratest will only run the phpunit command
*/
public function doRun(InputInterface $input, OutputInterface $output)
{
$this->add(new ParaTestCommand(new PHPUnit()));

return parent::doRun($input, $output);
}

/**
* The default InputDefinition for the application. Leave it to specific
* Tester objects for specifying further definitions
* Tester objects for specifying further definitions.
*
* @return InputDefinition
*/
public function getDefinition()
{
return new InputDefinition([
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.')
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
]);
}

/**
* @param InputInterface $input
*
* @return string
*/
public function getCommandName(InputInterface $input)
Expand Down
54 changes: 33 additions & 21 deletions src/Console/Testers/PHPUnit.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?php

namespace ParaTest\Console\Testers;

use ParaTest\Runners\PHPUnit\Configuration;
use ParaTest\Runners\PHPUnit\Runner;
use ParaTest\Runners\PHPUnit\WrapperRunner;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use ParaTest\Runners\PHPUnit\Configuration;
use ParaTest\Runners\PHPUnit\Runner;
use ParaTest\Runners\PHPUnit\WrapperRunner;

/**
* Class PHPUnit
* Class PHPUnit.
*
* Creates the interface for PHPUnit testing
*
* @package ParaTest\Console\Testers
*/
class PHPUnit extends Tester
{
Expand All @@ -26,10 +25,9 @@ class PHPUnit extends Tester

/**
* Configures the ParaTestCommand with PHPUnit specific
* definitions
* definitions.
*
* @param Command $command
* @return void
*/
public function configure(Command $command)
{
Expand All @@ -51,10 +49,11 @@ public function configure(Command $command)

/**
* Executes the PHPUnit Runner. Will Display help if no config and no path
* supplied
* supplied.
*
* @param InputInterface $input
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|mixed
*/
public function execute(InputInterface $input, OutputInterface $output)
Expand All @@ -81,37 +80,42 @@ public function execute(InputInterface $input, OutputInterface $output)
}

$runner->run();

return $runner->getExitCode();
}

/**
* Returns whether or not a test path has been supplied
* via option or regular input
* via option or regular input.
*
* @param InputInterface $input
*
* @return bool
*/
protected function hasPath(InputInterface $input)
{
$argument = $input->getArgument('path');
$option = $input->getOption('path');

return $argument || $option;
}

/**
* Is there a PHPUnit xml configuration present
* Is there a PHPUnit xml configuration present.
*
* @param InputInterface $input
*
* @return bool
*/
protected function hasConfig(InputInterface $input)
{
return (false !== $this->getConfig($input));
return false !== $this->getConfig($input);
}

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
* @return \ParaTest\Runners\PHPUnit\Configuration|boolean
*
* @return \ParaTest\Runners\PHPUnit\Configuration|bool
*/
protected function getConfig(InputInterface $input)
{
Expand All @@ -132,8 +136,10 @@ protected function getConfig(InputInterface $input)

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
* @return array
*
* @throws \RuntimeException
*
* @return array
*/
public function getRunnerOptions(InputInterface $input)
{
Expand All @@ -158,15 +164,16 @@ public function getRunnerOptions(InputInterface $input)
* then an exception will be raised.
*
* @param $file
*
* @throws \RuntimeException
*/
public function requireBootstrap($file)
{
if (! $file) {
if (!$file) {
return;
}

if (! file_exists($file)) {
if (!file_exists($file)) {
$message = sprintf('Bootstrap specified but could not be found (%s)', $file);
throw new \RuntimeException($message);
}
Expand All @@ -178,6 +185,8 @@ public function requireBootstrap($file)
* This function limits the scope of a required file
* so that variables defined in it do not break
* this object's configuration.
*
* @param mixed $file
*/
protected function scopedRequire($file)
{
Expand All @@ -190,20 +199,23 @@ protected function scopedRequire($file)
* Return whether or not code coverage information should be collected.
*
* @param $options
*
* @return bool
*/
protected function hasCoverage($options)
{
$isFileFormat = isset($options['coverage-html']) || isset($options['coverage-clover']);
$isPHP = isset($options['coverage-php']);
return $isFileFormat && ! $isPHP;

return $isFileFormat && !$isPHP;
}

/**
* Fetch the path to the bootstrap file.
*
* @param InputInterface $input
* @param array $options
* @param array $options
*
* @return string
*/
protected function getBootstrapFile(InputInterface $input, array $options)
Expand All @@ -212,7 +224,7 @@ protected function getBootstrapFile(InputInterface $input, array $options)
return $options['bootstrap'];
}

if (! $this->hasConfig($input)) {
if (!$this->hasConfig($input)) {
return '';
}

Expand Down
Loading

0 comments on commit 6d2202e

Please sign in to comment.