Skip to content

Commit

Permalink
PSR-2 compliance (Codeception#3105)
Browse files Browse the repository at this point in the history
* Add composer.lock to .gitignore

* Put direct link to coding standards description

* Fix spacing

* Fix code style for ext and symfony-shim

* Fix PSR2 compliance issues

* Fix PSR2 compliance issues

* Add generated test files to gitginore

* Fix PSR2 compliance issues in tests

* Get rid of long code lines in tests to comply PSR2

* Get rid of long code lines to comply PSR2

* Add code style rule set

* Fix wrong indentation

* Improve code style
  • Loading branch information
MAXakaWIZARD authored and DavertMik committed May 16, 2016
1 parent 3e0a451 commit 4e6cf28
Show file tree
Hide file tree
Showing 252 changed files with 2,143 additions and 5,112 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
.roboci
Dockerfile
composer.phar
composer.lock
vendor
package/codecept.phar
tests/support/_generated
tests/data/app/db
tests/data/sandbox
tests/_output/*
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ At Codeception we are glad to receive contributions and patches from the communi
Please check the guide for sending your contributions with Github at https://github.com/Codeception/Codeception/wiki/Git-workflow-for-Codeception-contributors

## Coding Standards
All contributions must follow the coding standards described at: https://github.com/Codeception/Codeception/wiki/Codeception-coding-style-standard
All contributions must follow [PSR-2](http://www.php-fig.org/psr/psr-2/) coding standard.

## Code
**Bugfixes should be sent to to current stable branch, which is the same as major version number.**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"facebook/webdriver": ">=1.0.1 <2.0",
"guzzlehttp/guzzle": ">=4.1.4 <7.0",
"guzzlehttp/psr7": "~1.0",
"symfony/finder": ">=2.5 <3.1",
"symfony/finder": ">=2.5 <3.1",
"symfony/console": ">=2.5 <3.1",
"symfony/event-dispatcher": ">=2.5 <3.1",
"symfony/yaml": ">=2.5 <3.1",
Expand Down
5 changes: 2 additions & 3 deletions ext/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
class Logger extends Extension
{
static $events = [
public static $events = [
Events::SUITE_BEFORE => 'beforeSuite',
Events::TEST_BEFORE => 'beforeTest',
Events::TEST_AFTER => 'afterTest',
Expand Down Expand Up @@ -120,5 +120,4 @@ public function beforeStep(StepEvent $e)
{
$this->logger->info((string) $e->getStep());
}

}
}
19 changes: 13 additions & 6 deletions ext/Recorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
* #### Configuration
*
* * `delete_successful` (default: true) - delete records for successfully passed tests (log only failed and errored)
* * `module` (default: WebDriver) - which module for screenshots to use. Module should implement `Codeception\Lib\Interfaces\ScreenshotSaver` interface. Currently only WebDriver or any its children can be used.
* * `module` (default: WebDriver) - which module for screenshots to use.
* Module should implement `Codeception\Lib\Interfaces\ScreenshotSaver` interface.
* Currently only WebDriver or any its children can be used.
*
* ``` yaml
* extensions:
Expand Down Expand Up @@ -207,7 +209,7 @@ class Recorder extends \Codeception\Extension
</div>
EOF;

static $events = [
public static $events = [
Events::SUITE_BEFORE => 'beforeSuite',
Events::SUITE_AFTER => 'afterSuite',
Events::TEST_BEFORE => 'before',
Expand Down Expand Up @@ -236,9 +238,15 @@ public function beforeSuite()
$this->seed = uniqid();
$this->webDriverModule = $this->getModule($this->config['module']);
if (!$this->webDriverModule instanceof ScreenshotSaver) {
throw new ExtensionException($this, 'You should pass module which implements Codeception\Lib\Interfaces\ScreenshotSaver interface');
throw new ExtensionException(
$this,
'You should pass module which implements Codeception\Lib\Interfaces\ScreenshotSaver interface'
);
}
$this->writeln(sprintf("⏺ <bold>Recording</bold> ⏺ step-by-step screenshots will be saved to <info>%s</info>", codecept_output_dir()));
$this->writeln(sprintf(
"⏺ <bold>Recording</bold> ⏺ step-by-step screenshots will be saved to <info>%s</info>",
codecept_output_dir()
));
$this->writeln("Directory Format: <debug>record_{$this->seed}_{testname}</debug> ----");
}

Expand Down Expand Up @@ -337,5 +345,4 @@ public function afterStep(StepEvent $e)
$this->stepNum++;
$this->slides[$filename] = $e->getStep();
}

}
}
5 changes: 2 additions & 3 deletions ext/RunFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
class RunFailed extends Extension
{
static $events = [
public static $events = [
Events::RESULT_PRINT_AFTER => 'saveFailed'
];

Expand Down Expand Up @@ -67,5 +67,4 @@ protected function localizePath($path)
}
return $path;
}

}
}
2 changes: 1 addition & 1 deletion ext/SimpleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function _initialize()
}

// we are listening for events
static $events = [
public static $events = [
Events::SUITE_BEFORE => 'beforeSuite',
Events::TEST_END => 'after',
Events::TEST_SUCCESS => 'success',
Expand Down
2 changes: 1 addition & 1 deletion package/stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

require_once 'phar://codecept.phar/codecept';

__HALT_COMPILER();
__halt_compiler();
14 changes: 14 additions & 0 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<ruleset name="Codeception">
<description>
Codeception coding standard. Inherits from PSR-2.
</description>

<rule ref="PSR2">
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/>
<exclude name="PSR1.Classes.ClassDeclaration.MultipleClasses"/>
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
</rule>
</ruleset>
5 changes: 4 additions & 1 deletion src/Codeception/Codecept.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ public function registerSubscribers()

public function run($suite, $test = null)
{
ini_set('memory_limit', isset($this->config['settings']['memory_limit']) ? $this->config['settings']['memory_limit'] : '1024M');
ini_set(
'memory_limit',
isset($this->config['settings']['memory_limit']) ? $this->config['settings']['memory_limit'] : '1024M'
);
$settings = Configuration::suiteSettings($suite, Configuration::config());

$selectedEnvironments = $this->options['env'];
Expand Down
13 changes: 9 additions & 4 deletions src/Codeception/Command/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
use Symfony\Component\Console\Question\Question;

/**
* Creates default config, tests directory and sample suites for current project. Use this command to start building a test suite.
* Creates default config, tests directory and sample suites for current project.
* Use this command to start building a test suite.
*
* By default it will create 3 suites **acceptance**, **functional**, and **unit**.
*
Expand All @@ -38,7 +39,12 @@ protected function configure()
$this->setDefinition(
[
new InputArgument('path', InputArgument::OPTIONAL, 'custom installation path', '.'),
new InputOption('namespace', 'ns', InputOption::VALUE_OPTIONAL, 'Namespace to add for actor classes and helpers'),
new InputOption(
'namespace',
'ns',
InputOption::VALUE_OPTIONAL,
'Namespace to add for actor classes and helpers'
),
new InputOption('actor', 'a', InputOption::VALUE_OPTIONAL, 'Custom actor instead of Tester'),
new InputOption('empty', 'e', InputOption::VALUE_NONE, 'Don\'t create standard suites')
]
Expand Down Expand Up @@ -176,7 +182,7 @@ class_name: $actor{$this->actorSuffix}

protected function createAcceptanceSuite($actor = 'Acceptance')
{
$suiteConfig = <<<EOF
$suiteConfig = <<<EOF
# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
Expand Down Expand Up @@ -244,5 +250,4 @@ protected function createDirs()
'/* Replace this file with actual dump of your database */'
);
}

}
4 changes: 2 additions & 2 deletions src/Codeception/Command/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ private function buildActor(array $settings)

$file = $this->buildPath(
Configuration::supportDir(),
$settings['class_name']) . $this->getClassName($settings['class_name']
);
$settings['class_name']
) . $this->getClassName($settings['class_name']);
$file .= '.php';
return $this->save($file, $content);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Command/Clean.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ protected function execute(InputInterface $input, OutputInterface $output)
FileSystem::doEmptyDir(Configuration::outputDir());
$output->writeln("Done");
}
}
}
2 changes: 1 addition & 1 deletion src/Codeception/Command/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ protected function executeCommands(InputInterface $input, OutputInterface $outpu
protected function listenToSignals()
{
if (function_exists('pcntl_signal')) {
declare(ticks = 1);
declare (ticks = 1);
pcntl_signal(SIGINT, SIG_IGN);
pcntl_signal(SIGTERM, SIG_IGN);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Command/GenerateCept.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function execute(InputInterface $input, OutputInterface $output)
$filename = $this->completeSuffix($filename, 'Cept');
$gen = new Cept($config);

$full_path = rtrim( $config['path'], DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $filename;
$full_path = rtrim($config['path'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $filename;
$res = $this->save($full_path, $gen->produce());
if (!$res) {
$output->writeln("<error>Test $filename already exists</error>");
Expand Down
6 changes: 2 additions & 4 deletions src/Codeception/Command/GenerateEnvironment.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
namespace Codeception\Command;

use Codeception\Configuration;
Expand Down Expand Up @@ -56,7 +56,5 @@ public function execute(InputInterface $input, OutputInterface $output)
} else {
$output->writeln("<error>File $relativePath/$file already exists</error>");
}

}

}
}
4 changes: 3 additions & 1 deletion src/Codeception/Command/GenerateGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function execute(InputInterface $input, OutputInterface $output)
}

$output->writeln("<info>Group extension was created in $filename</info>");
$output->writeln('To use this group extension, include it to "extensions" option of global Codeception config.');
$output->writeln(
'To use this group extension, include it to "extensions" option of global Codeception config.'
);
}
}
1 change: 0 additions & 1 deletion src/Codeception/Command/GeneratePhpUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;


/**
* Generates skeleton for unit test as in classical PHPUnit.
*
Expand Down
20 changes: 16 additions & 4 deletions src/Codeception/Command/GenerateScenarios.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,20 @@ protected function configure()
$this->setDefinition([
new InputArgument('suite', InputArgument::REQUIRED, 'suite from which texts should be generated'),
new InputOption('config', 'c', InputOption::VALUE_REQUIRED, 'Use specified config instead of default'),
new InputOption('path', 'p', InputOption::VALUE_REQUIRED, 'Use specified path as destination instead of default'),
new InputOption(
'path',
'p',
InputOption::VALUE_REQUIRED,
'Use specified path as destination instead of default'
),
new InputOption('single-file', '', InputOption::VALUE_NONE, 'Render all scenarios to only one file'),
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Specify output format: html or text (default)', 'text'),
new InputOption(
'format',
'f',
InputOption::VALUE_REQUIRED,
'Specify output format: html or text (default)',
'text'
),
new InputOption('config', 'c', InputOption::VALUE_REQUIRED, 'Use specified config instead of default'),
]);
parent::configure();
Expand All @@ -56,7 +67,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
@mkdir($path);

if (!is_writable($path)) {
throw new ConfigurationException("Path $path is not writable. Please, set valid permissions for folder to store scenarios.");
throw new ConfigurationException(
"Path $path is not writable. Please, set valid permissions for folder to store scenarios."
);
}

$path = $path . DIRECTORY_SEPARATOR . $suite;
Expand Down Expand Up @@ -138,5 +151,4 @@ private function underscore($name)
$name = preg_replace('/_Cest$/', '', $name);
return $name;
}

}
16 changes: 10 additions & 6 deletions src/Codeception/Command/GenerateSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;


/**
* Create new test suite. Requires suite name and actor name
*
Expand Down Expand Up @@ -70,7 +69,10 @@ public function execute(InputInterface $input, OutputInterface $output)
);
$actorName = $this->removeSuffix($actor, $config['actor']);

$file = $this->buildPath(\Codeception\Configuration::supportDir() . "Helper", "$actorName.php") . "$actorName.php";
$file = $this->buildPath(
\Codeception\Configuration::supportDir() . "Helper",
"$actorName.php"
) . "$actorName.php";

$gen = new Helper($actorName, $config['namespace']);
// generate helper
Expand All @@ -86,10 +88,12 @@ class_name: {{actor}}
- {{helper}}
EOF;

$this->save($dir . $suite . '.suite.yml', (new Template($conf))
->place('actor', $actorName . $config['actor'])
->place('helper', $gen->getHelperName())
->produce()
$this->save(
$dir . $suite . '.suite.yml',
(new Template($conf))
->place('actor', $actorName . $config['actor'])
->place('helper', $gen->getHelperName())
->produce()
);

$output->writeln("<info>Suite $suite generated</info>");
Expand Down
Loading

0 comments on commit 4e6cf28

Please sign in to comment.