azine /
email-bundle
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Azine\EmailBundle\Tests\DependencyInjection; |
||
| 4 | |||
| 5 | use Azine\EmailBundle\DependencyInjection\AzineEmailExtension; |
||
| 6 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
| 7 | use Symfony\Component\Yaml\Yaml; |
||
| 8 | |||
| 9 | class AzineEmailExtensionTest extends \PHPUnit\Framework\TestCase |
||
| 10 | { |
||
| 11 | /** @var ContainerBuilder */ |
||
| 12 | protected $configuration; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * This should not throw an exception. |
||
| 16 | */ |
||
| 17 | public function testMinimalConfig() |
||
| 18 | { |
||
| 19 | $loader = new AzineEmailExtension(); |
||
| 20 | $config = $this->getMinimalConfig(); |
||
| 21 | $loader->load(array($config), new ContainerBuilder()); |
||
| 22 | $this->assertTrue(true, 'Without this stupid assertion, PHPUnit classifies this test as risky'); |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * This should not throw an exception. |
||
| 27 | */ |
||
| 28 | public function testFullConfig() |
||
| 29 | { |
||
| 30 | $loader = new AzineEmailExtension(); |
||
| 31 | $config = $this->getFullConfig(); |
||
| 32 | $loader->load(array($config), new ContainerBuilder()); |
||
| 33 | $this->assertTrue(true, 'Without this stupid assertion, PHPUnit classifies this test as risky'); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * This should throw an exception. |
||
| 38 | * |
||
| 39 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 40 | */ |
||
| 41 | public function testConfigWithMissingRecipientClass() |
||
| 42 | { |
||
| 43 | $loader = new AzineEmailExtension(); |
||
| 44 | $config = $this->getFullConfig(); |
||
| 45 | unset($config['recipient_class']); |
||
| 46 | $loader->load(array($config), new ContainerBuilder()); |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * This should throw an exception. |
||
| 51 | * |
||
| 52 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 53 | */ |
||
| 54 | public function testConfigWithMissingTemplateProvider() |
||
| 55 | { |
||
| 56 | $loader = new AzineEmailExtension(); |
||
| 57 | $config = $this->getFullConfig(); |
||
| 58 | unset($config['template_provider']); |
||
| 59 | $loader->load(array($config), new ContainerBuilder()); |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * This should throw an exception. |
||
| 64 | * |
||
| 65 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 66 | */ |
||
| 67 | public function testConfigWithMissingEmailAddress() |
||
| 68 | { |
||
| 69 | $loader = new AzineEmailExtension(); |
||
| 70 | $config = $this->getFullConfig(); |
||
| 71 | unset($config['no_reply']['email']); |
||
| 72 | $loader->load(array($config), new ContainerBuilder()); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * This should throw an exception. |
||
| 77 | * |
||
| 78 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 79 | */ |
||
| 80 | public function testConfigWithMissingEmailName() |
||
| 81 | { |
||
| 82 | $loader = new AzineEmailExtension(); |
||
| 83 | $config = $this->getFullConfig(); |
||
| 84 | unset($config['no_reply']['name']); |
||
| 85 | $loader->load(array($config), new ContainerBuilder()); |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * This should throw an exception. |
||
| 90 | * |
||
| 91 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 92 | */ |
||
| 93 | public function testConfigWithMissingEmail() |
||
| 94 | { |
||
| 95 | $loader = new AzineEmailExtension(); |
||
| 96 | $config = $this->getFullConfig(); |
||
| 97 | unset($config['no_reply']); |
||
| 98 | $loader->load(array($config), new ContainerBuilder()); |
||
| 99 | } |
||
| 100 | |||
| 101 | public function testCustomConfiguration() |
||
| 102 | { |
||
| 103 | $this->configuration = new ContainerBuilder(); |
||
| 104 | $loader = new AzineEmailExtension(); |
||
| 105 | $config = $this->getFullConfig(); |
||
| 106 | $config['recipient_class'] = 'TestRecipientClass'; |
||
| 107 | $config['recipient_newsletter_field'] = 'some_field'; |
||
| 108 | $config['template_provider'] = 'TestTemplateProvider'; |
||
| 109 | $config['notifier_service'] = 'TestNotifierService'; |
||
| 110 | $config['recipient_provider'] = 'TestRecipientService'; |
||
| 111 | $config['template_twig_swift_mailer'] = 'TestTwigSwiftMailer'; |
||
| 112 | $config['no_reply']['email'] = '[email protected]'; |
||
| 113 | $config['no_reply']['name'] = 'test name'; |
||
| 114 | $config['image_dir'] = '/tmp'; |
||
| 115 | |||
| 116 | $loader->load(array($config), $this->configuration); |
||
| 117 | |||
| 118 | $this->assertParameter('TestRecipientClass', 'azine_email_recipient_class'); |
||
| 119 | $this->assertParameter('some_field', 'azine_email_recipient_newsletter_field'); |
||
| 120 | |||
| 121 | $mailArray = $this->configuration->getParameter('azine_email_no_reply'); |
||
| 122 | $this->assertSame('test name', $mailArray['name'], 'The no-reply-name is not correct.'); |
||
| 123 | $this->assertSame('[email protected]', $mailArray['email'], 'The no-reply-email is not correct.'); |
||
| 124 | |||
| 125 | $this->assertParameter('/tmp', 'azine_email_image_dir'); |
||
| 126 | |||
| 127 | $this->assertAlias('testtemplateprovider', 'azine_email_template_provider'); |
||
| 128 | $this->assertAlias('testnotifierservice', 'azine_email_notifier_service'); |
||
| 129 | $this->assertAlias('testrecipientservice', 'azine_email_recipient_provider'); |
||
| 130 | $this->assertAlias('testtwigswiftmailer', 'azine_email_template_twig_swift_mailer'); |
||
| 131 | } |
||
| 132 | |||
| 133 | protected function createEmptyConfiguration() |
||
| 134 | { |
||
| 135 | $this->configuration = new ContainerBuilder(); |
||
| 136 | $loader = new AzineEmailExtension(); |
||
| 137 | $config = $this->getEmptyConfig(); |
||
|
0 ignored issues
–
show
|
|||
| 138 | $loader->load(array($config), $this->configuration); |
||
| 139 | $this->assertTrue($this->configuration instanceof ContainerBuilder); |
||
| 140 | } |
||
| 141 | |||
| 142 | protected function createFullConfiguration() |
||
| 143 | { |
||
| 144 | $this->configuration = new ContainerBuilder(); |
||
| 145 | $loader = new AzineEmailExtension(); |
||
| 146 | $config = $this->getFullConfig(); |
||
| 147 | $loader->load(array($config), $this->configuration); |
||
| 148 | $this->assertTrue($this->configuration instanceof ContainerBuilder); |
||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Get the minimal config. |
||
| 153 | * |
||
| 154 | * @return array |
||
| 155 | */ |
||
| 156 | protected function getMinimalConfig() |
||
| 157 | { |
||
| 158 | $yaml = <<<YAML |
||
| 159 | recipient_class: 'Azine\\PlatformBundle\\Entity\\User' |
||
| 160 | template_provider: 'azine_platform.emailtemplateprovider' |
||
| 161 | no_reply: |
||
| 162 | email: '[email protected]' |
||
| 163 | name: 'azine.me notification daemon' |
||
| 164 | YAML; |
||
| 165 | |||
| 166 | return Yaml::parse($yaml); |
||
|
0 ignored issues
–
show
|
|||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Get a full config for this bundle. |
||
| 171 | */ |
||
| 172 | protected function getFullConfig() |
||
| 173 | { |
||
| 174 | $yaml = <<<YAML |
||
| 175 | recipient_class: 'Acme\\SomeBundle\\Entity\\User' |
||
| 176 | recipient_newsletter_field: 'newsletter' |
||
| 177 | notifier_service: 'azine_email.example.notifier_service' |
||
| 178 | template_provider: 'azine_email.example.template_provider' |
||
| 179 | recipient_provider: 'azine_email.default.recipient_provider' |
||
| 180 | template_twig_swift_mailer: 'azine_email.default.template_twig_swift_mailer' |
||
| 181 | no_reply: |
||
| 182 | email: '[email protected]' |
||
| 183 | name: 'notification daemon' |
||
| 184 | image_dir: '%kernel.root_dir%/../vendor/azine/email-bundle/Azine/EmailBundle/Resources/htmlTemplateImages/' |
||
| 185 | allowed_images_folders: |
||
| 186 | - '%kernel.root_dir%/../vendor/azine/email-bundle/Azine/EmailBundle/Resources/htmlTemplateImages/' |
||
| 187 | - '%kernel.root_dir%/../vendor/azine/email-bundle/Azine/EmailBundle/Resources/' |
||
| 188 | YAML; |
||
| 189 | |||
| 190 | return Yaml::parse($yaml); |
||
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @param string $value |
||
| 195 | * @param string $key |
||
| 196 | */ |
||
| 197 | private function assertAlias($value, $key) |
||
| 198 | { |
||
| 199 | $this->assertSame(strtolower($value), strtolower((string) $this->configuration->getAlias($key)), sprintf('%s alias is correct', $key)); |
||
| 200 | } |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param string $value |
||
| 204 | * @param string $key |
||
| 205 | */ |
||
| 206 | private function assertParameter($value, $key) |
||
| 207 | { |
||
| 208 | $this->assertSame($value, $this->configuration->getParameter($key), sprintf('%s parameter is correct', $key)); |
||
| 209 | } |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @param string $id |
||
| 213 | */ |
||
| 214 | private function assertHasDefinition($id) |
||
|
0 ignored issues
–
show
|
|||
| 215 | { |
||
| 216 | $this->assertTrue(($this->configuration->hasDefinition($id) ?: $this->configuration->hasAlias($id))); |
||
| 217 | } |
||
| 218 | |||
| 219 | /** |
||
| 220 | * @param string $id |
||
| 221 | */ |
||
| 222 | private function assertNotHasDefinition($id) |
||
|
0 ignored issues
–
show
|
|||
| 223 | { |
||
| 224 | $this->assertFalse(($this->configuration->hasDefinition($id) ?: $this->configuration->hasAlias($id))); |
||
| 225 | } |
||
| 226 | |||
| 227 | protected function tearDown() |
||
| 228 | { |
||
| 229 | unset($this->configuration); |
||
| 230 | } |
||
| 231 | } |
||
| 232 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.