Code development platform for open source projects from the European Union institutions

Verified Commit cba6e5e4 authored by Pol Dellaiera's avatar Pol Dellaiera
Browse files

chore: Get rid of PHPSpec.

parent 9f25c50d
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@
/grumphp.yml.dist export-ignore
/infection.json export-ignore
/infection.json.dist export-ignore
/phpspec.yml export-ignore
/phpspec.yml.dist export-ignore
/phpstan.neon export-ignore
/phpstan.neon.dist export-ignore
/psalm.xml export-ignore
+16 −20
Original line number Diff line number Diff line
@@ -11,16 +11,13 @@ Workflow
--------

Every time changes are introduced into the library, `Github Actions`_
run the tests written with `PHPSpec`_.

`PHPInfection`_ is also triggered used to ensure that your code is properly
tested.
run the tests written with `Behat`_.

The code style is based on `PSR-12`_ plus a set of custom rules.
Find more about the code style in use in the package `drupol/php-conventions`_.

A PHP quality tool, Grumphp_, is used to orchestrate all these tasks at each commit
on the local machine, but also on the continuous integration tools (Travis, Github actions)
on the local machine, but also on the continuous integration tools.

To run the whole tests tasks locally, do

@@ -35,25 +32,24 @@ and that will check your project.

    ./vendor/bin/grumphp run
    GrumPHP is sniffing your code!
    Running task  1/14: License... ✔
    Running task  2/14: composer_require_checker... ✔
    Running task  3/14: composer... ✔
    Running task  4/14: ComposerNormalize... ✔
    Running task  5/14: YamlLint... ✔
    Running task  6/14: JsonLint... ✔
    Running task  7/14: PhpLint... ✔
    Running task  8/14: TwigCs... ✔
    Running task  9/14: PhpCsFixer... ✔
    Running task 10/14: Phpcs... ✔
    Running task 11/14: PhpStan... ✔
    Running task 12/14: Psalm... ✔
    Running task 13/14: Phpspec... ✔
    Running task 14/14: Behat... ✔
    Running task  1/13: License... ✔
    Running task  2/13: composer_require_checker... ✔
    Running task  3/13: composer... ✔
    Running task  4/13: ComposerNormalize... ✔
    Running task  5/13: YamlLint... ✔
    Running task  6/13: JsonLint... ✔
    Running task  7/13: PhpLint... ✔
    Running task  8/13: TwigCs... ✔
    Running task  9/13: PhpCsFixer... ✔
    Running task 10/13: Phpcs... ✔
    Running task 11/13: PhpStan... ✔
    Running task 12/13: Psalm... ✔
    Running task 13/13: Behat... ✔

.. _PSR-12: https://www.php-fig.org/psr/psr-12/
.. _drupol/php-conventions: https://github.com/drupol/php-conventions
.. _Github Actions: https://github.com/ecphp/eu-login-api-authentication-bundle/actions
.. _PHPSpec: http://www.phpspec.net/
.. _Behat: http://www.behat.org/
.. _PHPInfection: https://github.com/infection/infection
.. _Grumphp: https://github.com/phpro/grumphp
.. _environment: https://symfony.com/doc/current/configuration.html#configuration-environments
+0 −5
Original line number Diff line number Diff line
@@ -4,9 +4,4 @@ imports:
parameters:
  tasks.license.date_from: 2020
  extra_tasks:
    phpspec:
      verbose: true
    clover_coverage:
      clover_file: build/logs/clover.xml
      level: 5
    behat: ~

phpspec.yml.dist

deleted100644 → 0
+0 −16
Original line number Diff line number Diff line
formatter.name: pretty
extensions:
  FriendsOfPhpSpec\PhpSpec\CodeCoverage\CodeCoverageExtension:
    format:
      - clover
      - php
      - text
      - html
    output:
      html: build/coverage
      clover: build/logs/clover.xml
      php: build/coverage.php
    whitelist:
      - src
    blacklist:
      - src/Resources
+0 −144
Original line number Diff line number Diff line
<?php

/**
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 *
 * @see https://github.com/ecphp
 */

declare(strict_types=1);

namespace spec\EcPhp\EuLoginApiAuthenticationBundle\Service;

use EcPhp\EuLoginApiAuthenticationBundle\Exception\EuLoginApiAuthenticationException;
use EcPhp\EuLoginApiAuthenticationBundle\Service\EuLoginApiCredentials;
use Nyholm\Psr7\Request;
use Nyholm\Psr7\Response;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;

class EuLoginApiCredentialsSpec extends ObjectBehavior
{
    public function disabled_it_can_get_credentials_from_a_request(RequestInterface $request, ClientInterface $httpClient)
    {
        $configuration = [
            'client_id' => 'client_id',
            'client_secret' => 'client_secret',
            'environment' => 'acceptance',
        ];

        $this->beConstructedWith($httpClient, $configuration);

        $token = 'eyJhbGciOiAiRVMyNTYiLCAiY3R5IjoiSldUIn0.eyJhdCI6IkFULTg0MDExNTgtNENWenBjVUJ6TXBzNldISk9jUVNvc29ndThGT3dIQk8wcUV2WjVhb0tVN0VQMXk0eThLVEVscThKdHp5ZG9yRU16SUltTEJ4MnkwVEI1UEh3Z1kwVXhDLXJhOGduQ0YxbFdhbGw3WVQyR0VCQUstUEZVd3NOZ3c0aFFaMWhBa1N4UTdmMlBING1WWk9jQnN6elZxc1cyOENkYkkySTZ5TEM5S3B3dHJwZkh6THBFeFNZaFhrenFmempDSmlramFQNklKN3BTIiwidHMiOjE2MTU5ODAyOTA1MzF9.opB_4uxzgOxhf9BhwF06To7nVnun_ji85sSHV_D5B6Gg9F15cepGxa8ea5bL6pTg3R8MH7QvYdmX82O-lzGUyw';

        $request
            ->hasHeader('Authorization')
            ->willReturn(true);

        $request
            ->getHeaderLine('Authorization')
            ->willReturn('pop ' . $token);

        $response = new Response(200, [], json_encode(['active' => false]));

        $httpClient
            ->sendRequest(Argument::any())
            ->willReturn($response);

        $this
            ->shouldThrow(
                EuLoginApiAuthenticationException::unableToGetCredentials(
                    EuLoginApiAuthenticationException::invalidOrRevokedToken()
                )
            )
            ->duringGetCredentials($request);
    }

    public function it_can_detect_if_the_Authorization_header_is_valid()
    {
        $request = new Request(
            'POST',
            'http://localhost',
            [
                'Authorization' => 'pop foo bar',
            ]
        );

        $this
            ->shouldThrow(
                EuLoginApiAuthenticationException::unableToGetCredentials(
                    EuLoginApiAuthenticationException::invalidAuthorizationHeader(['foo', 'bar'])
                )
            )
            ->duringGetCredentials($request);
    }

    public function it_can_detect_if_the_Authorization_prefix_is_valid()
    {
        $request = new Request(
            'POST',
            'http://localhost',
            [
                'Authorization' => 'bearer foo',
            ]
        );

        $this
            ->shouldThrow(
                EuLoginApiAuthenticationException::unableToGetCredentials(
                    EuLoginApiAuthenticationException::invalidAuthorizationHeaderPrefix('bearer')
                )
            )
            ->duringGetCredentials($request);
    }

    public function it_can_detect_if_the_request_has_an_Authorization_header()
    {
        $request = new Request(
            'POST',
            'http://localhost',
        );

        $this
            ->shouldThrow(EuLoginApiAuthenticationException::class)
            ->duringGetCredentials($request);
    }

    public function it_can_detect_if_the_token_has_a_valid_structure()
    {
        $request = new Request(
            'POST',
            'http://localhost',
            [
                'Authorization' => 'pop foo.foo.foo.foo',
            ]
        );

        $this
            ->shouldThrow(
                EuLoginApiAuthenticationException::unableToGetCredentials(
                    EuLoginApiAuthenticationException::invalidJWTTokenStructure('foo.foo.foo.foo')
                )
            )
            ->duringGetCredentials($request);
    }

    public function it_is_initializable()
    {
        $this->shouldHaveType(EuLoginApiCredentials::class);
    }

    public function let(ClientInterface $client)
    {
        $configuration = [
            'client_id' => 'client_id',
            'client_secret' => 'client_secret',
            'environment' => 'acceptance',
        ];

        $this->beConstructedWith($client, $configuration);
    }
}