Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ on:

jobs:
quality:
runs-on: 'ubuntu-20.04'
runs-on: 'ubuntu-22.04'
steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.4'
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
Expand All @@ -23,41 +23,29 @@ jobs:
key: ${{ runner.os }}-quality-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-quality-php
- name: Require symfony quality tools
run: |
composer require --dev --no-update \
phpstan/phpstan \
squizlabs/php_codesniffer \
phpstan/phpstan-phpunit \
doctrine/coding-standard:^8.0 \
phpstan/phpstan-symfony
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: Run phpcs
run: ./vendor/bin/phpcs
run: composer phpcs
- name: Run phpstan
run: ./vendor/bin/phpstan analyse
run: composer phpstan

test:
strategy:
matrix:
os: ['ubuntu-20.04']
version: [ '7.4', '8.0', '8.1', '8.2']
os: ['ubuntu-22.04']
version: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
include:
- os: 'ubuntu-20.04'
version: '7.2'
- os: 'ubuntu-20.04'
version: '7.3'
- os: 'ubuntu-20.04'
- os: 'ubuntu-22.04'
version: '7.4'
symfony: '^4.0'
- os: 'ubuntu-20.04'
- os: 'ubuntu-22.04'
version: '7.4'
symfony: '^5.0'
- os: 'ubuntu-20.04'
- os: 'ubuntu-22.04'
version: '8.1'
symfony: '^6.0'
- os: 'ubuntu-20.04'
- os: 'ubuntu-22.04'
version: '8.2'
symfony: '^7.0'
runs-on: ${{ matrix.os }}
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ Use `--parallel` or `-l` option for start in parallel scenario mode.
3/3 [============================] 100% 12 secs/12 secs
```

## Test with the oldest supported PHP version

```bash
composer update --prefer-lowest --prefer-stable
docker run --rm -ti -v $(pwd):/app -w /app -u $(id -u):$(id -g) php:7.4-cli bash -c "vendor/bin/phpunit; vendor/bin/behat"
```

## Tools and Coding standards

The extension uses the following coding standards and quality tools:
Expand Down Expand Up @@ -215,4 +222,4 @@ classes for behat tests in directory [tests/Behat](tests/Behat).
[PSR-12]: <https://www.php-fig.org/psr/psr-12/>
[Behat]: <https://behat.org/>
[SymfonyExtension]: <https://github.com/FriendsOfBehat/SymfonyExtension>
[MinkExtension]: <https://github.com/FriendsOfBehat/MinkExtension>
[MinkExtension]: <https://github.com/FriendsOfBehat/MinkExtension>
29 changes: 19 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@
}
],
"require": {
"php": ">=7.2",
"behat/behat": "^3.6",
"symfony/process": "^2.7.52 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0",
"symfony/console": "^2.7.52 || ^2.8.33 || ^3.3.15 || ^3.4.3 || ^4.0 || ^5.0 || ^6.0 || ^7.0",
"symfony/serializer": "^2.7.52 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^2.7.52 || ^3.0 || ^4.0 || ^4.1.12 || ^5.0 || ^6.0 || ^7.0",
"symfony/event-dispatcher": "^2.7.52 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0",
"symfony/yaml": "^2.7.52 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0",
"symfony/expression-language": "^2.7.52 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"
"php": ">=7.4",
"behat/behat": "^3.9",
"symfony/process": "^4.0 || ^5.0 || ^6.0 || ^7.0",
"symfony/console": "^4.0 || ^5.0 || ^6.0 || ^7.0",
"symfony/serializer": "^4.0 || ^5.0 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^4.0 || ^4.1.12 || ^5.0 || ^6.0 || ^7.0",
"symfony/event-dispatcher": "^4.0 || ^5.0 || ^6.0 || ^7.0",
"symfony/yaml": "^4.0 || ^5.0 || ^6.0 || ^7.0",
"symfony/expression-language": "^4.0 || ^5.0 || ^6.0 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^8.5 || ^9.0",
"ext-json": "*",
"dg/bypass-finals": "^1.1 || ^1.2"
"dg/bypass-finals": "^1.1 || ^1.2",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-phpunit": "^2.0",
"squizlabs/php_codesniffer": "^3.13",
"doctrine/coding-standard": "^9.0"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -63,5 +67,10 @@
"@phpunit",
"@behat"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
33 changes: 0 additions & 33 deletions phpmd.xml.dist

This file was deleted.

7 changes: 2 additions & 5 deletions src/Cli/ParallelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ private function addEventListeners(): void
$this->eventDispatcher->addListener(ParallelTestsAborted::ABORTED, [$this, 'parallelTestsAborted']);
}

/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
private function setupTasksWithProgressBar(): void
{
$tasks = $this->createTasks();
Expand Down Expand Up @@ -195,11 +192,11 @@ private function createTasks()
{
$paths = $this->input->hasArgument('paths') ? $this->input->getArgument('paths') : null;

if (is_null($paths) || is_string($paths)) {
if ($paths === null || is_string($paths)) {
return $this->taskFactory->createTasks($this->input, $paths);
}

if (!is_array($paths)) {
if (! is_array($paths)) {
throw new UnexpectedValue('Expected array, string or null');
}

Expand Down
5 changes: 4 additions & 1 deletion src/Event/EventDispatcherDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public function __construct(TestworkEventDispatcher $eventDispatcher)
*/
public function dispatch($event, $eventName = null)
{
if (TestworkEventDispatcher::DISPATCHER_VERSION === 2) {
$dispatcherVersion = defined(TestworkEventDispatcher::class . '::DISPATCHER_VERSION')
? constant(TestworkEventDispatcher::class . '::DISPATCHER_VERSION')
: 1;
if ((int) $dispatcherVersion === 2) {
return $this->eventDispatcher->dispatch($event, $eventName);
}

Expand Down
23 changes: 3 additions & 20 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use DMarynicz\BehatParallelExtension\Exception\UnexpectedValue;
use DMarynicz\BehatParallelExtension\Worker\Poll;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -47,10 +46,7 @@ public function load(ContainerBuilder $container, array $config): void
$loader->load('services.yaml');

$pollDefinition = $container->findDefinition(Poll::class);
$pollDefinition->setArgument(
'$environments',
$config['environments']
);
$pollDefinition->setArgument('$environments', $config['environments']);
}

public function process(ContainerBuilder $container): void
Expand All @@ -64,7 +60,6 @@ private function addEventsNode()
{
$node = $this->getNewArrayNode('events');

// @phpstan-ignore-next-line
$node
->prototype('array')
->children()
Expand Down Expand Up @@ -95,7 +90,7 @@ private function addEventsNode()
}

/**
* @return ArrayNodeDefinition|NodeDefinition
* @return ArrayNodeDefinition
*/
private function addEnvironmentsNode()
{
Expand Down Expand Up @@ -145,22 +140,10 @@ private function addEnvironmentsNode()
*/
private function getNewArrayNode($name): ArrayNodeDefinition
{
if (method_exists(TreeBuilder::class, 'root')) {
// @phpstan-ignore-next-line
$treeBuilder = new TreeBuilder();

// @phpstan-ignore-next-line
$node = $treeBuilder->root($name);
if (! $node instanceof ArrayNodeDefinition) {
throw new UnexpectedValue('expected ArrayNodeDefinition');
}

return $node;
}

$treeBuilder = new TreeBuilder($name);
$node = $treeBuilder->getRootNode();

// @phpstan-ignore-next-line
if (! $node instanceof ArrayNodeDefinition) {
throw new UnexpectedValue('expected ArrayNodeDefinition');
}
Expand Down
13 changes: 7 additions & 6 deletions src/Task/SpecificationsFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ class SpecificationsFinder implements TestworkSpecificationsFinder
/** @var SuiteRepository */
private $suiteRepository;

/** @var TestworkSpecificationFinder */
/** @var TestworkSpecificationFinder<mixed> */
private $specificationFinder;

/**
* @param TestworkSpecificationFinder<mixed> $specificationFinder
*/
public function __construct(
SuiteRepository $suiteRepository,
TestworkSpecificationFinder $specificationFinder
Expand All @@ -27,9 +30,7 @@ public function __construct(
/**
* @param string|null $path
*
* @return GroupedSpecificationIterator[]
*
* @SuppressWarnings(PHPMD.StaticAccess)
* @return array<string, GroupedSpecificationIterator<mixed>>
*/
public function findGroupedSpecifications($path)
{
Expand All @@ -43,7 +44,7 @@ public function findGroupedSpecifications($path)
*
* @param string|null $path
*
* @return SpecificationIterator[]
* @return list<SpecificationIterator<mixed>>
*/
private function findSpecifications($path)
{
Expand All @@ -56,7 +57,7 @@ private function findSpecifications($path)
* @param Suite[] $suites
* @param string|null $locator
*
* @return SpecificationIterator[]
* @return list<SpecificationIterator<mixed>>
*/
private function findSuitesSpecifications($suites, $locator)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Task/TestworkSpecificationsFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface TestworkSpecificationsFinder
/**
* @param string|null $path
*
* @return GroupedSpecificationIterator[]
* @return array<string, GroupedSpecificationIterator<mixed>>
*/
public function findGroupedSpecifications($path);
}
29 changes: 8 additions & 21 deletions src/Worker/TaskWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use DMarynicz\BehatParallelExtension\Event\WorkerCreated;
use DMarynicz\BehatParallelExtension\Event\WorkerDestroyed;
use DMarynicz\BehatParallelExtension\Exception\Runtime;
use DMarynicz\BehatParallelExtension\Exception\UnexpectedValue;
use DMarynicz\BehatParallelExtension\Task\Queue;
use DMarynicz\BehatParallelExtension\Task\TaskEntity;
use DMarynicz\BehatParallelExtension\Util\ProcessFactory;
Expand All @@ -17,7 +16,7 @@

class TaskWorker implements Worker
{
/** @var string[] */
/** @var array<string, string> */
private $environment;

/** @var Queue */
Expand All @@ -42,8 +41,8 @@ class TaskWorker implements Worker
private $processFactory;

/**
* @param string[] $environment
* @param int $workerId
* @param array<string, string> $environment
* @param int $workerId
*/
public function __construct(
Queue $queue,
Expand All @@ -55,11 +54,7 @@ public function __construct(
$this->environment = $environment;
$this->queue = $queue;
$this->eventDispatcher = $eventDispatcher;
if (! is_int($workerId)) {
throw new UnexpectedValue('Expected int');
}

$this->workerId = $workerId;
$this->workerId = $workerId;
$this->eventDispatcher->dispatch(new WorkerCreated($this), WorkerCreated::WORKER_CREATED);
if (! $processFactory instanceof ProcessFactory) {
$processFactory = new SymfonyProcessFactory();
Expand Down Expand Up @@ -120,27 +115,19 @@ public function stop(): void
}

/**
* @return string[]
* @return array<string, string>
*/
public function getEnvironment()
public function getEnvironment(): array
{
return $this->environment;
}

/**
* @param string[] $env
*
* @return Worker
* @param array<string, string> $env
*/
public function setEnvironment($env)
public function setEnvironment(array $env): void
{
if (! is_array($env)) {
throw new UnexpectedValue('Expected array');
}

$this->environment = $env;

return $this;
}

public function getWorkerId(): int
Expand Down
Loading