Skip to content

Commit

Permalink
Improve coverage (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan authored and drupol committed Jul 23, 2020
1 parent e682a43 commit 8903595
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 39 deletions.
9 changes: 7 additions & 2 deletions grumphp.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ parameters:
verbose: true
metadata:
priority: 3000
clover_coverage:
clover_file: build/logs/clover.xml
level: 80
metadata:
priority: 2000
infection:
threads: 10
test_framework: phpspec
configuration: infection.json.dist
min_msi: 50
min_covered_msi: 50
min_msi: 70
min_covered_msi: 90
metadata:
priority: 2000
7 changes: 6 additions & 1 deletion phpspec.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ extensions:
- clover
- php
- text
- html
output:
html: build/coverage
clover: build/logs/clover.xml
php: build/coverage.php
php: build/coverage.php
whitelist:
- src
blacklist:
- src/Resources
6 changes: 0 additions & 6 deletions spec/EcPhp/CasBundle/Cas.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ public static function getHttpClientMock()
return new MockHttpClient($callback);
}

/**
* @return \EcPhp\CasLib\Configuration\Properties
*/
public static function getTestProperties(): CasProperties
{
return new CasProperties([
Expand Down Expand Up @@ -234,9 +231,6 @@ public static function getTestProperties(): CasProperties
]);
}

/**
* @return \EcPhp\CasLib\Configuration\Properties
*/
public static function getTestPropertiesWithPgtUrl(): CasProperties
{
$properties = self::getTestProperties()->all();
Expand Down
22 changes: 22 additions & 0 deletions spec/EcPhp/CasBundle/Controller/LoginSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,32 @@
namespace spec\EcPhp\CasBundle\Controller;

use EcPhp\CasBundle\Controller\Login;
use EcPhp\CasLib\CasInterface;
use PhpSpec\ObjectBehavior;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Security;

class LoginSpec extends ObjectBehavior
{
public function it_can_be_invoked(CasInterface $cas, Security $security, ResponseInterface $casResponse)
{
$request = Request::create('');
$response = $this
->__invoke($request, $cas, $security);
$response->shouldBeAnInstanceOf(RedirectResponse::class);
$response->headers->get('location')->shouldBe('/');

$casResponse->getHeaderLine('location')->willReturn('https://foo.com');
$cas->login(['renew' => false])->willReturn($casResponse);

$response = $this
->__invoke($request, $cas, $security);
$response->shouldBeAnInstanceOf(RedirectResponse::class);
$response->headers->get('location')->shouldBe('https://foo.com');
}

public function it_is_initializable()
{
$this->shouldHaveType(Login::class);
Expand Down
8 changes: 8 additions & 0 deletions spec/EcPhp/CasBundle/Controller/LogoutSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use EcPhp\CasBundle\Controller\Logout;
use EcPhp\CasLib\Cas;
use EcPhp\CasLib\CasInterface;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7\ServerRequest;
use PhpSpec\ObjectBehavior;
Expand Down Expand Up @@ -54,4 +55,11 @@ public function it_is_initializable()
{
$this->shouldHaveType(Logout::class);
}

public function it_redirects_to_index(CasInterface $cas, TokenStorageInterface $tokenStorage)
{
$response = $this->__invoke($cas, $tokenStorage);
$response->shouldBeAnInstanceOf(RedirectResponse::class);
$response->headers->get('location')->shouldReturn('/');
}
}
2 changes: 1 addition & 1 deletion src/Controller/Homepage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class Homepage
/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public function __invoke()
public function __invoke(): Response
{
$body = <<< 'EOF'
<p>You have been redirected here by default. You are most probably using the default CAS configuration.</p>
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ final class Login
* @param \EcPhp\CasLib\CasInterface $cas
* @param \Symfony\Component\Security\Core\Security $security
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function __invoke(
Request $request,
CasInterface $cas,
Security $security
) {
): RedirectResponse {
$parameters = $request->query->all() + [
'renew' => null !== $security->getUser(),
];
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ final class Logout
* @param \EcPhp\CasLib\CasInterface $cas
* @param \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface $tokenStorage
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function __invoke(
CasInterface $cas,
TokenStorageInterface $tokenStorage
) {
): RedirectResponse {
if (null !== $response = $cas->logout()) {
$tokenStorage->setToken();

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ProxyCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class ProxyCallback
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function __invoke(CasInterface $casProtocol, HttpFoundationFactoryInterface $httpFoundationFactory)
public function __invoke(CasInterface $casProtocol, HttpFoundationFactoryInterface $httpFoundationFactory): Response
{
if (null !== $response = $casProtocol->handleProxyCallback()) {
return $httpFoundationFactory->createResponse($response);
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('cas');

Expand Down
4 changes: 3 additions & 1 deletion src/Resources/config/routes/routes.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
declare(strict_types=1);

use EcPhp\CasBundle\Controller\Homepage;
use EcPhp\CasBundle\Controller\Login;
use EcPhp\CasBundle\Controller\Logout;
use EcPhp\CasBundle\Controller\ProxyCallback;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return static function (RoutingConfigurator $routes) {
$routes
Expand Down
30 changes: 19 additions & 11 deletions src/Security/CasGuardAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
}

/**
* @param Request $request
* @param TokenInterface $token
* @param string $providerKey
*
* @return Response|null
* {@inheritdoc}
*/
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
{
Expand All @@ -143,10 +139,16 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token,
*/
public function onLogoutSuccess(Request $request)
{
$response = $this
->cas
->logout();

if (null === $response) {
throw new AuthenticationException('Unable to trigger the logout procedure');
}

return new RedirectResponse(
$this
->cas
->logout()
$response
->getHeaderLine('location')
);
}
Expand All @@ -163,10 +165,16 @@ public function start(Request $request, ?AuthenticationException $authException
);
}

$response = $this
->cas
->login();

if (null === $response) {
throw new AuthenticationException('Unable to trigger the login procedure');
}

return new RedirectResponse(
$this
->cas
->login()
$response
->getHeaderLine('location')
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Security/Core/User/CasUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getAttributes(): array
/**
* {@inheritdoc}
*/
public function getPassword()
public function getPassword(): ?string
{
}

Expand All @@ -75,15 +75,15 @@ public function getPgt(): ?string
/**
* @return string[]
*/
public function getRoles()
public function getRoles(): array
{
return ['ROLE_CAS_AUTHENTICATED'];
}

/**
* {@inheritdoc}
*/
public function getSalt()
public function getSalt(): ?string
{
}

Expand All @@ -98,7 +98,7 @@ public function getUser(): string
/**
* {@inheritdoc}
*/
public function getUsername()
public function getUsername(): string
{
return $this->getUser();
}
Expand All @@ -108,7 +108,7 @@ public function getUsername()
*
* @return array<mixed>
*/
private function getStorage()
private function getStorage(): array
{
return $this->storage;
}
Expand Down
8 changes: 2 additions & 6 deletions src/Security/Core/User/CasUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public function loadUserByResponse(ResponseInterface $response): CasUserInterfac
}

/**
* @param string $username
*
* @return UserInterface
* {@inheritdoc}
*/
public function loadUserByUsername($username)
{
Expand All @@ -57,9 +55,7 @@ public function refreshUser(UserInterface $user)
}

/**
* @param string $class
*
* @return bool
* {@inheritdoc}
*/
public function supportsClass($class)
{
Expand Down

0 comments on commit 8903595

Please sign in to comment.