Skip to content

Commit

Permalink
Switched to Drupal coding standards. (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk authored Jan 7, 2025
1 parent cca66ff commit a0ef050
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 349 deletions.
12 changes: 9 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ root = true
[*]
end_of_line = LF
indent_style = space
indent_size = 4
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.php]
indent_size = 2

[*.{json,lock}]
indent_size = 4

[*.feature]
[*.{yml,yaml}]
indent_size = 2

[*.{yml,yaml}]
[*.{sh,bash,bats}]
indent_size = 2

[*.xml]
indent_size = 4
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"phpunit/phpunit": "^10.0",
"rector/rector": "^2",
"squizlabs/php_codesniffer": "^3",
"symfony/process": "^6 || ^7.0"
"symfony/process": "^6 || ^7.0",
"drupal/coder": "^8.3"
},
"autoload": {
"psr-0": {
Expand Down
48 changes: 25 additions & 23 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
<?xml version="1.0"?>
<ruleset name="behat-format-progress-fail">
<description>The coding standard for behat-format-progress-fail.</description>
<ruleset name="custom">
<description>Custom PHPCS standard.</description>

<rule ref="Symfony" />
<!-- Using Drupal coding standard as a base-fix. -->
<rule ref="Drupal"/>
<!-- Checks that the strict_types has been declared. -->
<rule ref="Generic.PHP.RequireStrictTypes" />

<file>src/</file>
<file>tests/</file>
<!-- Show sniff codes in all reports -->
<arg value="s"/>
<!-- Show progress of the run. -->
<arg value="p"/>
<arg name="colors"/>

<exclude-pattern>./tests/behat/features/fixtures/*</exclude-pattern>
<file>src</file>
<file>tests/behat</file>

<rule ref="PSR2.Methods.FunctionCallSignature.MultipleArguments">
<exclude-pattern>.*</exclude-pattern>
</rule>

<!--Exclude namespacing for test features.-->
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
<exclude-pattern>./tests/*</exclude-pattern>
</rule>
<rule ref="Symfony.NamingConventions.ValidClassName.InvalidInterfaceName">
<exclude-pattern>.*context.*</exclude-pattern>
</rule>
<rule ref="Symfony.Commenting.FunctionComment.MissingParamTag">
<exclude-pattern>*</exclude-pattern>
</rule>
<rule ref="Symfony.Commenting.Annotations.Invalid">
<exclude-pattern>.*context.*</exclude-pattern>
</rule>
<!-- Allow long array lines in tests. -->
<rule ref="Drupal.Arrays.Array.LongLineDeclaration">
<exclude-pattern>*.Test\.php</exclude-pattern>
<exclude-pattern>*.TestCase\.php</exclude-pattern>
<exclude-pattern>*.test</exclude-pattern>
</rule>

<!-- Allow missing function names in tests. -->
<rule ref="Drupal.Commenting.FunctionComment.Missing">
<exclude-pattern>*.Test\.php</exclude-pattern>
<exclude-pattern>*.TestCase\.php</exclude-pattern>
<exclude-pattern>*.test</exclude-pattern>
</rule>
</ruleset>
287 changes: 140 additions & 147 deletions src/DrevOps/BehatFormatProgressFail/FormatExtension.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php

/**
* @file
* Behat progress format extension.
*/
declare(strict_types=1);

namespace DrevOps\BehatFormatProgressFail;

Expand All @@ -28,148 +25,144 @@

/**
* Class FormatExtension.
*
* Behat output formatter to show progress as TAP and failures inline.
*/
class FormatExtension implements ExtensionInterface
{

/**
* Available services
*/
const ROOT_LISTENER_ID = 'output.node.listener.progress_fail';

const RESULT_TO_STRING_CONVERTER_ID = 'output.node.printer.result_to_string';

/**
* Extension configuration ID.
*/
const MOD_ID = 'progress_fail';

/**
* Default base path.
*/
const BASE_PATH = '%paths.base%';

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container): void
{
}

/**
* {@inheritdoc}
*/
public function getConfigKey()
{
return self::MOD_ID;
}

/**
* {@inheritdoc}
*/
public function initialize(ExtensionManager $extensionManager): void
{
}

/**
* {@inheritdoc}
*/
public function configure(ArrayNodeDefinition $builder): void
{
$builder->children()->scalarNode('name')->defaultValue(self::MOD_ID);
$builder->children()->scalarNode('base_path')->defaultValue(self::BASE_PATH);
}

/**
* {@inheritdoc}
*/
public function load(ContainerBuilder $container, array $config): void
{
$name = is_string($config['name']) ? $config['name'] : self::MOD_ID;

$definition = new Definition(
StepListener::class, [
new Reference('output.printer.'.$name),
]
);
$container->setDefinition(self::ROOT_LISTENER_ID, $definition);

$definition = new Definition(
PrinterProgressFail::class, [
new Reference(self::RESULT_TO_STRING_CONVERTER_ID),
$config['base_path'],
]
);
$container->setDefinition(
'output.printer.'.$name, $definition
);

$definition = new Definition(
NodeEventListeningFormatter::class, [
$config['name'],
'Prints one character per step and fail view pretty.',
['timer' => true],
$this->createOutputPrinterDefinition(),
new Definition(
ChainEventListener::class, [
[
new Reference(self::ROOT_LISTENER_ID),
new Definition(
StatisticsListener::class, [
new Reference('output.progress.statistics'),
new Reference(
'output.node.printer.progress.statistics'
),
]
),
new Definition(
ScenarioStatsListener::class, [
new Reference('output.progress.statistics'),
]
),
new Definition(
StepStatsListener::class, [
new Reference('output.progress.statistics'),
new Reference(
ExceptionExtension::PRESENTER_ID
),
]
),
new Definition(
HookStatsListener::class, [
new Reference('output.progress.statistics'),
new Reference(
ExceptionExtension::PRESENTER_ID
),
]
),
],
]
),
]
);
$definition->addTag(
OutputExtension::FORMATTER_TAG, ['priority' => 100]
);
$container->setDefinition(
OutputExtension::FORMATTER_TAG.'.'.$name, $definition
);
}

/**
* Creates output printer definition.
*
* @return Definition
* The output printer definition.
*/
protected function createOutputPrinterDefinition(): Definition
{
return new Definition(
StreamOutputPrinter::class, [
new Definition(
ConsoleOutputFactory::class
),
]
);
}
class FormatExtension implements ExtensionInterface {

/**
* Available services.
*/
const ROOT_LISTENER_ID = 'output.node.listener.progress_fail';

const RESULT_TO_STRING_CONVERTER_ID = 'output.node.printer.result_to_string';

/**
* Extension configuration ID.
*/
const MOD_ID = 'progress_fail';

/**
* Default base path.
*/
const BASE_PATH = '%paths.base%';

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container): void {
}

/**
* {@inheritdoc}
*/
public function getConfigKey() {
return self::MOD_ID;
}

/**
* {@inheritdoc}
*/
public function initialize(ExtensionManager $extensionManager): void {
}

/**
* {@inheritdoc}
*/
public function configure(ArrayNodeDefinition $builder): void {
$builder->children()->scalarNode('name')->defaultValue(self::MOD_ID);
$builder->children()->scalarNode('base_path')->defaultValue(self::BASE_PATH);
}

/**
* {@inheritdoc}
*/
public function load(ContainerBuilder $container, array $config): void {
$name = is_string($config['name']) ? $config['name'] : self::MOD_ID;

$definition = new Definition(
StepListener::class, [
new Reference('output.printer.' . $name),
]
);
$container->setDefinition(self::ROOT_LISTENER_ID, $definition);

$definition = new Definition(
PrinterProgressFail::class, [
new Reference(self::RESULT_TO_STRING_CONVERTER_ID),
$config['base_path'],
]
);
$container->setDefinition(
'output.printer.' . $name, $definition
);

$definition = new Definition(
NodeEventListeningFormatter::class, [
$config['name'],
'Prints one character per step and fail view pretty.',
['timer' => TRUE],
$this->createOutputPrinterDefinition(),
new Definition(
ChainEventListener::class, [
[
new Reference(self::ROOT_LISTENER_ID),
new Definition(
StatisticsListener::class, [
new Reference('output.progress.statistics'),
new Reference(
'output.node.printer.progress.statistics'
),
]
),
new Definition(
ScenarioStatsListener::class, [
new Reference('output.progress.statistics'),
]
),
new Definition(
StepStatsListener::class, [
new Reference('output.progress.statistics'),
new Reference(
ExceptionExtension::PRESENTER_ID
),
]
),
new Definition(
HookStatsListener::class, [
new Reference('output.progress.statistics'),
new Reference(
ExceptionExtension::PRESENTER_ID
),
]
),
],
]
),
]
);
$definition->addTag(
OutputExtension::FORMATTER_TAG, ['priority' => 100]
);
$container->setDefinition(
OutputExtension::FORMATTER_TAG . '.' . $name, $definition
);
}

/**
* Creates output printer definition.
*
* @return \Symfony\Component\DependencyInjection\Definition
* The output printer definition.
*/
protected function createOutputPrinterDefinition(): Definition {
return new Definition(
StreamOutputPrinter::class, [
new Definition(
ConsoleOutputFactory::class
),
]
);
}

}
Loading

0 comments on commit a0ef050

Please sign in to comment.