Skip to content

Commit

Permalink
:octocat: unbreak my tests 🎶
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Mar 11, 2024
1 parent f34d84d commit 0effae2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
<xml outputDirectory=".build/coverage/coverage-xml"/>
</report>
</coverage>
<!--
<groups>
<exclude>
<!--
<group>output</group>
<group>slow</group>
-->
</exclude>
</groups>
-->
<php>
<const name="REQUEST_FACTORY" value="chillerlan\HTTP\Psr7\HTTPFactory"/>
<const name="RESPONSE_FACTORY" value="chillerlan\HTTP\Psr7\HTTPFactory"/>
Expand Down
10 changes: 7 additions & 3 deletions src/HTTPOptionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace chillerlan\HTTP;

use function file_exists, ini_get, is_dir, is_file, is_link, readlink, trim;
use function file_exists, ini_get, is_dir, is_file, is_link, readlink, realpath, trim;
use const CURLOPT_CAINFO, CURLOPT_CAPATH;

/**
Expand Down Expand Up @@ -152,9 +152,13 @@ protected function setCA(string|null $ca_info = null):void{
if($ca_info !== null){

if($this->checkCA($ca_info)){
$this->ca_info = $ca_info;
$ca_info = realpath($ca_info);

return;
if($ca_info !== false){
$this->ca_info = $ca_info;

return;
}
}

throw new ClientException('invalid path to SSL CA bundle: '.$ca_info);
Expand Down
3 changes: 2 additions & 1 deletion tests/HTTPOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use chillerlan\HTTP\{CurlHandle, HTTPOptions};
use PHPUnit\Framework\TestCase;
use Psr\Http\Client\ClientExceptionInterface;
use function realpath;
use const CURLOPT_CAINFO, CURLOPT_CAPATH, CURLOPT_SSL_VERIFYHOST, CURLOPT_SSL_VERIFYPEER;

/**
Expand Down Expand Up @@ -51,7 +52,7 @@ public function testInvalidCAException():void{
}

public function testCaInfoFile():void{
$file = __DIR__.'/cacert.pem';
$file = realpath(__DIR__.'/cacert.pem');
// via the ca_info option
$options = new HTTPOptions(['ca_info' => $file]);
$curl_options = $this->createTestHandleOptions($options);
Expand Down
14 changes: 8 additions & 6 deletions tests/LoggingClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

namespace chillerlan\HTTPTest;

use chillerlan\HTTP\LoggingClient;
use chillerlan\HTTP\{CurlClient, LoggingClient};
use PHPUnit\Framework\Attributes\Group;
use Psr\Http\Client\ClientInterface;
use Psr\Log\AbstractLogger;
use Stringable;
use function date, printf;
Expand All @@ -23,18 +24,19 @@
*/
#[Group('slow')]
#[Group('output')]
class LoggingClientTest extends CurlClientTest{
class LoggingClientTest extends HTTPClientTestAbstract{

protected function setUp():void{
parent::setUp();
protected function initClient():ClientInterface{
$this->options->ssl_verifypeer = false; // whyyy???
$http = new CurlClient($this->responseFactory, $this->options);
$logger = new class () extends AbstractLogger{
public function log($level, string|Stringable $message, array $context = []):void{
printf("\n[%s][%s] LoggingClientTest: %s", date('Y-m-d H:i:s'), $level, $message);
}
};
// we'll just wrap the parent's client
$this->http = new LoggingClient($this->http, $logger);

return new LoggingClient($http, $logger);
}

public function testNetworkError():void{
Expand Down

0 comments on commit 0effae2

Please sign in to comment.