Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.5 automated build #684

Closed
wants to merge 14 commits into from
Closed
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
54 changes: 54 additions & 0 deletions .github/workflows/build-35.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Automated v3.5 build

on:
workflow_dispatch: # yamllint disable-line rule:truthy

jobs:
build_v3_5:
name: v3.5 Build
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
coverage: "none"
- name: Validate Composer configuration
run: composer validate --no-interaction --strict
- name: Install dependencies
uses: ramsey/composer-install@v2
- name: Check PSR-4 mapping"
run: composer dump-autoload --no-interaction --optimize --strict-psr
- name: Require rector
run: composer require --dev rector/rector
- name: Get changed files
id: changed-files
uses: yumemi-inc/changed-files@v3
with:
separator: " "
patterns: |
src/**/*.php
includes/**/*.php
tests/**/*.php
- name: Build v3.5
run: |
vendor/bin/rector process --config=config/rector-35.php -- ${{ steps.changed-files.outputs.files }}
- name: Create Pull Request on v3.5
run: |
git reset HEAD
git status
git add 'src/*.php'
git add 'includes/*.php'
git add 'tests/*.php'
gh pr create \
--assignee lucatume \
--base v3.5 \
--draft \
--title "v3.5 automated build" \
--body "v3.5 automated build changes" \
--label "auto-build" \
--label "v3.5"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

### Fixed

- Improve router script to speed up localhost server.

## [4.0.16] 2023-12-07;

### Changed
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
"phpstan/phpstan": "*",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-symfony": "^1.3",
"squizlabs/php_codesniffer": "^3.7",
"rector/rector": "^0.18.5"
"squizlabs/php_codesniffer": "^3.7"
},
"autoload": {
"psr-4": {
Expand Down
60 changes: 42 additions & 18 deletions src/Adapters/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
namespace lucatume\WPBrowser\Adapters\Symfony\Component\Process;

use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Pipes\PipesInterface;
use Symfony\Component\Process\Process as SymfonyProcess;

class Process extends SymfonyProcess
{
/**
* @var array<string,mixed>
* @var bool
*/
private $options = [];
private $createNewConsole = false;

/**
* @param string[] $command
* @param array<string,mixed>|null $env
Expand Down Expand Up @@ -50,28 +52,50 @@ public function getStartTime(): float
return $startTime;
}

/**
* @param string $name
* @param array<mixed> $arguments
* @return void
*/
public function __call(string $name, array $arguments)
/** @noinspection MagicMethodsValidityInspection */
public function __destruct()
{
if ($name === 'setOptions') {
$this->options = $arguments[0] ?? [];
if ($this->createNewConsole) {
$processPipesProperty = new \ReflectionProperty(SymfonyProcess::class, 'processPipes');
$processPipesProperty->setAccessible(true);
/** @var PipesInterface $processPipes */
$processPipes = $processPipesProperty->getValue($this);
$processPipes->close();

return;
}
return;

$this->stop(0);
}

public function __destruct()
public function createNewConsole(): void
{
if (($this->options['create_new_console'] ?? false) || method_exists($this, 'setOptions')) {
parent::__destruct();
return;
$this->createNewConsole = true;

$optionsReflectionProperty = new \ReflectionProperty(SymfonyProcess::class, 'options');
$optionsReflectionProperty->setAccessible(true);
$options = $optionsReflectionProperty->getValue($this);
$options = is_array($options) ? $options : [];
$options['create_new_console'] = true;
$options['bypass_shell'] = true;
$optionsReflectionProperty->setValue($this, $options);
}

/**
* @param array<mixed> $arguments
*/
public static function __callStatic(string $name, array $arguments):mixed
{
if ($name === 'fromShellCommandline') {
$command = array_shift($arguments);
$process = new self([], ...$arguments); // @phpstan-ignore-line
$processCommandLineProperty = new \ReflectionProperty(SymfonyProcess::class, 'commandline');
$processCommandLineProperty->setAccessible(true);
$processCommandLineProperty->setValue($process, $command);

return $process;
}

$closeMethodReflection = new \ReflectionMethod(SymfonyProcess::class, 'close');
$closeMethodReflection->setAccessible(true);
$closeMethodReflection->invoke($this);
return null;
}
}
2 changes: 1 addition & 1 deletion src/ManagedProcess/ChromeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function doStart(): void
{
$command = [$this->chromeDriverBinary, '--port=' . $this->port, ...$this->arguments];
$process = new Process($command);
$process->setOptions(['create_new_console' => true]);
$process->createNewConsole();
$process->start();
$this->confirmStart($process);
$this->pid = $process->getPid();
Expand Down
2 changes: 1 addition & 1 deletion src/ManagedProcess/PhpBuiltInServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function doStart(): void
$this->docRoot,
$this->env
);
$process->setOptions(['create_new_console' => true]);
$process->createNewConsole();
$process->start();
if (!$this->confirmServerRunningOnPort($process)) {
$error = new RuntimeException(
Expand Down
6 changes: 0 additions & 6 deletions tests/Issue/BlogArchiveCest.php

This file was deleted.

Loading
Loading