Skip to content

Commit

Permalink
Merge pull request #289 from WaylandAce/chore/update-phpstan
Browse files Browse the repository at this point in the history
feat: update phpstan/phpstan analyze tool
  • Loading branch information
cfmack committed Feb 13, 2023
2 parents fbb50d9 + 6c025d3 commit 2baa81c
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 38 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"amphp/cache": "^1.4.0",
"amphp/windows-registry": "v0.3.3",
"guzzlehttp/guzzle": "^6.5.8|^7.4.5",
"phpunit/phpunit": ">=8.5.23",
"phpunit/phpunit": ">=8.5.23 <10",
"tienvx/composer-downloads-plugin": "^1.1.0"
},
"require-dev": {
Expand All @@ -45,7 +45,7 @@
"slim/psr7": "^1.2.0",
"friendsofphp/php-cs-fixer": "^3.0",
"php-amqplib/php-amqplib": "^3.0",
"phpstan/phpstan": "^0.12.90"
"phpstan/phpstan": "^1.9"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/PhpPact/Exception/ConnectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*/
class ConnectionException extends Exception
{
public function __construct(string $message)
public function __construct(string $message, \Exception $previous = null)
{
parent::__construct($message, 0, null);
parent::__construct($message, 0, $previous);
}
}
9 changes: 3 additions & 6 deletions src/PhpPact/Standalone/MockService/MockServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace PhpPact\Standalone\MockService;

use Exception;
use GuzzleHttp\Exception\ConnectException;
use PhpPact\Http\GuzzleClient;
use PhpPact\Standalone\Exception\HealthCheckFailedException;
use PhpPact\Standalone\Installer\Model\Scripts;
use PhpPact\Standalone\MockService\Service\MockServerHttpService;
use PhpPact\Standalone\Runner\ProcessRunner;
use PhpPact\Exception\ConnectionException;

/**
* Ruby Standalone Mock Server Wrapper
Expand Down Expand Up @@ -135,15 +135,12 @@ private function verifyHealthCheck(): bool
++$tries;

try {
$status = $service->healthCheck();

return $status;
} catch (ConnectException $e) {
return $service->healthCheck();
} catch (ConnectionException $e) {
\sleep($retrySec);
}
} while ($tries <= $maxTries);

// @phpstan-ignore-next-line
throw new HealthCheckFailedException("Failed to make connection to Mock Server in {$maxTries} attempts.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace PhpPact\Standalone\MockService\Service;

use GuzzleHttp\Exception\RequestException;
use PhpPact\Consumer\Model\Interaction;
use PhpPact\Consumer\Model\Message;
use PhpPact\Exception\ConnectionException;
use PhpPact\Http\ClientInterface;
use PhpPact\Standalone\MockService\MockServerConfigInterface;
use GuzzleHttp\Exception\ConnectException as GuzzleConnectionException;

/**
* Http Service that interacts with the Ruby Standalone Mock Server.
Expand Down Expand Up @@ -45,18 +47,24 @@ public function healthCheck(): bool
{
$uri = $this->config->getBaseUri()->withPath('/');

$response = $this->client->get($uri, [
'headers' => [
'Content-Type' => 'application/json',
'X-Pact-Mock-Service' => true,
],
]);

$body = $response->getBody()->getContents();

if ($response->getStatusCode() !== 200
|| $body !== "Mock service running\n") {
throw new ConnectionException('Failed to receive a successful response from the Mock Server.');
try {
$response = $this->client->get($uri, [
'headers' => [
'Content-Type' => 'application/json',
'X-Pact-Mock-Service' => true,
],
]);

$body = $response->getBody()->getContents();

if ($response->getStatusCode() !== 200
|| $body !== "Mock service running\n") {
throw new ConnectionException('Failed to receive a successful response from the Mock Server.');
}
} catch (RequestException $e) {
throw new ConnectionException('Failed to receive a successful response from the Mock Server.', $e);
} catch (GuzzleConnectionException $e) {
throw new ConnectionException('Failed to receive a successful response from the Mock Server.', $e);
}

return true;
Expand Down
3 changes: 2 additions & 1 deletion tests/PhpPact/Consumer/InteractionBuilderTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace PhpPact\Consumer;
namespace PhpPactTest\Consumer;

use PhpPact\Consumer\InteractionBuilder;
use PhpPact\Consumer\Matcher\Matcher;
use PhpPact\Consumer\Model\ConsumerRequest;
use PhpPact\Consumer\Model\ProviderResponse;
Expand Down
3 changes: 2 additions & 1 deletion tests/PhpPact/Consumer/Matcher/MatcherTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace PhpPact\Consumer\Matcher;
namespace PhpPactTest\Consumer\Matcher;

use Exception;
use PhpPact\Consumer\Matcher\Matcher;
use PHPUnit\Framework\TestCase;

class MatcherTest extends TestCase
Expand Down
3 changes: 2 additions & 1 deletion tests/PhpPact/Consumer/Model/ConsumerRequestTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace PhpPact\Consumer\Model;
namespace PhpPactTest\Consumer\Model;

use PhpPact\Consumer\Matcher\Matcher;
use PhpPact\Consumer\Model\ConsumerRequest;
use PHPUnit\Framework\TestCase;

class ConsumerRequestTest extends TestCase
Expand Down
3 changes: 2 additions & 1 deletion tests/PhpPact/Consumer/Model/ProviderResponseTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace PhpPact\Consumer\Model;
namespace PhpPactTest\Consumer\Model;

use PhpPact\Consumer\Model\ProviderResponse;
use PHPUnit\Framework\TestCase;

class ProviderResponseTest extends TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpPact/Standalone/Broker/BrokerConfigTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PhpPact\Consumer;
namespace PhpPactTest\Standalone\Broker;

use PhpPact\Standalone\MockService\MockServerConfig;
use PHPUnit\Framework\TestCase;
Expand Down
4 changes: 3 additions & 1 deletion tests/PhpPact/Standalone/Broker/BrokerTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace PhpPact\Standalone\Broker;
namespace PhpPactTest\Standalone\Broker;

use GuzzleHttp\Psr7\Uri;
use PhpPact\Standalone\Broker\Broker;
use PhpPact\Standalone\Broker\BrokerConfig;
use PHPUnit\Framework\TestCase;

class BrokerTest extends TestCase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PhpPact\Consumer;
namespace PhpPactTest\Standalone\MockServer;

use PhpPact\Standalone\MockService\MockServerConfig;
use PHPUnit\Framework\TestCase;
Expand Down
6 changes: 3 additions & 3 deletions tests/PhpPact/Standalone/MockServer/MockServerTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace PhpPact\Consumer;
namespace PhpPactTest\Standalone\MockServer;

use GuzzleHttp\Exception\ConnectException;
use PhpPact\Exception\ConnectionException;
use PhpPact\Standalone\Exception\HealthCheckFailedException;
use PhpPact\Standalone\Exception\MissingEnvVariableException;
use PhpPact\Standalone\MockService\MockServer;
Expand Down Expand Up @@ -43,7 +43,7 @@ public function testStartAndStopWithRecognizedTimeout()
->disableOriginalConstructor()
->getMock();

$connectionException = $this->getMockBuilder(ConnectException::class)
$connectionException = $this->getMockBuilder(ConnectionException::class)
->disableOriginalConstructor()
->getMock();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PhpPact\Standalone\MockService\Service;
namespace PhpPactTest\Standalone\MockServer\Service;

use GuzzleHttp\Exception\ServerException;
use PhpPact\Consumer\InteractionBuilder;
Expand All @@ -14,6 +14,8 @@
use PhpPact\Standalone\MockService\MockServer;
use PhpPact\Standalone\MockService\MockServerConfigInterface;
use PhpPact\Standalone\MockService\MockServerEnvConfig;
use PhpPact\Standalone\MockService\Service\MockServerHttpService;
use PhpPact\Standalone\MockService\Service\MockServerHttpServiceInterface;
use PHPUnit\Framework\TestCase;
use stdClass;

Expand Down
5 changes: 4 additions & 1 deletion tests/PhpPact/Standalone/ProviderVerifier/VerifierTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PhpPact\Standalone\ProviderVerifier;
namespace PhpPactTest\Standalone\ProviderVerifier;

use GuzzleHttp\Psr7\Uri;
use Monolog\Handler\TestHandler;
Expand All @@ -9,6 +9,9 @@
use PhpPact\Broker\Service\BrokerHttpClientInterface;
use PhpPact\Standalone\ProviderVerifier\Model\ConsumerVersionSelectors;
use PhpPact\Standalone\ProviderVerifier\Model\VerifierConfig;
use PhpPact\Standalone\ProviderVerifier\ProcessRunnerFactory;
use PhpPact\Standalone\ProviderVerifier\Verifier;
use PhpPact\Standalone\ProviderVerifier\VerifierProcess;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;

Expand Down
3 changes: 2 additions & 1 deletion tests/PhpPact/Standalone/Runner/ProcessRunnerTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace PhpPact\Standalone\Runner;
namespace PhpPactTest\Standalone\Runner;

use PhpPact\Standalone\Runner\ProcessRunner;
use PHPUnit\Framework\TestCase;

class ProcessRunnerTest extends TestCase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

namespace PhpPact\Standalone\StubService\Service;
namespace PhpPactTest\Standalone\StubServer\Service;

use PhpPact\Http\GuzzleClient;
use PhpPact\Standalone\Exception\MissingEnvVariableException;
use PhpPact\Standalone\StubService\Service\StubServerHttpService;
use PhpPact\Standalone\StubService\Service\StubServerHttpServiceInterface;
use PhpPact\Standalone\StubService\StubServer;
use PhpPact\Standalone\StubService\StubServerConfig;
use PhpPact\Standalone\StubService\StubServerConfigInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PhpPact\Consumer;
namespace PhpPactTest\Standalone\StubServer;

use PhpPact\Standalone\StubService\StubServerConfig;
use PHPUnit\Framework\TestCase;
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpPact/Standalone/StubServer/StubServerTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PhpPact\Consumer;
namespace PhpPactTest\Standalone\StubServer;

use PhpPact\Standalone\StubService\StubServer;
use PhpPact\Standalone\StubService\StubServerConfig;
Expand Down

0 comments on commit 2baa81c

Please sign in to comment.