Skip to content

Commit

Permalink
[#19] Update to scaffold 0.12.1 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
tannguyen04 authored Feb 19, 2024
1 parent 044d3a3 commit 046f04a
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 87 deletions.
9 changes: 3 additions & 6 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
## Checklist before requesting a review

- [ ] I have formatted the subject to include ticket number
as `[PRJ-123] Verb in past tense with dot at the end.`
- [ ] I have formatted the subject to include ticket number as `[#123] Verb in past tense with dot at the end.`
- [ ] I have added a link to the issue tracker
- [ ] I have provided information in `Changed` section about WHY something was
done if this was not a normal implementation
- [ ] I have provided information in `Changed` section about WHY something was done if this was not a normal implementation
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] I have run new and existing relevant tests locally with my changes, and
they passed
- [ ] I have run new and existing relevant tests locally with my changes, and they passed
- [ ] I have provided screenshots, where applicable

## Changed
Expand Down
8 changes: 5 additions & 3 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
name-template: '$NEXT_MINOR_VERSION'
tag-template: '$NEXT_MINOR_VERSION'
name-template: '$RESOLVED_VERSION'
tag-template: '$RESOLVED_VERSION'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
version-resolver:
default: minor
template: |
## What's new since $PREVIOUS_TAG
$CHANGES
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...$NEXT_MINOR_VERSION
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...$RESOLVED_VERSION
$CONTRIBUTORS
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: Draft release notes

on:
push:
Expand All @@ -15,8 +15,11 @@ jobs:
permissions:
contents: write
pull-requests: write

runs-on: ubuntu-latest

steps:
- uses: release-drafter/release-drafter@v6
- name: Draft release notes
uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ Behat Context to enable PHP server for tests.

```bash
composer lint
composer lint:fix
composer lint-fix
```

### Run tests

```bash
composer test
```

111 changes: 58 additions & 53 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,57 +1,62 @@
{
"name": "drevops/behat-phpserver",
"type": "library",
"description": "Behat Context to enable PHP server for tests",
"license": "GPL-2.0-or-later",
"keywords": [
"behat",
"server"
"name": "drevops/behat-phpserver",
"type": "library",
"description": "Behat Context to enable PHP server for tests",
"license": "GPL-2.0-or-later",
"keywords": [
"behat",
"server"
],
"authors": [
{
"name": "Alex Skrypnyk",
"email": "alex@drevops.com"
}
],
"homepage": "https://github.com/drevops/behat-phpserver",
"support": {
"issues": "https://github.com/drevops/behat-phpserver/issues",
"source": "https://github.com/drevops/behat-phpserver"
},
"require": {
"php": ">=8.1",
"behat/behat": "^3.13"
},
"require-dev": {
"behat/mink-browserkit-driver": "^2.2",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"escapestudios/symfony2-coding-standard": "^3.13",
"friends-of-behat/mink-extension": "^2.7",
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^1.10",
"rector/rector": "^1.0.0",
"squizlabs/php_codesniffer": "^3.8",
"symfony/http-client": "^6 || ^7.0"
},
"replace": {
"integratedexperts/behat-phpserver": "self.version"
},
"autoload": {
"psr-0": {
"DrevOps\\BehatPhpServer": "src/"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"scripts": {
"lint": [
"phpcs",
"phpmd --exclude vendor,vendor-bin,node_modules . text phpmd.xml",
"phpstan",
"rector --clear-cache --dry-run"
],
"authors": [
{
"name": "Alex Skrypnyk",
"email": "alex@drevops.com"
}
"lint-fix": [
"rector --clear-cache",
"phpcbf"
],
"homepage": "https://github.com/drevops/behat-phpserver",
"support": {
"issues": "https://github.com/drevops/behat-phpserver/issues",
"source": "https://github.com/drevops/behat-phpserver"
},
"require": {
"php": ">=8.1",
"behat/behat": "^3.13"
},
"require-dev": {
"behat/mink-browserkit-driver": "^2.2",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"escapestudios/symfony2-coding-standard": "^3.13",
"friends-of-behat/mink-extension": "^2.7",
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^1.10",
"squizlabs/php_codesniffer": "^3.8",
"symfony/http-client": "^6 || ^7.0"
},
"replace": {
"integratedexperts/behat-phpserver": "self.version"
},
"autoload": {
"psr-0": {
"DrevOps\\BehatPhpServer": "src/"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"scripts": {
"lint": [
"phpcs",
"phpmd --exclude vendor . text phpmd.xml",
"phpstan"
],
"lint:fix": "phpcbf",
"test": "cd ./tests/behat/ && ../../vendor/bin/behat --colors"
}
"test": "cd ./tests/behat/ && ../../vendor/bin/behat --colors"
}
}
65 changes: 65 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/**
* @file
* Rector configuration.
*
* Usage:
* ./vendor/bin/rector process .
*
* @see https://github.com/palantirnet/drupal-rector/blob/main/rector.php
*/

declare(strict_types=1);

use Rector\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector;
use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector;
use Rector\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
use Rector\Set\ValueObject\SetList;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/**',
]);

$rectorConfig->sets([
SetList::PHP_80,
SetList::PHP_81,
SetList::CODE_QUALITY,
SetList::CODING_STYLE,
SetList::DEAD_CODE,
SetList::INSTANCEOF,
SetList::TYPE_DECLARATION,
]);

$rectorConfig->skip([
// Rules added by Rector's rule sets.
ArraySpreadInsteadOfArrayMergeRector::class,
CountArrayToEmptyArrayComparisonRector::class,
DisallowedEmptyRuleFixerRector::class,
InlineArrayReturnAssignRector::class,
NewlineAfterStatementRector::class,
NewlineBeforeNewAssignSetRector::class,
PostIncDecToPreIncDecRector::class,
RemoveAlwaysTrueIfConditionRector::class,
SimplifyEmptyCheckOnEmptyArrayRector::class,
// Dependencies.
'*/vendor/*',
'*/node_modules/*',
]);

$rectorConfig->fileExtensions([
'php',
'inc',
]);

$rectorConfig->importNames(TRUE, FALSE);
$rectorConfig->importShortClasses(FALSE);
};
24 changes: 11 additions & 13 deletions src/DrevOps/BehatPhpServer/PhpServerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PhpServerContext implements Context
*
* @param mixed[] $parameters Settings for server.
*/
public function __construct($parameters = [])
public function __construct(array $parameters = [])
{
$this->docroot = isset($parameters['docroot']) ? $parameters['docroot'] : __DIR__.'/fixtures';
if (!file_exists($this->docroot)) {
Expand All @@ -67,11 +67,10 @@ public function __construct($parameters = [])
*
* @param BeforeScenarioScope $scope Scenario scope.
*
* @return void
*
* @beforeScenario @phpserver
*/
public function beforeScenarioStartPhpServer(BeforeScenarioScope $scope)
public function beforeScenarioStartPhpServer(BeforeScenarioScope $scope): void
{
if ($scope->getScenario()->hasTag('phpserver')) {
$this->start();
Expand All @@ -84,11 +83,10 @@ public function beforeScenarioStartPhpServer(BeforeScenarioScope $scope)
*
* @param AfterScenarioScope $scope Scenario scope.
*
* @return void
*
* @afterScenario @phpserver
*/
public function afterScenarioStopPhpServer(AfterScenarioScope $scope)
public function afterScenarioStopPhpServer(AfterScenarioScope $scope): void
{
if ($scope->getScenario()->hasTag('phpserver')) {
$this->stop();
Expand All @@ -105,7 +103,7 @@ public function afterScenarioStopPhpServer(AfterScenarioScope $scope)
* If unable to start a server.
*
*/
protected function start()
protected function start(): int
{
// If the server already running on this port, stop it.
// This is a much simpler way of handling previously started servers than
Expand Down Expand Up @@ -143,7 +141,7 @@ protected function start()
* @return bool
* TRUE if server process was stopped, FALSE otherwise.
*/
protected function stop()
protected function stop(): bool
{
if (!$this->isRunning(false)) {
return true;
Expand All @@ -163,7 +161,7 @@ protected function stop()
* @return bool
* TRUE if the server is running, FALSE otherwise.
*/
protected function isRunning($timeout = 1, $delay = 500000)
protected function isRunning($timeout = 1, $delay = 500000): bool
{
if ($timeout === false) {
return $this->canConnect();
Expand All @@ -190,10 +188,10 @@ protected function isRunning($timeout = 1, $delay = 500000)
* TRUE if server is running and it is possible to connect to it via
* socket, FALSE otherwise.
*/
protected function canConnect()
protected function canConnect(): bool
{
set_error_handler(
function () {
static function () : bool {
return true;
}
);
Expand All @@ -220,7 +218,7 @@ function () {
* @return boolean
* TRUE if the process was successfully terminated, FALSE otherwise.
*/
protected function terminateProcess($pid)
protected function terminateProcess($pid): bool
{
// If pid was not provided, do not allow to terminate current process.
if (!$pid) {
Expand All @@ -246,13 +244,13 @@ protected function terminateProcess($pid)
* @return int
* PID as number.
*/
protected function getPid($port)
protected function getPid($port): int
{
$pid = 0;

$output = [];
// @todo: Add support to OSes other then OSX and Ubuntu.
exec("netstat -peanut 2>/dev/null|grep ':$port'", $output);
exec(sprintf("netstat -peanut 2>/dev/null|grep ':%s'", $port), $output);

if (!isset($output[0])) {
throw new \RuntimeException(
Expand Down
15 changes: 7 additions & 8 deletions tests/behat/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ class FeatureContext extends MinkContext implements Context
{

/**
* Go to the phpserver test page.
*
* @return void
*
* @Given /^(?:|I )am on (?:|the )phpserver test page$/
* @When /^(?:|I )go to (?:|the )phpserver test page$/
*/
public function goToPhpServerTestPage()
* Go to the phpserver test page.
*
*
* @Given /^(?:|I )am on (?:|the )phpserver test page$/
* @When /^(?:|I )go to (?:|the )phpserver test page$/
*/
public function goToPhpServerTestPage(): void
{
$this->getSession()->visit('http://localhost:8888/testpage.html');
}
Expand Down

0 comments on commit 046f04a

Please sign in to comment.