|
| 1 | +<?php |
| 2 | +namespace FOS\OAuthServerBundle\Tests\DependencyInjection; |
| 3 | + |
| 4 | +use FOS\OAuthServerBundle\DependencyInjection\Configuration; |
| 5 | +use Symfony\Component\Config\Definition\ConfigurationInterface; |
| 6 | +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
| 7 | +use Symfony\Component\Config\Definition\Processor; |
| 8 | + |
| 9 | +class ConfigurationTest extends \PHPUnit_Framework_TestCase |
| 10 | +{ |
| 11 | + public function testShouldImplementConfigurationInterface() |
| 12 | + { |
| 13 | + $rc = new \ReflectionClass(Configuration::class); |
| 14 | + |
| 15 | + $this->assertTrue($rc->implementsInterface(ConfigurationInterface::class)); |
| 16 | + } |
| 17 | + public function testCouldBeConstructedWithoutAnyArguments() |
| 18 | + { |
| 19 | + new Configuration(); |
| 20 | + } |
| 21 | + |
| 22 | + public function testShouldNotMandatoryServiceIfNotCustomDriverIsUsed() |
| 23 | + { |
| 24 | + $configuration = new Configuration(); |
| 25 | + $processor = new Processor(); |
| 26 | + |
| 27 | + $config = $processor->processConfiguration($configuration, [[ |
| 28 | + 'db_driver' => 'orm', |
| 29 | + 'client_class' => 'aClientClass', |
| 30 | + 'access_token_class' => 'anAccessTokenClass', |
| 31 | + 'refresh_token_class' => 'aRefreshTokenClass', |
| 32 | + 'auth_code_class' => 'anAuthCodeClass', |
| 33 | + ]]); |
| 34 | + |
| 35 | + $this->assertArraySubset([ |
| 36 | + "db_driver" => "orm", |
| 37 | + "client_class" => "aClientClass", |
| 38 | + "access_token_class" => "anAccessTokenClass", |
| 39 | + "refresh_token_class" => "aRefreshTokenClass", |
| 40 | + "auth_code_class" => "anAuthCodeClass", |
| 41 | + "service" => [ |
| 42 | + "storage" => "fos_oauth_server.storage.default", |
| 43 | + "user_provider" => null, |
| 44 | + "client_manager" => "fos_oauth_server.client_manager.default", |
| 45 | + "access_token_manager" => "fos_oauth_server.access_token_manager.default", |
| 46 | + "refresh_token_manager" => "fos_oauth_server.refresh_token_manager.default", |
| 47 | + "auth_code_manager" => "fos_oauth_server.auth_code_manager.default", |
| 48 | + ], |
| 49 | + ], $config); |
| 50 | + } |
| 51 | + |
| 52 | + public function testShouldMakeClientManagerServiceMandatoryIfCustomDriverIsUsed() |
| 53 | + { |
| 54 | + $configuration = new Configuration(); |
| 55 | + $processor = new Processor(); |
| 56 | + |
| 57 | + $this->setExpectedException(InvalidConfigurationException::class, 'Invalid configuration for path "fos_oauth_server": The service client_manager must be set explicitly for custom db_driver.'); |
| 58 | + |
| 59 | + $processor->processConfiguration($configuration, [[ |
| 60 | + 'db_driver' => 'custom', |
| 61 | + 'client_class' => 'aClientClass', |
| 62 | + 'access_token_class' => 'anAccessTokenClass', |
| 63 | + 'refresh_token_class' => 'aRefreshTokenClass', |
| 64 | + 'auth_code_class' => 'anAuthCodeClass', |
| 65 | + |
| 66 | + ]]); |
| 67 | + } |
| 68 | + |
| 69 | + public function testShouldMakeAccessTokenManagerServiceMandatoryIfCustomDriverIsUsed() |
| 70 | + { |
| 71 | + $configuration = new Configuration(); |
| 72 | + $processor = new Processor(); |
| 73 | + |
| 74 | + $this->setExpectedException(InvalidConfigurationException::class, 'Invalid configuration for path "fos_oauth_server": The service access_token_manager must be set explicitly for custom db_driver.'); |
| 75 | + |
| 76 | + $processor->processConfiguration($configuration, [[ |
| 77 | + 'db_driver' => 'custom', |
| 78 | + 'client_class' => 'aClientClass', |
| 79 | + 'access_token_class' => 'anAccessTokenClass', |
| 80 | + 'refresh_token_class' => 'aRefreshTokenClass', |
| 81 | + 'auth_code_class' => 'anAuthCodeClass', |
| 82 | + 'service' => [ |
| 83 | + 'client_manager' => 'a_client_manager_id' |
| 84 | + ] |
| 85 | + ]]); |
| 86 | + } |
| 87 | + |
| 88 | + public function testShouldMakeRefreshTokenManagerServiceMandatoryIfCustomDriverIsUsed() |
| 89 | + { |
| 90 | + $configuration = new Configuration(); |
| 91 | + $processor = new Processor(); |
| 92 | + |
| 93 | + $this->setExpectedException(InvalidConfigurationException::class, 'Invalid configuration for path "fos_oauth_server": The service refresh_token_manager must be set explicitly for custom db_driver.'); |
| 94 | + |
| 95 | + $processor->processConfiguration($configuration, [[ |
| 96 | + 'db_driver' => 'custom', |
| 97 | + 'client_class' => 'aClientClass', |
| 98 | + 'access_token_class' => 'anAccessTokenClass', |
| 99 | + 'refresh_token_class' => 'aRefreshTokenClass', |
| 100 | + 'auth_code_class' => 'anAuthCodeClass', |
| 101 | + 'service' => [ |
| 102 | + 'client_manager' => 'a_client_manager_id', |
| 103 | + 'access_token_manager' => 'anId', |
| 104 | + ] |
| 105 | + ]]); |
| 106 | + } |
| 107 | + |
| 108 | + public function testShouldMakeAuthCodeManagerServiceMandatoryIfCustomDriverIsUsed() |
| 109 | + { |
| 110 | + $configuration = new Configuration(); |
| 111 | + $processor = new Processor(); |
| 112 | + |
| 113 | + $this->setExpectedException(InvalidConfigurationException::class, 'Invalid configuration for path "fos_oauth_server": The service auth_code_manager must be set explicitly for custom db_driver.'); |
| 114 | + |
| 115 | + $processor->processConfiguration($configuration, [[ |
| 116 | + 'db_driver' => 'custom', |
| 117 | + 'client_class' => 'aClientClass', |
| 118 | + 'access_token_class' => 'anAccessTokenClass', |
| 119 | + 'refresh_token_class' => 'aRefreshTokenClass', |
| 120 | + 'auth_code_class' => 'anAuthCodeClass', |
| 121 | + 'service' => [ |
| 122 | + 'client_manager' => 'a_client_manager_id', |
| 123 | + 'access_token_manager' => 'anId', |
| 124 | + 'refresh_token_manager' => 'anId', |
| 125 | + |
| 126 | + ] |
| 127 | + ]]); |
| 128 | + } |
| 129 | + |
| 130 | + public function testShouldLoadCustomDriverConfig() |
| 131 | + { |
| 132 | + $configuration = new Configuration(); |
| 133 | + $processor = new Processor(); |
| 134 | + |
| 135 | + $config = $processor->processConfiguration($configuration, [[ |
| 136 | + 'db_driver' => 'custom', |
| 137 | + 'client_class' => 'aClientClass', |
| 138 | + 'access_token_class' => 'anAccessTokenClass', |
| 139 | + 'refresh_token_class' => 'aRefreshTokenClass', |
| 140 | + 'auth_code_class' => 'anAuthCodeClass', |
| 141 | + 'service' => [ |
| 142 | + 'client_manager' => 'a_client_manager_id', |
| 143 | + 'access_token_manager' => 'an_access_token_manager_id', |
| 144 | + 'refresh_token_manager' => 'a_refresh_token_manager_id', |
| 145 | + 'auth_code_manager' => 'an_auth_code_manager_id', |
| 146 | + ] |
| 147 | + ]]); |
| 148 | + |
| 149 | + $this->assertArraySubset([ |
| 150 | + "db_driver" => "custom", |
| 151 | + "client_class" => "aClientClass", |
| 152 | + "access_token_class" => "anAccessTokenClass", |
| 153 | + "refresh_token_class" => "aRefreshTokenClass", |
| 154 | + "auth_code_class" => "anAuthCodeClass", |
| 155 | + "service" => [ |
| 156 | + "storage" => "fos_oauth_server.storage.default", |
| 157 | + "user_provider" => null, |
| 158 | + "client_manager" => "a_client_manager_id", |
| 159 | + "access_token_manager" => "an_access_token_manager_id", |
| 160 | + "refresh_token_manager" => "a_refresh_token_manager_id", |
| 161 | + "auth_code_manager" => "an_auth_code_manager_id", |
| 162 | + ], |
| 163 | + ], $config); |
| 164 | + } |
| 165 | +} |
0 commit comments