Skip to content

Commit

Permalink
refactor: Install rector and auto refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed Sep 24, 2024
1 parent 750be24 commit afdf26e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion compatibility-suite/public/provider-states/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

$app->post('/pact-change-state', $stateChangeHandler);

$app->post('/failed-pact-change-state', function (Request $request, Response $response) use ($stateChangeHandler) {
$app->post('/failed-pact-change-state', function (Request $request, Response $response) use ($stateChangeHandler): void {
$stateChangeHandler($request, $response);

throw new \Exception('Cant do it');
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"galbar/jsonpath": "^3.0",
"ramsey/uuid": "^4.7",
"pact-foundation/example-protobuf-sync-message-provider": "@dev",
"webonyx/graphql-php": "^15.14"
"webonyx/graphql-php": "^15.14",
"rector/rector": "^1.2"
},
"autoload": {
"psr-4": {
Expand All @@ -60,6 +61,7 @@
"fix": "php-cs-fixer fix",
"test": "phpunit --no-coverage",
"check-compatibility": "behat",
"refactor": "rector",
"run-examples": [
"composer run-example:binary",
"composer run-example:csv",
Expand Down
2 changes: 1 addition & 1 deletion example/message/consumer/src/receive.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$channel->queue_declare('myKey', false, false, false, false);
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";

$callback = function ($msg) {
$callback = function ($msg): void {
// process that invokes the use of the message
$processor = new MessageConsumer\ExampleMessageConsumer();
$processor->processMessage($msg->body);
Expand Down
16 changes: 16 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/compatibility-suite',
__DIR__ . '/example',
__DIR__ . '/src',
__DIR__ . '/tests',
])
// uncomment to reach your current PHP version
// ->withPhpSets()
->withTypeCoverageLevel(0);
16 changes: 8 additions & 8 deletions tests/PhpPact/Standalone/MockServer/MockServerEnvConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MockServerEnvConfigTest extends TestCase
#[TestWith(['PACT_MOCK_SERVER_HOST=example.test', 'example.test'])]
public function testHost(string $assignment, string $host): void
{
$this->preserveEnv('PACT_MOCK_SERVER_PORT', $assignment, function () use ($host) {
$this->preserveEnv('PACT_MOCK_SERVER_PORT', $assignment, function () use ($host): void {
$config = new MockServerEnvConfig();
$this->assertSame($host, $config->getHost());
});
Expand All @@ -23,7 +23,7 @@ public function testHost(string $assignment, string $host): void
#[TestWith(['PACT_MOCK_SERVER_PORT=123', 123])]
public function testPort(string $assignment, int $port): void
{
$this->preserveEnv('PACT_MOCK_SERVER_PORT', $assignment, function () use ($port) {
$this->preserveEnv('PACT_MOCK_SERVER_PORT', $assignment, function () use ($port): void {
$config = new MockServerEnvConfig();
$this->assertSame($port, $config->getPort());
});
Expand All @@ -33,7 +33,7 @@ public function testPort(string $assignment, int $port): void
#[TestWith(['PACT_CONSUMER_NAME=consumer', 'consumer'])]
public function testConsumer(string $assignment, ?string $consumer): void
{
$this->preserveEnv('PACT_CONSUMER_NAME', $assignment, function () use ($consumer) {
$this->preserveEnv('PACT_CONSUMER_NAME', $assignment, function () use ($consumer): void {
if (!$consumer) {
$this->expectException(MissingEnvVariableException::class);
$this->expectExceptionMessage('Please provide required environmental variable PACT_CONSUMER_NAME!');
Expand All @@ -47,7 +47,7 @@ public function testConsumer(string $assignment, ?string $consumer): void
#[TestWith(['PACT_PROVIDER_NAME=provider', 'provider'])]
public function testProvider(string $assignment, ?string $provider): void
{
$this->preserveEnv('PACT_PROVIDER_NAME', $assignment, function () use ($provider) {
$this->preserveEnv('PACT_PROVIDER_NAME', $assignment, function () use ($provider): void {
if (!$provider) {
$this->expectException(MissingEnvVariableException::class);
$this->expectExceptionMessage('Please provide required environmental variable PACT_PROVIDER_NAME!');
Expand All @@ -61,7 +61,7 @@ public function testProvider(string $assignment, ?string $provider): void
#[TestWith(['PACT_OUTPUT_DIR=/path/to/pact/dir', '/path/to/pact/dir'])]
public function testPactDir(string $assignment, ?string $pactDir): void
{
$this->preserveEnv('PACT_OUTPUT_DIR', $assignment, function () use ($pactDir) {
$this->preserveEnv('PACT_OUTPUT_DIR', $assignment, function () use ($pactDir): void {
$pactDir ??= \sys_get_temp_dir();
$config = new MockServerEnvConfig();
$this->assertSame($pactDir, $config->getPactDir());
Expand All @@ -72,7 +72,7 @@ public function testPactDir(string $assignment, ?string $pactDir): void
#[TestWith(['PACT_LOG=/path/to/log/dir', '/path/to/log/dir'])]
public function testLog(string $assignment, ?string $logDir): void
{
$this->preserveEnv('PACT_LOG', $assignment, function () use ($logDir) {
$this->preserveEnv('PACT_LOG', $assignment, function () use ($logDir): void {
$config = new MockServerEnvConfig();
$this->assertSame($logDir, $config->getLog());
});
Expand All @@ -82,7 +82,7 @@ public function testLog(string $assignment, ?string $logDir): void
#[TestWith(['PACT_LOGLEVEL=trace', 'TRACE'])]
public function testLogLevel(string $assignment, ?string $logLevel): void
{
$this->preserveEnv('PACT_LOGLEVEL', $assignment, function () use ($logLevel) {
$this->preserveEnv('PACT_LOGLEVEL', $assignment, function () use ($logLevel): void {
$config = new MockServerEnvConfig();
$this->assertSame($logLevel, $config->getLogLevel());
});
Expand All @@ -92,7 +92,7 @@ public function testLogLevel(string $assignment, ?string $logLevel): void
#[TestWith(['PACT_SPECIFICATION_VERSION=1.1.0', '1.1.0'])]
public function testPactSpecificationVersion(string $assignment, ?string $specificationVersion): void
{
$this->preserveEnv('PACT_SPECIFICATION_VERSION', $assignment, function () use ($specificationVersion) {
$this->preserveEnv('PACT_SPECIFICATION_VERSION', $assignment, function () use ($specificationVersion): void {
$config = new MockServerEnvConfig();
$this->assertSame($specificationVersion, $config->getPactSpecificationVersion());
});
Expand Down

0 comments on commit afdf26e

Please sign in to comment.