Skip to content

Commit

Permalink
All tests can run in one go without stalling
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFeeney committed May 22, 2018
1 parent 076e1a4 commit c74a40d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ public static function start()
while (@file_get_contents("http://$url/get") === false) {
usleep(1000);
}
register_shutdown_function(function () use ($pid) {
exec('kill '.$pid);
});
global $kill_test_server;
$kill_test_server = function () use ($pid) {
exec('kill '.$pid.' 2>/dev/null');
};
register_shutdown_function($kill_test_server);
}
};

Expand Down
10 changes: 6 additions & 4 deletions tests/unit/ApiClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public function get_latest_version_test()
$this->assertInstanceOf(Version::class, $response->version);

foreach ([
'new_version' => '1.2.3',
'new_version' => '1.2.3',
'stable_version' => '1.2.3',
'name' => 'Test Plugin',
'slug' => 'test-plugin',
'name' => 'Test Plugin',
'slug' => 'test-plugin',
] as $key => $value) {
$this->assertEquals($value, $response->version->$key);
}
Expand Down Expand Up @@ -62,13 +62,15 @@ public function get_latest_version_call_gracefully_handles_timeout()
));

$apiClient->setTimeout(1);

$response = $apiClient->getLatestVersion();

$this->assertTrue($response->isError());
$this->assertEquals('500', $response->code);
$this->assertTrue(
Str::contains($response->message, 'http_request_failed: cURL error 28: Operation timed out after')
);
global $kill_test_server;

@$kill_test_server();
}
}

0 comments on commit c74a40d

Please sign in to comment.