10000 Add tests · symfony/symfony@038825f · GitHub
[go: up one dir, main page]

Skip to content

Commit 038825f

Browse files
committed
Add tests
1 parent 6b708b7 commit 038825f

File tree

8 files changed

+230
-0
lines changed

8 files changed

+230
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\Authenticator;
4+
5+
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
6+
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
9+
class CustomAuthenticator implements AuthenticatorFactoryInterface
10+
{
11+
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
12+
{
13+
return 'security.authenticator.custom.'.$firewallName;
14+
}
15+
16+
public function getKey(): string
17+
{
18+
return 'custom';
19+
}
20+
21+
public function addConfiguration(NodeDefinition $builder)
22+
{
23+
}
24+
25+
public function getPriority(): int
26+
{
27+
return 0;
28+
}
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider;
4+
5+
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
6+
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
9+
class CustomProvider implements UserProviderFactoryInterface
10+
{
11+
public function create(ContainerBuilder $container, string $id, array $config)
12+
{
13+
}
14+
15+
public function getKey(): string
16+
{
17+
return 'custom';
18+
}
19+
20+
public function addConfiguration(NodeDefinition $builder)
21+
{
22+
$builder
23+
->children()
24+
->scalarNode('foo')->defaultValue('bar')->end()
25+
->end()
26+
;
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:sec="http://symfony.com/schema/dic/security"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services
7+
https://symfony.com/schema/dic/services/services-1.0.xsd
8+
http://symfony.com/schema/dic/security
9+
https://symfony.com/schema/dic/security/security-1.0.xsd">
10+
11+
<sec:config enable-authenticator-manager="true">
12+
<sec:firewall name="main">
13+
<custom xmlns="http://example.com/schema" />
14+
</sec:firewall>
15+
</sec:config>
16+
17+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:sec="http://symfony.com/schema/dic/security"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services
7+
https://symfony.com/schema/dic/services/services-1.0.xsd
8+
http://symfony.com/schema/dic/security
9+
https://symfony.com/schema/dic/security/security-1.0.xsd">
10+
11+
<sec:config enable-authenticator-manager="true">
12+
<sec:firewall name="main">
13+
<sec:custom />
14+
</sec:firewall>
15+
</sec:config>
16+
17+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:sec="http://symfony.com/schema/dic/security"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services
7+
https://symfony.com/schema/dic/services/services-1.0.xsd
8+
http://symfony.com/schema/dic/security
9+
https://symfony.com/schema/dic/security/security-1.0.xsd">
10+
11+
<sec:config enable-authenticator-manager="true">
12+
<sec:provider name="foo">
13+
<custom xmlns="http://example.com/schema" />
14+
</sec:provider>
15+
16+
<sec:firewall name="main" provider="foo" />
17+
</sec:config>
18+
19+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:sec="http://symfony.com/schema/dic/security"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services
7+
https://symfony.com/schema/dic/services/services-1.0.xsd
8+
http://symfony.com/schema/dic/security
9+
https://symfony.com/schema/dic/security/security-1.0.xsd">
10+
11+
<sec:config enable-authenticator-manager="true">
12+
<sec:provider name="foo">
13+
<sec:custom />
14+
</sec:provider>
15+
16+
<sec:firewall name="main" provider="foo" />
17+
</sec:config>
18+
19+
</container>
Lines changed: 51 additions & 0 deletions
< E41F tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
16+
use Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\Authenticator\CustomAuthenticator;
17+
use Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider\CustomProvider;
18+
use Symfony\Component\Config\FileLocator;
19+
use Symfony\Component\DependencyInjection\ContainerBuilder;
20+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
21+
22+
class XmlCustomAuthenticatorTest extends TestCase
23+
{
24+
/**
25+
* @dataProvider provideXmlConfigurationFile
26+
*/
27+
public function testCustomProviderElement(string $configurationFile)
28+
{
29+
$container = new ContainerBuilder();
30+
$container->setParameter('kernel.debug', false);
31+
$container->register('cache.system', \stdClass::class);
32+
33+
$security = new SecurityExtension();
34+
$security->addAuthenticatorFactory(new CustomAuthenticator());
35+
$container->registerExtension($security);
36+
37+
(new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml')))->load($configurationFile);
38+
39+
$container->getCompilerPassConfig()->setRemovingPasses([]);
40+
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
41+
$container->compile();
42+
43+
$this->addToAssertionCount(1);
44+
}
45+
46+
public static function provideXmlConfigurationFile(): iterable
47+
{
48+
yield 'Custom authenticator element under SecurityBundle’s namespace' => ['custom_authenticator_under_security_namespace.xml'];
49+
yield 'Custom authenticator element under its own namespace' => ['custom_authenticator_under_own_namespace.xml'];
50+
}
51+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
16+
use Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider\CustomProvider;
17+
use Symfony\Component\Config\FileLocator;
18+
use Symfony\Component\DependencyInjection\ContainerBuilder;
19+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
20+
21+
class XmlCustomProviderTest extends TestCase
22+
{
23+
/**
24+
* @dataProvider provideXmlConfigurationFile
25+
*/
26+
public function testCustomProviderElement(string $configurationFile)
27+
{
28+
$container = new ContainerBuilder();
29+
$container->setParameter('kernel.debug', false);
ABAB 30+
$container->register('cache.system', \stdClass::class);
31+
32+
$security = new SecurityExtension();
33+
$security->addUserProviderFactory(new CustomProvider());
34+
$container->registerExtension($security);
35+
36+
(new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml')))->load($configurationFile);
37+
38+
$container->getCompilerPassConfig()->setRemovingPasses([]);
39+
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
40+
$container->compile();
41+
42+
$this->addToAssertionCount(1);
43+
}
44+
45+
public static function provideXmlConfigurationFile(): iterable
46+
{
47+
yield 'Custom provider element under SecurityBundle’s namespace' => ['custom_provider_under_security_namespace.xml'];
48+
yield 'Custom provider element under its own namespace' => ['custom_provider_under_own_namespace.xml'];
49+
}
50+
}

0 commit comments

Comments
 (0)
0