From 111c5381a6ec865e921fcba8baf5f9556b11aaed Mon Sep 17 00:00:00 2001 From: Damien Russell Date: Tue, 30 Jun 2020 14:53:13 -0400 Subject: [PATCH 1/5] upgrade dependencies for laravel/lumen 7.x and more of utilization php 7.3 --- .phpunit.result.cache | 1 + composer.json | 13 +++---- docker-compose.yaml | 2 +- phpunit.xml | 3 +- src/Checks/General/DebugHealthCheck.php | 4 +-- src/Checks/General/EnvHealthCheck.php | 4 ++- src/Checks/General/HttpHealthCheck.php | 9 ++--- src/Checks/General/MemcachedHealthCheck.php | 20 ++++++----- src/Checks/Laravel/DatabaseHealthCheck.php | 14 +++++--- src/Checks/Laravel/QueueHealthCheck.php | 22 +++++++----- src/HealthCheck.php | 14 ++++---- src/HealthResult.php | 34 ++++++++++++++----- src/Healthz.php | 6 ++-- src/ResultStack.php | 16 +++++++-- src/Support/HealthzArtisanCommand.php | 8 +++-- src/Support/Stack.php | 25 +++++++++++--- tests/Checks/General/DebugHealthCheckTest.php | 4 +-- tests/Checks/General/EnvHealthCheckTest.php | 4 +-- tests/Checks/General/HttpHealthCheckTest.php | 6 ++-- .../General/MemcachedHealthCheckTest.php | 5 +-- .../Laravel/DatabaseHealthCheckTest.php | 4 +-- tests/Checks/Laravel/QueueHealthCheckTest.php | 4 +-- tests/HealthCheckTest.php | 2 +- tests/HealthResultTest.php | 2 +- tests/HealthzTest.php | 2 +- tests/ResultStackTest.php | 2 +- tests/TestCase.php | 2 +- 27 files changed, 148 insertions(+), 84 deletions(-) create mode 100644 .phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..2b31347 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +C:37:"PHPUnit\Runner\DefaultTestResultCache":5114:{a:2:{s:7:"defects";a:12:{s:95:"Gentux\Healthz\Checks\General\DebugHealthCheckTest::run_throws_warning_exception_if_debug_is_on";i:6;s:85:"Gentux\Healthz\Checks\General\EnvHealthCheckTest::unknown_environment_emits_a_warning";i:6;s:72:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::run_sends_the_request";i:5;s:117:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::run_throws_an_exception_if_the_expected_response_code_doesnt_match";i:6;s:103:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::run_catches_guzzle_exceptions_to_compare_status_code";i:5;s:106:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::run_builds_memcached_instance_and_tests_connection";i:5;s:117:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::run_throws_failure_exception_if_memcached_cant_set_test_value";i:3;s:107:"Gentux\Healthz\Checks\Laravel\DatabaseHealthCheckTest::throws_health_failure_when_laravel_runs_into_trouble";i:6;s:99:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::throws_warning_if_queue_driver_is_not_supported";i:6;s:75:"Gentux\Healthz\Checks\Laravel\DatabaseHealthCheckTest::sets_connection_name";i:4;s:67:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::sets_queue_name";i:4;s:59:"Gentux\Healthz\ResultStackTest::push_and_check_for_failures";i:4;}s:5:"times";a:39:{s:76:"Gentux\Healthz\Checks\General\DebugHealthCheckTest::instance_of_health_check";d:0.084;s:83:"Gentux\Healthz\Checks\General\DebugHealthCheckTest::run_sets_the_description_to_off";d:0.005;s:95:"Gentux\Healthz\Checks\General\DebugHealthCheckTest::run_throws_warning_exception_if_debug_is_on";d:0.015;s:74:"Gentux\Healthz\Checks\General\EnvHealthCheckTest::instance_of_health_check";d:0.006;s:92:"Gentux\Healthz\Checks\General\EnvHealthCheckTest::sets_the_status_to_the_current_environment";d:0.001;s:85:"Gentux\Healthz\Checks\General\EnvHealthCheckTest::unknown_environment_emits_a_warning";d:0.001;s:75:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::instance_of_health_check";d:0.241;s:73:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::get_request_to_be_made";d:0.004;s:88:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::gets_expected_status_code_for_request";d:0.003;s:70:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::gets_guzzle_options";d:0.003;s:72:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::run_sends_the_request";d:0.106;s:117:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::run_throws_an_exception_if_the_expected_response_code_doesnt_match";d:0.013;s:103:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::run_catches_guzzle_exceptions_to_compare_status_code";d:0.056;s:99:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::if_no_description_is_set_the_request_uri_is_used";d:0.006;s:80:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::instance_of_health_check";d:0.221;s:67:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::add_servers";d:0.002;s:67:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::set_options";d:0.002;s:77:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::username_and_password";d:0.002;s:106:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::run_builds_memcached_instance_and_tests_connection";d:0.016;s:117:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::run_throws_failure_exception_if_memcached_cant_set_test_value";d:0.005;s:79:"Gentux\Healthz\Checks\Laravel\DatabaseHealthCheckTest::instance_of_health_check";d:0.084;s:75:"Gentux\Healthz\Checks\Laravel\DatabaseHealthCheckTest::sets_connection_name";d:0.006;s:103:"Gentux\Healthz\Checks\Laravel\DatabaseHealthCheckTest::if_no_description_is_set_use_the_connection_name";d:0.002;s:118:"Gentux\Healthz\Checks\Laravel\DatabaseHealthCheckTest::uses_the_connection_name_set_to_resolve_a_laravel_db_connection";d:0.197;s:107:"Gentux\Healthz\Checks\Laravel\DatabaseHealthCheckTest::throws_health_failure_when_laravel_runs_into_trouble";d:0.004;s:76:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::instance_of_health_check";d:0.058;s:67:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::sets_queue_name";d:0.002;s:100:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::if_no_description_is_set_use_the_connection_name";d:0.002;s:89:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::checks_connection_status_of_sqs_queue";d:0.199;s:79:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::checks_status_of_sync_queue";d:0.084;s:99:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::throws_warning_if_queue_driver_is_not_supported";d:0.094;s:64:"Gentux\Healthz\HealthCheckTest::title_defaults_to_the_class_name";d:0.001;s:47:"Gentux\Healthz\HealthResultTest::result_helpers";d:0.036;s:63:"Gentux\Healthz\HealthResultTest::information_about_health_check";d:0.008;s:52:"Gentux\Healthz\HealthzTest::get_set_of_health_checks";d:0.022;s:65:"Gentux\Healthz\HealthzTest::push_new_health_checks_onto_the_stack";d:0.004;s:69:"Gentux\Healthz\HealthzTest::run_health_checks_and_return_result_stack";d:0.029;s:59:"Gentux\Healthz\ResultStackTest::push_and_check_for_failures";d:0.04;s:59:"Gentux\Healthz\ResultStackTest::push_and_check_for_warnings";d:0.011;}}} \ No newline at end of file diff --git a/composer.json b/composer.json index 3dd79a1..5b0c47a 100644 --- a/composer.json +++ b/composer.json @@ -26,17 +26,18 @@ ] }, "require": { + "php": ">=7.3", "guzzlehttp/guzzle": "~6.0", "aws/aws-sdk-php": "~3.0", - "illuminate/contracts": "^6.0", - "illuminate/database": "^6.0", - "illuminate/queue": "^6.0", - "illuminate/console": "^6.0", + "illuminate/contracts": "^7.0", + "illuminate/database": "^7.0", + "illuminate/queue": "^7.0", + "illuminate/console": "^7.0", "twig/twig": "~1.0" }, "require-dev": { - "phpunit/phpunit": "^7.0", - "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^8.5", + "mockery/mockery": "^1.2.1", "gecko-packages/gecko-memcache-mock": "^1.0" }, "extra": { diff --git a/docker-compose.yaml b/docker-compose.yaml index 06cd7c7..b729cba 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,7 @@ version: '3' services: app: - image: gentux/php:lumen-5.6-ci + image: gentux/php:laravel-6.x-ci volumes: - ./:/var/www ports: diff --git a/phpunit.xml b/phpunit.xml index 5b8e91e..60690ea 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,8 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true" - syntaxCheck="false"> + stopOnFailure="true"> ./tests/ diff --git a/src/Checks/General/DebugHealthCheck.php b/src/Checks/General/DebugHealthCheck.php index 1e0f35b..bd6639f 100644 --- a/src/Checks/General/DebugHealthCheck.php +++ b/src/Checks/General/DebugHealthCheck.php @@ -29,11 +29,11 @@ public function __construct($env = 'APP_DEBUG') /** * Check if the app is in debug mode * - * @return mixed + * @return void * * @throws HealthWarningException */ - public function run() + public function run(): void { $debug = getenv($this->env) == 'true'; diff --git a/src/Checks/General/EnvHealthCheck.php b/src/Checks/General/EnvHealthCheck.php index cc63185..979c666 100644 --- a/src/Checks/General/EnvHealthCheck.php +++ b/src/Checks/General/EnvHealthCheck.php @@ -29,8 +29,10 @@ public function __construct($env = 'APP_ENV') /** * Run the health check + * + * @throws HealthWarningException */ - public function run() + public function run(): void { $env = getenv($this->env) ?: 'UNKNOWN'; if ($env == 'UNKNOWN') { diff --git a/src/Checks/General/HttpHealthCheck.php b/src/Checks/General/HttpHealthCheck.php index b787e2b..57da612 100644 --- a/src/Checks/General/HttpHealthCheck.php +++ b/src/Checks/General/HttpHealthCheck.php @@ -6,6 +6,7 @@ use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\Request; use Gentux\Healthz\HealthCheck; +use Psr\Http\Message\ResponseInterface; /** * Health check for HTTP endpoints @@ -41,11 +42,11 @@ public function __construct(Request $request, $expectedStatusCode = 200, array $ /** * Send the request * - * @return mixed + * @return ResponseInterface * - * @throws HealthFailureException + * @throws HealthFailureException|RequestException */ - public function run() + public function run(): ResponseInterface { try { $response = $this->guzzle()->send( @@ -156,7 +157,7 @@ public function guzzle() * * @return string */ - public function description() + public function description(): ?string { $description = $this->description; diff --git a/src/Checks/General/MemcachedHealthCheck.php b/src/Checks/General/MemcachedHealthCheck.php index 90f6d6c..7799b0e 100644 --- a/src/Checks/General/MemcachedHealthCheck.php +++ b/src/Checks/General/MemcachedHealthCheck.php @@ -31,9 +31,11 @@ public function __construct($memcached = null) /** * Check for connection to memcached servers * - * @return mixed + * @return void + * + * @throws HealthFailureException */ - public function run() + public function run(): void { if (count($this->servers())) { $this->memcached->addServers($this->servers()); @@ -64,7 +66,7 @@ public function run() * * @return self */ - public function addServer($server, $port = 11211, $weight = 0) + public function addServer($server, $port = 11211, $weight = 0): HealthCheck { $this->servers[] = [$server, $port, $weight]; @@ -76,7 +78,7 @@ public function addServer($server, $port = 11211, $weight = 0) * * @return array */ - public function servers() + public function servers(): array { return $this->servers; } @@ -88,7 +90,7 @@ public function servers() * * @return self */ - public function setOptions(array $options) + public function setOptions(array $options): HealthCheck { $this->options = $options; @@ -100,7 +102,7 @@ public function setOptions(array $options) * * @return array */ - public function options() + public function options(): array { return $this->options; } @@ -113,7 +115,7 @@ public function options() * * @return self */ - public function setAuth($username, $password) + public function setAuth($username, $password): HealthCheck { $this->username = $username; $this->password = $password; @@ -126,7 +128,7 @@ public function setAuth($username, $password) * * @return string|null */ - public function username() + public function username(): ?string { return $this->username; } @@ -136,7 +138,7 @@ public function username() * * @return string|null */ - public function password() + public function password(): ?string { return $this->password; } diff --git a/src/Checks/Laravel/DatabaseHealthCheck.php b/src/Checks/Laravel/DatabaseHealthCheck.php index d229434..ba7e71a 100644 --- a/src/Checks/Laravel/DatabaseHealthCheck.php +++ b/src/Checks/Laravel/DatabaseHealthCheck.php @@ -42,11 +42,11 @@ public function __construct(DatabaseManager $db = null) /** * Check database connection * - * @return mixed + * @return void * * @throws HealthFailureException */ - public function run() + public function run(): void { try { $name = $this->connection(); @@ -63,7 +63,7 @@ public function run() * * @return null|string */ - public function connection() + public function connection(): ?string { return $this->connection; } @@ -72,8 +72,10 @@ public function connection() * Set the connection name * * @param string $connection + * + * @return void */ - public function setConnection($connection) + public function setConnection($connection): void { $this->connection = $connection; } @@ -81,8 +83,10 @@ public function setConnection($connection) /** * If no description property is defined, use the connection * name instead ('default' if connection is also null). + * + * @return string */ - public function description() + public function description(): string { $description = $this->description; diff --git a/src/Checks/Laravel/QueueHealthCheck.php b/src/Checks/Laravel/QueueHealthCheck.php index d75d3a6..5252938 100644 --- a/src/Checks/Laravel/QueueHealthCheck.php +++ b/src/Checks/Laravel/QueueHealthCheck.php @@ -45,12 +45,12 @@ public function __construct(QueueManager $queue = null) /** * Check database connection * - * @return mixed + * @return void * * @throws HealthFailureException * @throws HealthWarningException */ - public function run() + public function run(): void { $name = $this->name(); $queue = $this->queue->connection($name); @@ -68,8 +68,10 @@ public function run() * Run the health check against an sqs queue * * @param SqsQueue $queue + * + * @return void */ - protected function runSqsCheck(SqsQueue $queue) + protected function runSqsCheck(SqsQueue $queue): void { $url = $queue->getQueue(null); $queue->getSqs()->getQueueAttributes(['QueueUrl' => $url]); @@ -82,8 +84,10 @@ protected function runSqsCheck(SqsQueue $queue) * just set the status. * * @param SyncQueue $queue + * + * @return void */ - protected function runSyncCheck(SyncQueue $queue) + protected function runSyncCheck(SyncQueue $queue): void { $this->setStatus('connected to Sync queue'); } @@ -93,7 +97,7 @@ protected function runSyncCheck(SyncQueue $queue) * * @return null|string */ - public function name() + public function name(): ?string { return $this->name; } @@ -102,8 +106,10 @@ public function name() * Set the queue name * * @param string $name + * + * @return void */ - public function setName($name) + public function setName($name): void { $this->name = $name; } @@ -111,9 +117,9 @@ public function setName($name) /** * If no description property is defined, use the queue name instead. * - * @return string + * @return string|null */ - public function description() + public function description(): ?string { $description = $this->description ?: $this->name(); diff --git a/src/HealthCheck.php b/src/HealthCheck.php index 9161e1c..4da347b 100644 --- a/src/HealthCheck.php +++ b/src/HealthCheck.php @@ -39,7 +39,7 @@ abstract public function run(); * * @return string */ - public function title() + public function title(): string { $title = $this->title; @@ -58,7 +58,7 @@ public function title() * * @return $this */ - public function setTitle($title) + public function setTitle($title): self { $this->title = $title; @@ -70,7 +70,7 @@ public function setTitle($title) * * @return null|string */ - public function description() + public function description(): ?string { return $this->description; } @@ -82,7 +82,7 @@ public function description() * * @return $this */ - public function setDescription($description) + public function setDescription($description): self { $this->description = $description; @@ -97,7 +97,7 @@ public function setDescription($description) * * @return null|string */ - public function status() + public function status(): ?string { return $this->status; } @@ -109,10 +109,10 @@ public function status() * * @return $this */ - public function setStatus($status) + public function setStatus($status): self { $this->status = $status; - return $status; + return $this; } } diff --git a/src/HealthResult.php b/src/HealthResult.php index e632b7a..c2bca4c 100644 --- a/src/HealthResult.php +++ b/src/HealthResult.php @@ -18,6 +18,12 @@ class HealthResult /** @var HealthCheck */ protected $check; + /** + * HealthResult constructor. + * + * @param $result + * @param HealthCheck $check + */ public function __construct($result, HealthCheck $check) { $this->result = $result; @@ -29,7 +35,7 @@ public function __construct($result, HealthCheck $check) * * @return bool */ - public function failed() + public function failed(): bool { return $this->result() === self::RESULT_FAILURE; } @@ -39,7 +45,7 @@ public function failed() * * @return bool */ - public function passed() + public function passed(): bool { return $this->result() === self::RESULT_SUCCESS; } @@ -49,30 +55,42 @@ public function passed() * * @return bool */ - public function warned() + public function warned(): bool { return $this->result() === self::RESULT_WARNING; } /** Getters: information about the health check */ - public function title() + /** + * @return string + */ + public function title(): string { return $this->check->title(); } - public function description() + /** + * @return string + */ + public function description(): string { return $this->check->description(); } - public function status() + /** + * @return string|null + */ + public function status(): ?string { return $this->check->status(); } - public function result() + /** + * @return int + */ + public function result(): int { return $this->result; } -} \ No newline at end of file +} diff --git a/src/Healthz.php b/src/Healthz.php index 344c090..9cac6f8 100644 --- a/src/Healthz.php +++ b/src/Healthz.php @@ -34,7 +34,7 @@ public function __construct($healthChecks = []) * * @return $this */ - public function push(HealthCheck $healthCheck) + public function push(HealthCheck $healthCheck): self { return $this->stackPush($healthCheck); } @@ -44,7 +44,7 @@ public function push(HealthCheck $healthCheck) * * @return ResultStack */ - public function run() + public function run(): ResultStack { $results = []; @@ -73,7 +73,7 @@ public function run() * * @return string */ - public function html(ResultStack $results=null) + public function html(ResultStack $results=null): string { if ($results === null) { $results = $this->run(); diff --git a/src/ResultStack.php b/src/ResultStack.php index 4f6e670..d1a8384 100644 --- a/src/ResultStack.php +++ b/src/ResultStack.php @@ -15,12 +15,22 @@ class ResultStack Stack::push as stackPush; } + /** + * ResultStack constructor. + * + * @param array $results + */ public function __construct(array $results=[]) { $this->items = $results; } - public function push(HealthResult $result) + /** + * @param HealthResult $result + * + * @return Stack + */ + public function push(HealthResult $result): ResultStack { return $this->stackPush($result); } @@ -30,7 +40,7 @@ public function push(HealthResult $result) * * @return bool */ - public function hasFailures() + public function hasFailures(): bool { $hasFailure = false; foreach ($this->all() as $result) { @@ -48,7 +58,7 @@ public function hasFailures() * * @return bool */ - public function hasWarnings() + public function hasWarnings(): bool { $hasWarning = false; foreach($this->all() as $result) { diff --git a/src/Support/HealthzArtisanCommand.php b/src/Support/HealthzArtisanCommand.php index 8920780..43d22d7 100644 --- a/src/Support/HealthzArtisanCommand.php +++ b/src/Support/HealthzArtisanCommand.php @@ -28,7 +28,7 @@ public function __construct(Healthz $checks) * * @return int */ - public function handle() + public function handle(): int { if (count($this->checks->all()) == 0) { $this->comment("No health checks registered. Be sure to register Gentux\Healthz\Healthz in a service provider. See github.com/generationtux/php-healthz for more info."); @@ -51,8 +51,10 @@ public function handle() * Output message about health check result * * @param HealthResult $result + * + * @return void */ - protected function outputCheckResult(HealthResult $result) + protected function outputCheckResult(HealthResult $result): void { $message = $result->title() . ": " . $result->status(); @@ -70,4 +72,4 @@ protected function outputCheckResult(HealthResult $result) $this->comment($message); } } -} \ No newline at end of file +} diff --git a/src/Support/Stack.php b/src/Support/Stack.php index 5f588d1..b0bd3dd 100644 --- a/src/Support/Stack.php +++ b/src/Support/Stack.php @@ -14,29 +14,44 @@ trait Stack /** * @return array */ - public function all() + public function all(): array { return $this->items; } - public function push($item) + /** + * @param $item + * + * @return $this + */ + public function push($item): self { $this->items[] = $item; return $this; } - public function merge(array $items) + /** + * @param array $items + * + * @return $this + */ + public function merge(array $items): self { $this->items = array_merge($this->items, $items); return $this; } - public function replace(array $items) + /** + * @param array $items + * + * @return $this + */ + public function replace(array $items): self { $this->items = $items; return $this; } -} \ No newline at end of file +} diff --git a/tests/Checks/General/DebugHealthCheckTest.php b/tests/Checks/General/DebugHealthCheckTest.php index 2db5652..6f6bafc 100644 --- a/tests/Checks/General/DebugHealthCheckTest.php +++ b/tests/Checks/General/DebugHealthCheckTest.php @@ -6,7 +6,7 @@ class DebugHealthCheckTest extends \TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); $this->debug = new DebugHealthCheck(); @@ -29,10 +29,10 @@ public function run_sets_the_description_to_off() /** * @test - * @expectedException \Gentux\Healthz\Exceptions\HealthWarningException */ public function run_throws_warning_exception_if_debug_is_on() { + $this->expectException(\Gentux\Healthz\Exceptions\HealthWarningException::class); $this->debug = new DebugHealthCheck('DEBUG_CUSTOM'); putenv('DEBUG_CUSTOM=true'); diff --git a/tests/Checks/General/EnvHealthCheckTest.php b/tests/Checks/General/EnvHealthCheckTest.php index 0035691..f8138bc 100644 --- a/tests/Checks/General/EnvHealthCheckTest.php +++ b/tests/Checks/General/EnvHealthCheckTest.php @@ -10,7 +10,7 @@ class EnvHealthCheckTest extends \TestCase /** @var EnvHealthCheck */ protected $env; - public function setUp() + public function setUp(): void { parent::setUp(); $this->env = new EnvHealthCheck('CUSTOM_ENV'); @@ -32,10 +32,10 @@ public function sets_the_status_to_the_current_environment() /** * @test - * @expectedException \Gentux\Healthz\Exceptions\HealthWarningException */ public function unknown_environment_emits_a_warning() { + $this->expectException(\Gentux\Healthz\Exceptions\HealthWarningException::class); putenv('CUSTOM_ENV='); $this->env->run(); } diff --git a/tests/Checks/General/HttpHealthCheckTest.php b/tests/Checks/General/HttpHealthCheckTest.php index cb1d02e..4e353b3 100644 --- a/tests/Checks/General/HttpHealthCheckTest.php +++ b/tests/Checks/General/HttpHealthCheckTest.php @@ -21,7 +21,7 @@ class HttpHealthCheckTest extends \TestCase /** @var HttpHealthCheck */ protected $http; - public function setUp() + public function setUp(): void { parent::setUp(); $this->request = Mockery::mock(Request::class); @@ -77,14 +77,15 @@ public function run_sends_the_request() $this->guzzle->shouldReceive('send')->with($this->request, [])->once()->andReturn($response); $this->http->run(); + $this->assertTrue(true); } /** * @test - * @expectedException \Gentux\Healthz\Exceptions\HealthFailureException */ public function run_throws_an_exception_if_the_expected_response_code_doesnt_match() { + $this->expectException(\Gentux\Healthz\Exceptions\HealthFailureException::class); $response = Mockery::mock(Response::class); $response->shouldReceive('getStatusCode')->andReturn(201); @@ -106,6 +107,7 @@ public function run_catches_guzzle_exceptions_to_compare_status_code() $this->http->setExpectedStatusCode(404); $this->http->run(); // no exceptions, should pass + $this->assertTrue(true); } /** @test */ diff --git a/tests/Checks/General/MemcachedHealthCheckTest.php b/tests/Checks/General/MemcachedHealthCheckTest.php index e533321..608e8d2 100644 --- a/tests/Checks/General/MemcachedHealthCheckTest.php +++ b/tests/Checks/General/MemcachedHealthCheckTest.php @@ -23,7 +23,7 @@ class MemcachedHealthCheckTest extends \TestCase /** @var MemcachedHealthCheck */ protected $health; - public function setUp() + public function setUp(): void { parent::setUp(); $this->memcached = Mockery::mock(MemcachedMock::class); @@ -81,14 +81,15 @@ public function run_builds_memcached_instance_and_tests_connection() $this->memcached->shouldReceive('set')->with('test.connection', 'success', 1)->once()->andReturn(true); $this->health->run(); + $this->assertTrue(true); } /** * @test - * @expectedException \Gentux\Healthz\Exceptions\HealthFailureException */ public function run_throws_failure_exception_if_memcached_cant_set_test_value() { + $this->expectException(\Gentux\Healthz\Exceptions\HealthFailureException::class); $this->memcached->shouldReceive('set')->with('test.connection', 'success', 1)->once()->andReturn(false); $this->health->run(); } diff --git a/tests/Checks/Laravel/DatabaseHealthCheckTest.php b/tests/Checks/Laravel/DatabaseHealthCheckTest.php index eaa5e40..20b5ab8 100644 --- a/tests/Checks/Laravel/DatabaseHealthCheckTest.php +++ b/tests/Checks/Laravel/DatabaseHealthCheckTest.php @@ -16,7 +16,7 @@ class DatabaseHealthCheckTest extends \TestCase /** @var DatabaseHealthCheck */ protected $db; - public function setUp() + public function setUp(): void { parent::setUp(); $this->manager = Mockery::mock(DatabaseManager::class); @@ -64,10 +64,10 @@ public function uses_the_connection_name_set_to_resolve_a_laravel_db_connection( /** * @test - * @expectedException \Gentux\Healthz\Exceptions\HealthFailureException */ public function throws_health_failure_when_laravel_runs_into_trouble() { + $this->expectException(\Gentux\Healthz\Exceptions\HealthFailureException::class); $this->manager->shouldReceive('connection')->andThrow(new \Exception()); $this->db->run(); } diff --git a/tests/Checks/Laravel/QueueHealthCheckTest.php b/tests/Checks/Laravel/QueueHealthCheckTest.php index fcc871e..164221f 100644 --- a/tests/Checks/Laravel/QueueHealthCheckTest.php +++ b/tests/Checks/Laravel/QueueHealthCheckTest.php @@ -19,7 +19,7 @@ class QueueHealthCheckTest extends \TestCase /** @var QueueHealthCheck */ protected $queue; - public function setUp() + public function setUp(): void { parent::setUp(); $this->manager = Mockery::mock(QueueManager::class); @@ -90,10 +90,10 @@ public function checks_status_of_sync_queue() /** * @test - * @expectedException \Gentux\Healthz\Exceptions\HealthWarningException */ public function throws_warning_if_queue_driver_is_not_supported() { + $this->expectException(\Gentux\Healthz\Exceptions\HealthWarningException::class); $redis = Mockery::mock(RedisQueue::class); $this->manager->shouldReceive('connection')->andReturn($redis); diff --git a/tests/HealthCheckTest.php b/tests/HealthCheckTest.php index 3c512e7..1ef376d 100644 --- a/tests/HealthCheckTest.php +++ b/tests/HealthCheckTest.php @@ -13,7 +13,7 @@ class HealthCheckTest extends \TestCase /** @var MockCheckTitle */ protected $checkWithTitle; - public function setUp() + public function setUp(): void { parent::setUp(); $this->check = new MockCheck(); diff --git a/tests/HealthResultTest.php b/tests/HealthResultTest.php index 00cfd05..3a37af2 100644 --- a/tests/HealthResultTest.php +++ b/tests/HealthResultTest.php @@ -15,7 +15,7 @@ class HealthResultTest extends \TestCase /** @var HealthResult*/ protected $resultFailure; - public function setUp() + public function setUp(): void { parent::setUp(); $check = Mockery::mock(HealthCheck::class); diff --git a/tests/HealthzTest.php b/tests/HealthzTest.php index d2cf7cd..ac366c0 100644 --- a/tests/HealthzTest.php +++ b/tests/HealthzTest.php @@ -20,7 +20,7 @@ class HealthzTest extends \TestCase /** @var Healthz */ protected $healthz; - public function setUp() + public function setUp(): void { parent::setUp(); $this->check1 = Mockery::mock(HealthCheck::class); diff --git a/tests/ResultStackTest.php b/tests/ResultStackTest.php index 64593b0..e47b531 100644 --- a/tests/ResultStackTest.php +++ b/tests/ResultStackTest.php @@ -18,7 +18,7 @@ class ResultStackTest extends \TestCase /** @var HealthResult */ protected $checkWarned; - public function setUp() + public function setUp(): void { $this->checkPassed = Mockery::mock(HealthResult::class); $this->checkPassed->shouldReceive('failed')->andReturn(false); diff --git a/tests/TestCase.php b/tests/TestCase.php index e888df3..24e31ac 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,7 +3,7 @@ class TestCase extends \PHPUnit\Framework\TestCase { - public function tearDown() + public function tearDown(): void { Mockery::close(); parent::tearDown(); From bdf3a5bbef3114479f5b8c1c9e47eab7c6dd7a2e Mon Sep 17 00:00:00 2001 From: Damien Russell Date: Tue, 30 Jun 2020 15:22:18 -0400 Subject: [PATCH 2/5] added independent dockerfiles and instructions in the readme --- .travis.yml | 2 +- Dockerfile | 29 +++++++++++++++++++++++++++++ docker-compose.yaml | 4 +++- docker/installComposer.sh | 20 ++++++++++++++++++++ readme.md | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100755 docker/installComposer.sh diff --git a/.travis.yml b/.travis.yml index c763d7b..4ad775c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: php php: - - '7.2' + - '7.3' install: composer install script: ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml after_success: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..248939c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM php:7.3-fpm-alpine + +# The following labels need to be set as part of the docker build process. +# org.opencontainers.image.created +# org.opencontainers.image.revision +LABEL org.opencontainers.image.url="https://laravel.com" \ + org.opencontainers.image.documentation="https://github.com/generationtux/php-healthz/blob/master/README.md" \ + org.opencontainers.image.source="https://github.com/generationtux/php-healthz/Dockerfile" \ + org.opencontainers.image.vendor="Generation Tux " \ + org.opencontainers.image.title="Laravel 6.x" \ + org.opencontainers.image.description="PHP built for use with the Laravel/Lumen framework" \ + com.generationtux.php.backend="fpm" + +COPY ./docker/installComposer.sh /tmp/installComposer.sh + +RUN apk --no-cache --update add bash ca-certificates libpq postgresql-dev curl git curl git mysql-client unzip wget zip postgresql-client \ + && apk add --no-cache --virtual build-dependencies autoconf build-base g++ make \ + && pecl install redis xdebug \ + && docker-php-ext-install bcmath opcache pdo_mysql pdo_pgsql pcntl \ + && docker-php-ext-enable bcmath opcache redis xdebug \ + && chmod +x /tmp/installComposer.sh \ + && /tmp/installComposer.sh \ + && chown www-data:www-data /usr/local/bin/composer \ + && apk del --purge autoconf build-dependencies g++ make \ + && chown -R www-data:www-data /var/www \ + +WORKDIR /var/www + +USER www-data:www-data diff --git a/docker-compose.yaml b/docker-compose.yaml index b729cba..b747ab8 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,9 @@ version: '3' services: app: - image: gentux/php:laravel-6.x-ci + build: + context: . + dockerfile: ./Dockerfile volumes: - ./:/var/www ports: diff --git a/docker/installComposer.sh b/docker/installComposer.sh new file mode 100755 index 0000000..b034dea --- /dev/null +++ b/docker/installComposer.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig) +php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +ACTUAL_SIGNATURE=$(php -r "echo hash_file('sha384', 'composer-setup.php');") + +if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]; then + >&2 echo 'ERROR: Invalid installer signature' + rm composer-setup.php + exit 1 +fi + +php composer-setup.php --install-dir=/usr/local/bin --filename=composer --quiet +RESULT=$? +rm composer-setup.php +if [[ "$RESULT" -eq "0" ]]; then + composer global require hirak/prestissimo +fi; +exit $RESULT +Terms diff --git a/readme.md b/readme.md index 07bfa44..2cbd217 100644 --- a/readme.md +++ b/readme.md @@ -237,3 +237,39 @@ public function run() throw new HealthWarningException("The check didn't fail, but here ye be warned."); } ``` + + +## Contributing + +### What you need +* [docker & docker-compose](https://docs.docker.com/compose/install/) +* a fork of this repo + +### Bringing up the development environment + +```sh +docker-compose up -d +``` + +### Exec into the container +```sh +docker-compose exec app bash +``` +### Composer install +```sh +composer install +``` + +### Running the tests +```sh +./vendor/bin/phpunit +``` + + +### Finally +Make your changes and add any needed tests around said changes. +Then open a pull request into the generationtux repository. + + + + From 58deaefa0ae674439f29a18744f479ec32dea278 Mon Sep 17 00:00:00 2001 From: Damien Russell Date: Tue, 30 Jun 2020 15:44:36 -0400 Subject: [PATCH 3/5] require guzzle ^6.2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5b0c47a..7b45e63 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ }, "require": { "php": ">=7.3", - "guzzlehttp/guzzle": "~6.0", + "guzzlehttp/guzzle": "^6.2", "aws/aws-sdk-php": "~3.0", "illuminate/contracts": "^7.0", "illuminate/database": "^7.0", From cb12bd1d32dd5495f3dae19b9eb94213b48ed322 Mon Sep 17 00:00:00 2001 From: Damien Russell Date: Tue, 30 Jun 2020 15:56:42 -0400 Subject: [PATCH 4/5] remove .phpunit.result.cache --- .gitignore | 1 + .phpunit.result.cache | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 .phpunit.result.cache diff --git a/.gitignore b/.gitignore index d2a4c00..c1fcba1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /tests/coverage composer.lock .idea +.phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache deleted file mode 100644 index 2b31347..0000000 --- a/.phpunit.result.cache +++ /dev/null @@ -1 +0,0 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":5114:{a:2:{s:7:"defects";a:12:{s:95:"Gentux\Healthz\Checks\General\DebugHealthCheckTest::run_throws_warning_exception_if_debug_is_on";i:6;s:85:"Gentux\Healthz\Checks\General\EnvHealthCheckTest::unknown_environment_emits_a_warning";i:6;s:72:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::run_sends_the_request";i:5;s:117:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::run_throws_an_exception_if_the_expected_response_code_doesnt_match";i:6;s:103:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::run_catches_guzzle_exceptions_to_compare_status_code";i:5;s:106:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::run_builds_memcached_instance_and_tests_connection";i:5;s:117:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::run_throws_failure_exception_if_memcached_cant_set_test_value";i:3;s:107:"Gentux\Healthz\Checks\Laravel\DatabaseHealthCheckTest::throws_health_failure_when_laravel_runs_into_trouble";i:6;s:99:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::throws_warning_if_queue_driver_is_not_supported";i:6;s:75:"Gentux\Healthz\Checks\Laravel\DatabaseHealthCheckTest::sets_connection_name";i:4;s:67:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::sets_queue_name";i:4;s:59:"Gentux\Healthz\ResultStackTest::push_and_check_for_failures";i:4;}s:5:"times";a:39:{s:76:"Gentux\Healthz\Checks\General\DebugHealthCheckTest::instance_of_health_check";d:0.084;s:83:"Gentux\Healthz\Checks\General\DebugHealthCheckTest::run_sets_the_description_to_off";d:0.005;s:95:"Gentux\Healthz\Checks\General\DebugHealthCheckTest::run_throws_warning_exception_if_debug_is_on";d:0.015;s:74:"Gentux\Healthz\Checks\General\EnvHealthCheckTest::instance_of_health_check";d:0.006;s:92:"Gentux\Healthz\Checks\General\EnvHealthCheckTest::sets_the_status_to_the_current_environment";d:0.001;s:85:"Gentux\Healthz\Checks\General\EnvHealthCheckTest::unknown_environment_emits_a_warning";d:0.001;s:75:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::instance_of_health_check";d:0.241;s:73:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::get_request_to_be_made";d:0.004;s:88:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::gets_expected_status_code_for_request";d:0.003;s:70:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::gets_guzzle_options";d:0.003;s:72:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::run_sends_the_request";d:0.106;s:117:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::run_throws_an_exception_if_the_expected_response_code_doesnt_match";d:0.013;s:103:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::run_catches_guzzle_exceptions_to_compare_status_code";d:0.056;s:99:"Gentux\Healthz\Checks\General\HttpHealthCheckTest::if_no_description_is_set_the_request_uri_is_used";d:0.006;s:80:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::instance_of_health_check";d:0.221;s:67:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::add_servers";d:0.002;s:67:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::set_options";d:0.002;s:77:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::username_and_password";d:0.002;s:106:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::run_builds_memcached_instance_and_tests_connection";d:0.016;s:117:"Gentux\Healthz\Checks\General\MemcachedHealthCheckTest::run_throws_failure_exception_if_memcached_cant_set_test_value";d:0.005;s:79:"Gentux\Healthz\Checks\Laravel\DatabaseHealthCheckTest::instance_of_health_check";d:0.084;s:75:"Gentux\Healthz\Checks\Laravel\DatabaseHealthCheckTest::sets_connection_name";d:0.006;s:103:"Gentux\Healthz\Checks\Laravel\DatabaseHealthCheckTest::if_no_description_is_set_use_the_connection_name";d:0.002;s:118:"Gentux\Healthz\Checks\Laravel\DatabaseHealthCheckTest::uses_the_connection_name_set_to_resolve_a_laravel_db_connection";d:0.197;s:107:"Gentux\Healthz\Checks\Laravel\DatabaseHealthCheckTest::throws_health_failure_when_laravel_runs_into_trouble";d:0.004;s:76:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::instance_of_health_check";d:0.058;s:67:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::sets_queue_name";d:0.002;s:100:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::if_no_description_is_set_use_the_connection_name";d:0.002;s:89:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::checks_connection_status_of_sqs_queue";d:0.199;s:79:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::checks_status_of_sync_queue";d:0.084;s:99:"Gentux\Healthz\Checks\Laravel\QueueHealthCheckTest::throws_warning_if_queue_driver_is_not_supported";d:0.094;s:64:"Gentux\Healthz\HealthCheckTest::title_defaults_to_the_class_name";d:0.001;s:47:"Gentux\Healthz\HealthResultTest::result_helpers";d:0.036;s:63:"Gentux\Healthz\HealthResultTest::information_about_health_check";d:0.008;s:52:"Gentux\Healthz\HealthzTest::get_set_of_health_checks";d:0.022;s:65:"Gentux\Healthz\HealthzTest::push_new_health_checks_onto_the_stack";d:0.004;s:69:"Gentux\Healthz\HealthzTest::run_health_checks_and_return_result_stack";d:0.029;s:59:"Gentux\Healthz\ResultStackTest::push_and_check_for_failures";d:0.04;s:59:"Gentux\Healthz\ResultStackTest::push_and_check_for_warnings";d:0.011;}}} \ No newline at end of file From c913680103587cf325cfa2e349d6fb21980888a4 Mon Sep 17 00:00:00 2001 From: Damien Russell Date: Thu, 2 Jul 2020 13:36:00 -0400 Subject: [PATCH 5/5] update twig --- Dockerfile | 4 +++- composer.json | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 248939c..9d362cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,8 @@ LABEL org.opencontainers.image.url="https://laravel.com" \ org.opencontainers.image.description="PHP built for use with the Laravel/Lumen framework" \ com.generationtux.php.backend="fpm" +USER root + COPY ./docker/installComposer.sh /tmp/installComposer.sh RUN apk --no-cache --update add bash ca-certificates libpq postgresql-dev curl git curl git mysql-client unzip wget zip postgresql-client \ @@ -22,7 +24,7 @@ RUN apk --no-cache --update add bash ca-certificates libpq postgresql-dev curl g && /tmp/installComposer.sh \ && chown www-data:www-data /usr/local/bin/composer \ && apk del --purge autoconf build-dependencies g++ make \ - && chown -R www-data:www-data /var/www \ + && chown -R www-data:www-data /var/www WORKDIR /var/www diff --git a/composer.json b/composer.json index 7b45e63..ab5a19e 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "illuminate/database": "^7.0", "illuminate/queue": "^7.0", "illuminate/console": "^7.0", - "twig/twig": "~1.0" + "twig/twig": "~3.0" }, "require-dev": { "phpunit/phpunit": "^8.5",