Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More code cleaned up, test coverage increased #38

Merged
merged 2 commits into from
Aug 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Client/ClientRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@

class ClientRegistry
{
/** @var ContainerInterface */
private $container;

/** @var array */
private $serviceMap;

/**
* ClientRegistry constructor.
*
* @param ContainerInterface $container
* @param array $serviceMap
*/
public function __construct(ContainerInterface $container, array $serviceMap)
{
$this->container = $container;
Expand Down
13 changes: 11 additions & 2 deletions src/Client/OAuth2Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@

class OAuth2Client
{
const OAUTH2_SESSION_STATE_KEY = 'knpu.oauth2_client_state';

/** @var AbstractProvider */
private $provider;

/** @var RequestStack */
private $requestStack;

/** @var bool */
private $isStateless = false;

const OAUTH2_SESSION_STATE_KEY = 'knpu.oauth2_client_state';

/**
* OAuth2Client constructor.
*
* @param AbstractProvider $provider
* @param RequestStack $requestStack
*/
public function __construct(AbstractProvider $provider, RequestStack $requestStack)
{
$this->provider = $provider;
Expand Down
17 changes: 14 additions & 3 deletions src/DependencyInjection/KnpUOAuth2ClientExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

class KnpUOAuth2ClientExtension extends Extension
{
/**
* @var bool
*/
/** @var bool */
private $checkExternalClassExistence;

/** @var array */
private $configurators = [];

/** @var array */
private static $supportedProviderTypes = [
'facebook' => FacebookProviderConfigurator::class,
'github' => GithubProviderConfigurator::class,
Expand All @@ -49,11 +49,22 @@ class KnpUOAuth2ClientExtension extends Extension
'generic' => GenericProviderConfigurator::class,
];

/**
* KnpUOAuth2ClientExtension constructor.
*
* @param bool $checkExternalClassExistence
*/
public function __construct($checkExternalClassExistence = true)
{
$this->checkExternalClassExistence = $checkExternalClassExistence;
}

/**
* Load the bundle configuration.
*
* @param array $configs
* @param ContainerBuilder $container
*/
public function load(array $configs, ContainerBuilder $container)
{
$processor = new Processor();
Expand Down
19 changes: 17 additions & 2 deletions src/DependencyInjection/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,28 @@
*/
class ProviderFactory
{
private $generator;

/** @var UrlGeneratorInterface */
protected $generator;

/**
* ProviderFactory constructor.
*
* @param UrlGeneratorInterface $generator
*/
public function __construct(UrlGeneratorInterface $generator)
{
$this->generator = $generator;
}

/**
* Creates a provider of the given class.
*
* @param string $class
* @param array $options
* @param string $redirectUri
* @param array $redirectParams
* @return mixed
*/
public function createProvider($class, array $options, $redirectUri, array $redirectParams = [])
{
$redirectUri = $this->generator
Expand Down
8 changes: 4 additions & 4 deletions src/Security/Exception/FinishRegistrationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class FinishRegistrationException extends AuthenticationException
private $userInformation;

/**
* @param mixed $userInfo Any info to be used to help registration
* @param string $message
* @param int $code
* @param \Exception $previous
* @param mixed $userInfo Any info to be used to help registration
* @param string $message
* @param int $code
* @param \Exception $previous
*/
public function __construct($userInfo, $message = '', $code = 0, Exception $previous = null)
{
Expand Down
24 changes: 24 additions & 0 deletions tests/DependencyInjection/KnpUOAuth2ClientExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace KnpU\OAuth2ClientBundle\Tests\DependencyInjection;

use KnpU\OAuth2ClientBundle\DependencyInjection\KnpUOAuth2ClientExtension;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\ProviderConfiguratorInterface;
use Symfony\Component\Config\Definition\ArrayNode;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\NodeInterface;
Expand Down Expand Up @@ -81,6 +82,29 @@ public function testFacebookProviderMakesService()
);
}

/**
* @dataProvider getAllProviderConfigurators
*/
public function testProviderConfiguratorsAreFullyImplemented(ProviderConfiguratorInterface $providerConfigurator)
{
$this->assertRegexp('#^[ \w]+$#', $providerConfigurator->getProviderDisplayName());
if ('Generic' !== $providerConfigurator->getProviderDisplayName()) {
$this->assertRegexp('#^[\w-]+/[\w-]+$#', $providerConfigurator->getPackagistName());
$this->assertNotFalse(filter_var($providerConfigurator->getLibraryHomepage(), FILTER_VALIDATE_URL));
$this->assertTrue(class_exists($providerConfigurator->getClientClass([])));
}
}

public function getAllProviderConfigurators()
{
$extension = new KnpUOAuth2ClientExtension();
$configurators = [];
foreach (KnpUOAuth2ClientExtension::getAllSupportedTypes() as $type) {
$configurators[$type] = [$extension->getConfigurator($type)];
}
return $configurators;
}

/**
* @dataProvider provideTypesAndConfig
*/
Expand Down