Skip to content

Commit

Permalink
refactor: Use loophp/psr17 dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Apr 14, 2022
1 parent 96f8d18 commit 3cd0f0f
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 233 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"friends-of-phpspec/phpspec-code-coverage": "^6.0.0",
"infection/infection": "^0.23 || ^0.24",
"infection/phpspec-adapter": "^0.1.2",
"loophp/psr17": "^1.0",
"monolog/monolog": "^1.0",
"nyholm/psr7": "^1.4",
"nyholm/psr7-server": "^1.0.0",
Expand All @@ -40,6 +41,10 @@
"symfony/cache": "^5.2",
"symfony/http-client": "^5.2"
},
"suggest": {
"loophp/psr17": "Provides a PSR17 synthetic implementation",
"nyholm/psr7": "A super lightweight PSR-7 implementation"
},
"autoload": {
"psr-4": {
"EcPhp\\CasLib\\": "./src/"
Expand Down
71 changes: 38 additions & 33 deletions spec/EcPhp/CasLib/CasSpec.php

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions spec/EcPhp/CasLib/Handler/ProxyCallbackSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use EcPhp\CasLib\Handler\ProxyCallback;
use EcPhp\CasLib\Utils\Uri as UtilsUri;
use Exception;
use loophp\psr17\Psr17;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7\Request;
use Nyholm\Psr7\Uri;
Expand All @@ -28,6 +29,7 @@ class ProxyCallbackSpec extends ObjectBehavior
public function it_can_catch_issue_with_the_cache(CacheItemPoolInterface $cache, CacheItemInterface $cacheItem, LoggerInterface $logger)
{
$psr17Factory = new Psr17Factory();
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$request = new Request(
'GET',
Expand Down Expand Up @@ -58,7 +60,7 @@ public function it_can_catch_issue_with_the_cache(CacheItemPoolInterface $cache,
->save($cacheItem)
->willReturn(true);

$this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger);
$this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger);

$this
->handle($request);
Expand Down Expand Up @@ -92,8 +94,9 @@ public function it_can_test_if_the_cache_is_working(CacheItemPoolInterface $cach
public function it_can_test_the_logger_when_missing_pgtId(CacheItemPoolInterface $cache, LoggerInterface $logger)
{
$psr17Factory = new Psr17Factory();
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger);
$this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger);

$request = new Request(
'GET',
Expand All @@ -116,8 +119,9 @@ public function it_can_test_the_logger_when_missing_pgtId(CacheItemPoolInterface
public function it_can_test_the_logger_when_missing_pgtIou(CacheItemPoolInterface $cache, LoggerInterface $logger)
{
$psr17Factory = new Psr17Factory();
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger);
$this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger);

$request = new Request(
'GET',
Expand All @@ -140,8 +144,9 @@ public function it_can_test_the_logger_when_missing_pgtIou(CacheItemPoolInterfac
public function it_can_test_the_logger_when_no_parameter_is_in_the_url(CacheItemPoolInterface $cache, LoggerInterface $logger)
{
$psr17Factory = new Psr17Factory();
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger);
$this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger);

$request = new Request(
'GET',
Expand All @@ -162,6 +167,7 @@ public function it_can_test_the_logger_when_no_parameter_is_in_the_url(CacheItem
public function it_can_test_the_logger_when_parameters_are_in_the_url(CacheItemPoolInterface $cache, CacheItemInterface $cacheItem, LoggerInterface $logger)
{
$psr17Factory = new Psr17Factory();
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$cacheItem
->set('pgtId')
Expand All @@ -179,7 +185,7 @@ public function it_can_test_the_logger_when_parameters_are_in_the_url(CacheItemP
->save($cacheItem)
->willReturn(true);

$this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger);
$this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger);

$request = new Request(
'GET',
Expand Down Expand Up @@ -208,6 +214,7 @@ public function it_is_initializable()
public function let(CacheItemPoolInterface $cache, CacheItemInterface $cacheItem, LoggerInterface $logger)
{
$psr17Factory = new Psr17Factory();
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$cacheItem
->set('pgtId')
Expand All @@ -225,6 +232,6 @@ public function let(CacheItemPoolInterface $cache, CacheItemInterface $cacheItem
->save($cacheItem)
->willReturn(true);

$this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger);
$this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger);
}
}
30 changes: 18 additions & 12 deletions spec/EcPhp/CasLib/Redirect/LoginSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace spec\EcPhp\CasLib\Redirect;

use EcPhp\CasLib\Redirect\Login;
use loophp\psr17\Psr17;
use loophp\psr17\Psr17Interface;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7\Request;
use Nyholm\Psr7\Uri;
Expand All @@ -26,17 +28,18 @@ class LoginSpec extends ObjectBehavior
public function it_can_deal_with_array_parameters(CacheItemPoolInterface $cache, LoggerInterface $logger)
{
$psr17Factory = new Psr17Factory();

$request = new Request(
'GET',
new Uri('http://from/it_can_deal_with_array_parameters')
);
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$parameters = [
'custom' => range(1, 5),
];

$this->beConstructedWith($parameters, Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger);
$this->beConstructedWith($parameters, Cas::getTestProperties(), $psr17, $cache, $logger);

$request = new Request(
'GET',
new Uri('http://from/it_can_deal_with_array_parameters')
);

$this
->handle($request)
Expand All @@ -51,14 +54,15 @@ public function it_can_deal_with_array_parameters(CacheItemPoolInterface $cache,
public function it_can_deal_with_renew_and_gateway_parameters(CacheItemPoolInterface $cache, LoggerInterface $logger)
{
$psr17Factory = new Psr17Factory();
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$parameters = [
'renew' => true,
'gateway' => true,
'service' => 'service',
];

$this->beConstructedWith($parameters, Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger);
$this->beConstructedWith($parameters, Cas::getTestProperties(), $psr17, $cache, $logger);

$request = new Request(
'GET',
Expand Down Expand Up @@ -91,13 +95,14 @@ public function it_can_deal_with_renew_and_gateway_parameters(CacheItemPoolInter
public function it_can_deal_with_renew_parameter(CacheItemPoolInterface $cache, LoggerInterface $logger)
{
$psr17Factory = new Psr17Factory();
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$parameters = [
'renew' => 'coin',
'gateway' => false,
];

$this->beConstructedWith($parameters, Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger);
$this->beConstructedWith($parameters, Cas::getTestProperties(), $psr17, $cache, $logger);

$request = new Request(
'GET',
Expand All @@ -121,7 +126,9 @@ public function it_can_deal_with_renew_parameter(CacheItemPoolInterface $cache,
public function it_can_get_a_response(CacheItemPoolInterface $cache, LoggerInterface $logger)
{
$psr17Factory = new Psr17Factory();
$this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger);
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger);

$request = new Request(
'GET',
Expand All @@ -133,10 +140,9 @@ public function it_can_get_a_response(CacheItemPoolInterface $cache, LoggerInter
->shouldBeAnInstanceOf(ResponseInterface::class);
}

public function it_is_initializable(CacheItemPoolInterface $cache, LoggerInterface $logger)
public function it_is_initializable(CacheItemPoolInterface $cache, LoggerInterface $logger, Psr17Interface $psr17)
{
$psr17Factory = new Psr17Factory();
$this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger);
$this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger);

$this->shouldHaveType(Login::class);
}
Expand Down
10 changes: 6 additions & 4 deletions spec/EcPhp/CasLib/Redirect/LogoutSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace spec\EcPhp\CasLib\Redirect;

use EcPhp\CasLib\Redirect\Logout;
use loophp\psr17\Psr17;
use loophp\psr17\Psr17Interface;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7\Request;
use Nyholm\Psr7\Uri;
Expand All @@ -26,7 +28,8 @@ class LogoutSpec extends ObjectBehavior
public function it_can_get_a_response(CacheItemPoolInterface $cache, LoggerInterface $logger)
{
$psr17Factory = new Psr17Factory();
$this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger);
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);
$this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger);

$request = new Request(
'GET',
Expand All @@ -38,10 +41,9 @@ public function it_can_get_a_response(CacheItemPoolInterface $cache, LoggerInter
->shouldBeAnInstanceOf(ResponseInterface::class);
}

public function it_is_initializable(CacheItemPoolInterface $cache, LoggerInterface $logger)
public function it_is_initializable(CacheItemPoolInterface $cache, LoggerInterface $logger, Psr17Interface $psr17)
{
$psr17Factory = new Psr17Factory();
$this->beConstructedWith([], Cas::getTestProperties(), $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger);
$this->beConstructedWith([], Cas::getTestProperties(), $psr17, $cache, $logger);

$this->shouldHaveType(Logout::class);
}
Expand Down
8 changes: 3 additions & 5 deletions spec/EcPhp/CasLib/Service/ProxySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use EcPhp\CasLib\Introspection\Introspector;
use EcPhp\CasLib\Service\Proxy;
use Nyholm\Psr7\Factory\Psr17Factory;
use loophp\psr17\Psr17Interface;
use Nyholm\Psr7\Response;
use PhpSpec\ObjectBehavior;
use Psr\Cache\CacheItemPoolInterface;
Expand Down Expand Up @@ -58,10 +58,8 @@ public function it_is_initializable()
$this->shouldHaveType(Proxy::class);
}

public function let(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger)
public function let(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger, Psr17Interface $psr17)
{
$psr17Factory = new Psr17Factory();

$this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector());
$this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector());
}
}
10 changes: 7 additions & 3 deletions spec/EcPhp/CasLib/Service/ProxyValidateSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use EcPhp\CasLib\Introspection\Introspector;
use EcPhp\CasLib\Service\ProxyValidate;
use loophp\psr17\Psr17;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7\Request;
use Nyholm\Psr7\Response;
Expand Down Expand Up @@ -41,6 +42,7 @@ public function it_can_detect_when_no_credentials()
public function it_can_get_credentials_with_pgtUrl(ClientInterface $client, CacheItemPoolInterface $cache, CacheItemInterface $cacheItem, LoggerInterface $logger)
{
$psr17Factory = new Psr17Factory();
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$client = new Psr18Client(CasSpecUtils::getHttpClientMock());

Expand Down Expand Up @@ -68,7 +70,7 @@ public function it_can_get_credentials_with_pgtUrl(ClientInterface $client, Cach
->getItem('pgtIou')
->willReturn($cacheItem);

$this->beConstructedWith([], Cas::getTestPropertiesWithPgtUrl(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector());
$this->beConstructedWith([], Cas::getTestPropertiesWithPgtUrl(), $client, $psr17, $cache, $logger, new Introspector());

$request = new Request(
'GET',
Expand All @@ -92,10 +94,11 @@ public function it_can_get_credentials_with_pgtUrl(ClientInterface $client, Cach
public function it_can_get_credentials_without_pgtUrl(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger)
{
$psr17Factory = new Psr17Factory();
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$client = new Psr18Client(CasSpecUtils::getHttpClientMock());

$this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector());
$this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector());

$request = new Request(
'GET',
Expand Down Expand Up @@ -124,7 +127,8 @@ public function it_is_initializable()
public function let(ClientInterface $client, CacheItemPoolInterface $cache, LoggerInterface $logger)
{
$psr17Factory = new Psr17Factory();
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger, new Introspector());
$this->beConstructedWith([], Cas::getTestProperties(), $client, $psr17, $cache, $logger, new Introspector());
}
}
12 changes: 4 additions & 8 deletions spec/tests/EcPhp/CasLib/CasSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ public function it_can_test_the_proxy_mode_with_pgtUrl()
$client = new Psr18Client(CasSpecUtils::getHttpClientMock());

$psr17Factory = new Psr17Factory();
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$introspector = new Introspector();

$this->beConstructedWith(new Cas(
$properties,
$client,
$psr17Factory,
$psr17Factory,
$psr17Factory,
$psr17Factory,
$psr17,
new ArrayAdapter(),
new NullLogger(),
$introspector
Expand All @@ -64,16 +62,14 @@ public function it_can_test_the_proxy_mode_without_pgtUrl()
$client = new Psr18Client(CasSpecUtils::getHttpClientMock());

$psr17Factory = new Psr17Factory();
$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$introspector = new Introspector();

$this->beConstructedWith(new Cas(
$properties,
$client,
$psr17Factory,
$psr17Factory,
$psr17Factory,
$psr17Factory,
$psr17,
new ArrayAdapter(),
new NullLogger(),
$introspector
Expand Down

0 comments on commit 3cd0f0f

Please sign in to comment.