Skip to content

Commit

Permalink
Merge pull request #34 from nucleos/dev
Browse files Browse the repository at this point in the history
Add noop driver to allow flex recipe
  • Loading branch information
core23 authored Feb 1, 2020
2 parents 81bffe3 + 1248b1d commit cdbeb14
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 62 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@
"cs": "PHP_CS_FIXER_IGNORE_ENV=1 && vendor/bin/php-cs-fixer fix --verbose",
"cs-diff": "PHP_CS_FIXER_IGNORE_ENV=1 && vendor/bin/php-cs-fixer fix --verbose --diff --diff-format=udiff --dry-run",
"deps": "vendor/bin/composer-require-checker check --config-file composer-require.json composer.json",
"infection": "vendor/bin/infection --ignore-msi-with-no-mutations --min-covered-msi=65 --min-msi=35",
"infection": "vendor/bin/infection --ignore-msi-with-no-mutations --min-covered-msi=64 --min-msi=34",
"lint": [
"find ./src \\( -name '*.xml' -or -name '*.xml.dist' -or -name '*.xlf' \\) -type f -exec xmllint --encode UTF-8 --output '{}' --format '{}' \\;",
"find ./src \\( -name '*.yml' -or -name '*.yaml' \\) -not -path '*/vendor/*' | xargs yaml-lint"
],
"phpstan": "vendor/bin/phpstan analyse",
"test": "vendor/bin/phpunit --colors=always --coverage-clover build/logs/clover.xml"
"test": "vendor/bin/phpunit --colors=always"
}
}
25 changes: 10 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ parameters:
count: 1
path: src/DependencyInjection/NucleosUserExtension.php

-
message: "#^Method Nucleos\\\\UserBundle\\\\DependencyInjection\\\\NucleosUserExtension\\:\\:load\\(\\) has parameter \\$configs with no value type specified in iterable type array\\.$#"
count: 1
path: src/DependencyInjection/NucleosUserExtension.php

-
message: "#^Method Nucleos\\\\UserBundle\\\\DependencyInjection\\\\NucleosUserExtension\\:\\:remapParameters\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -210,16 +205,6 @@ parameters:
count: 2
path: src/EventListener/LocaleEventListener.php

-
message: "#^Method Nucleos\\\\UserBundle\\\\Form\\\\Type\\\\ChangePasswordFormType\\:\\:buildForm\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Form/Type/ChangePasswordFormType.php

-
message: "#^Method Nucleos\\\\UserBundle\\\\Form\\\\Type\\\\ResettingFormType\\:\\:buildForm\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Form/Type/ResettingFormType.php

-
message: "#^Method Nucleos\\\\UserBundle\\\\Model\\\\Group\\:\\:__construct\\(\\) has parameter \\$roles with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -255,6 +240,16 @@ parameters:
count: 1
path: src/Model/UserManagerInterface.php

-
message: "#^Method Nucleos\\\\UserBundle\\\\Noop\\\\GroupManager\\:\\:findGroupBy\\(\\) has parameter \\$criteria with no value type specified in iterable type array\\.$#"
count: 1
path: src/Noop/GroupManager.php

-
message: "#^Method Nucleos\\\\UserBundle\\\\Noop\\\\UserManager\\:\\:findUserBy\\(\\) has parameter \\$criteria with no value type specified in iterable type array\\.$#"
count: 1
path: src/Noop/UserManager.php

-
message: "#^Method Nucleos\\\\UserBundle\\\\Security\\\\UserProvider\\:\\:loadUserByUsername\\(\\) has parameter \\$username with no typehint specified\\.$#"
count: 1
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getConfigTreeBuilder(): TreeBuilder

$rootNode = $treeBuilder->getRootNode();

$supportedDrivers = ['orm', 'mongodb', 'custom'];
$supportedDrivers = ['noop', 'orm', 'mongodb', 'custom'];

$rootNode
->children()
Expand All @@ -35,7 +35,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($supportedDrivers))
->end()
->cannotBeOverwritten()
->isRequired()
->defaultValue('noop')
->cannotBeEmpty()
->end()
->scalarNode('user_class')->isRequired()->cannotBeEmpty()->end()
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/NucleosUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function prepend(ContainerBuilder $container): void

$storage = $container->getParameter('nucleos_user.storage');

if ('custom' === $storage) {
if (!\in_array($storage, ['orm', 'mongodb'], true)) {
return;
}

Expand Down
3 changes: 0 additions & 3 deletions src/Doctrine/UserListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public function __construct(PasswordUpdaterInterface $passwordUpdater, Canonical
$this->canonicalFieldsUpdater = $canonicalFieldsUpdater;
}

/**
* @return string[]
*/
public function getSubscribedEvents(): array
{
return [
Expand Down
3 changes: 0 additions & 3 deletions src/EventListener/AuthenticationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public function __construct(LoginManagerInterface $loginManager, string $firewal
$this->firewallName = $firewallName;
}

/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
Expand Down
3 changes: 0 additions & 3 deletions src/EventListener/FlashListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public function __construct(FlashBagInterface $flashBag, TranslatorInterface $tr
$this->translator = $translator;
}

/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
Expand Down
3 changes: 0 additions & 3 deletions src/EventListener/LastLoginListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public function __construct(UserManagerInterface $userManager)
$this->userManager = $userManager;
}

/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
Expand Down
3 changes: 0 additions & 3 deletions src/EventListener/LocaleEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public function __construct(LocaleAwareTranslator $translator, Environment $twig
$this->twig = $twig;
}

/**
* @return array<string, mixed>
*/
public static function getSubscribedEvents(): array
{
return [
Expand Down
3 changes: 0 additions & 3 deletions src/EventListener/ResettingListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public function __construct(UrlGeneratorInterface $router, int $tokenTtl)
$this->tokenTtl = $tokenTtl;
}

/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
Expand Down
27 changes: 27 additions & 0 deletions src/Noop/Exception/NoDriverException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the NucleosUserBundle package.
*
* (c) Christian Gripp <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nucleos\UserBundle\Noop\Exception;

use Exception;
use RuntimeException;

final class NoDriverException extends RuntimeException
{
public function __construct(?string $message = null, int $code = 0, Exception $previous = null)
{
parent::__construct(
null === $message ? 'The child node "db_driver" at path "nucleos_user" must be configured.' : $message,
$code,
$previous
);
}
}
51 changes: 51 additions & 0 deletions src/Noop/GroupManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

/*
* This file is part of the NucleosUserBundle package.
*
* (c) Christian Gripp <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nucleos\UserBundle\Noop;

use Nucleos\UserBundle\Model\GroupInterface;
use Nucleos\UserBundle\Model\GroupManager as BaseGroupManager;
use Nucleos\UserBundle\Model\GroupTemplate;
use Nucleos\UserBundle\Noop\Exception\NoDriverException;

/**
* @phpstan-template GroupTemplate of \Nucleos\UserBundle\Model\GroupInterface
* @phpstan-extends \Nucleos\UserBundle\Model\GroupManager<GroupTemplate>
*/
final class GroupManager extends BaseGroupManager
{
public function deleteGroup(GroupInterface $group): void
{
throw new NoDriverException();
}

public function findGroupBy(array $criteria): GroupInterface
{
throw new NoDriverException();
}

public function findGroups(): array
{
throw new NoDriverException();
}

public function getClass(): string
{
throw new NoDriverException();
}

public function updateGroup(GroupInterface $group, bool $andFlush = true): void
{
throw new NoDriverException();
}
}
25 changes: 25 additions & 0 deletions src/Noop/UserListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

/*
* This file is part of the NucleosUserBundle package.
*
* (c) Christian Gripp <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nucleos\UserBundle\Noop;

use Doctrine\Common\EventSubscriber;

final class UserListener implements EventSubscriber
{
public function getSubscribedEvents(): array
{
return [
];
}
}
51 changes: 51 additions & 0 deletions src/Noop/UserManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

/*
* This file is part of the NucleosUserBundle package.
*
* (c) Christian Gripp <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nucleos\UserBundle\Noop;

use Nucleos\UserBundle\Model\UserInterface;
use Nucleos\UserBundle\Model\UserManager as BaseUserManager;
use Nucleos\UserBundle\Noop\Exception\NoDriverException;

final class UserManager extends BaseUserManager
{
public function deleteUser(UserInterface $user): void
{
throw new NoDriverException();
}

public function findUserBy(array $criteria): ?UserInterface
{
throw new NoDriverException();
}

public function findUsers(): array
{
throw new NoDriverException();
}

public function getClass(): string
{
throw new NoDriverException();
}

public function reloadUser(UserInterface $user): void
{
throw new NoDriverException();
}

public function updateUser(UserInterface $user, bool $andFlush = true): void
{
throw new NoDriverException();
}
}
11 changes: 11 additions & 0 deletions src/Resources/config/noop.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="nucleos_user.user_manager.default" class="Nucleos\UserBundle\Noop\UserManager">
<argument type="service" id="nucleos_user.util.password_updater"/>
<argument type="service" id="nucleos_user.util.canonical_fields_updater"/>
</service>
<service id="nucleos_user.user_listener" class="Nucleos\UserBundle\Noop\UserListener">
</service>
</services>
</container>
7 changes: 7 additions & 0 deletions src/Resources/config/noop_group.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="nucleos_user.group_manager.default" class="Nucleos\UserBundle\Noop\GroupManager">
</service>
</services>
</container>
2 changes: 0 additions & 2 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Nucleos\UserBundle\Tests\App;

use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Nucleos\UserBundle\NucleosUserBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
Expand All @@ -38,7 +37,6 @@ public function registerBundles()
yield new FrameworkBundle();
yield new TwigBundle();
yield new SecurityBundle();
yield new DoctrineBundle();
yield new NucleosUserBundle();
}

Expand Down
12 changes: 0 additions & 12 deletions tests/App/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@ framework:
storage_id: session.storage.mock_file
handler_id: session.handler.native_file

doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_sqlite
memory: true

orm:
auto_mapping: true

nucleos_user:
db_driver: orm
firewall_name: main

from_email: 'no-reply@localhost'
Expand Down
10 changes: 0 additions & 10 deletions tests/DependencyInjection/NucleosUserExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ final class NucleosUserExtensionTest extends TestCase
*/
protected $configuration;

public function testUserLoadThrowsExceptionUnlessDatabaseDriverSet(): void
{
$this->expectException(InvalidConfigurationException::class);

$loader = new NucleosUserExtension();
$config = $this->getEmptyConfig();
unset($config['db_driver']);
$loader->load([$config], new ContainerBuilder());
}

public function testUserLoadThrowsExceptionUnlessDatabaseDriverIsValid(): void
{
$this->expectException(InvalidConfigurationException::class);
Expand Down

0 comments on commit cdbeb14

Please sign in to comment.