|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Sentry\SentryBundle\Test\DependencyInjection; |
| 4 | + |
| 5 | +use Sentry\SentryBundle\DependencyInjection\SentryExtension; |
| 6 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 7 | + |
| 8 | +class ExtensionTest extends \PHPUnit_Framework_TestCase |
| 9 | +{ |
| 10 | + const CONFIG_ROOT = 'sentry'; |
| 11 | + |
| 12 | + public function test_that_it_uses_kernel_root_as_app_path_by_default() |
| 13 | + { |
| 14 | + $container = $this->getContainer(); |
| 15 | + |
| 16 | + $this->assertSame( |
| 17 | + 'kernel/root', |
| 18 | + $container->getParameter('sentry.app_path') |
| 19 | + ); |
| 20 | + } |
| 21 | + |
| 22 | + public function test_that_it_uses_app_path_value() |
| 23 | + { |
| 24 | + $container = $this->getContainer([ |
| 25 | + static::CONFIG_ROOT => array( |
| 26 | + 'app_path' => 'sentry/app/path', |
| 27 | + ), |
| 28 | + ]); |
| 29 | + |
| 30 | + $this->assertSame( |
| 31 | + 'sentry/app/path', |
| 32 | + $container->getParameter('sentry.app_path') |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + public function test_that_it_uses_defined_class_as_client_class_by_default() |
| 37 | + { |
| 38 | + $container = $this->getContainer(); |
| 39 | + |
| 40 | + $this->assertSame( |
| 41 | + 'Sentry\SentryBundle\SentrySymfonyClient', |
| 42 | + $container->getParameter('sentry.client') |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + public function test_that_it_uses_client_value() |
| 47 | + { |
| 48 | + $container = $this->getContainer([ |
| 49 | + static::CONFIG_ROOT => array( |
| 50 | + 'client' => 'clientClass', |
| 51 | + ), |
| 52 | + ]); |
| 53 | + |
| 54 | + $this->assertSame( |
| 55 | + 'clientClass', |
| 56 | + $container->getParameter('sentry.client') |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + public function test_that_it_uses_kernel_environment_as_environment_by_default() |
| 61 | + { |
| 62 | + $container = $this->getContainer(); |
| 63 | + |
| 64 | + $this->assertSame( |
| 65 | + 'test', |
| 66 | + $container->getParameter('sentry.environment') |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + public function test_that_it_uses_environment_value() |
| 71 | + { |
| 72 | + $container = $this->getContainer(array( |
| 73 | + static::CONFIG_ROOT => array( |
| 74 | + 'environment' => 'custom_env', |
| 75 | + ), |
| 76 | + )); |
| 77 | + |
| 78 | + $this->assertSame( |
| 79 | + 'custom_env', |
| 80 | + $container->getParameter('sentry.environment') |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + public function test_that_it_uses_null_as_dsn_default_value() |
| 85 | + { |
| 86 | + $container = $this->getContainer(); |
| 87 | + |
| 88 | + $this->assertSame( |
| 89 | + null, |
| 90 | + $container->getParameter('sentry.dsn') |
| 91 | + ); |
| 92 | + } |
| 93 | + |
| 94 | + public function test_that_it_uses_dsn_value() |
| 95 | + { |
| 96 | + $container = $this->getContainer([ |
| 97 | + static::CONFIG_ROOT => [ |
| 98 | + 'dsn' => 'custom_dsn', |
| 99 | + ], |
| 100 | + ]); |
| 101 | + |
| 102 | + $this->assertSame( |
| 103 | + 'custom_dsn', |
| 104 | + $container->getParameter('sentry.dsn') |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + public function test_that_it_uses_defined_class_as_exception_listener_class_by_default() |
| 109 | + { |
| 110 | + $container = $this->getContainer(); |
| 111 | + |
| 112 | + $this->assertSame( |
| 113 | + 'Sentry\SentryBundle\EventListener\ExceptionListener', |
| 114 | + $container->getParameter('sentry.exception_listener') |
| 115 | + ); |
| 116 | + } |
| 117 | + |
| 118 | + public function test_that_it_uses_exception_listener_value() |
| 119 | + { |
| 120 | + $container = $this->getContainer([ |
| 121 | + static::CONFIG_ROOT => array( |
| 122 | + 'exception_listener' => 'exceptionListenerClass', |
| 123 | + ), |
| 124 | + ]); |
| 125 | + |
| 126 | + $this->assertSame( |
| 127 | + 'exceptionListenerClass', |
| 128 | + $container->getParameter('sentry.exception_listener') |
| 129 | + ); |
| 130 | + } |
| 131 | + |
| 132 | + public function test_that_it_uses_array_with_http_exception_as_skipped_capture_by_default() |
| 133 | + { |
| 134 | + $container = $this->getContainer(); |
| 135 | + |
| 136 | + $this->assertSame( |
| 137 | + array( |
| 138 | + 'Symfony\Component\HttpKernel\Exception\HttpExceptionInterface', |
| 139 | + ), |
| 140 | + $container->getParameter('sentry.skip_capture') |
| 141 | + ); |
| 142 | + } |
| 143 | + |
| 144 | + public function test_that_it_uses_skipped_capture_value() |
| 145 | + { |
| 146 | + $container = $this->getContainer(array( |
| 147 | + static::CONFIG_ROOT => array( |
| 148 | + 'skip_capture' => array( |
| 149 | + 'classA', |
| 150 | + 'classB', |
| 151 | + ), |
| 152 | + ), |
| 153 | + )); |
| 154 | + |
| 155 | + $this->assertSame( |
| 156 | + array('classA', 'classB'), |
| 157 | + $container->getParameter('sentry.skip_capture') |
| 158 | + ); |
| 159 | + } |
| 160 | + |
| 161 | + public function test_that_it_uses_null_as_release_by_default() |
| 162 | + { |
| 163 | + $container = $this->getContainer(); |
| 164 | + |
| 165 | + $this->assertSame( |
| 166 | + null, |
| 167 | + $container->getParameter('sentry.release') |
| 168 | + ); |
| 169 | + } |
| 170 | + |
| 171 | + public function test_that_it_uses_release_value() |
| 172 | + { |
| 173 | + $container = $this->getContainer(array( |
| 174 | + static::CONFIG_ROOT => array( |
| 175 | + 'release' => '1.0', |
| 176 | + ), |
| 177 | + )); |
| 178 | + |
| 179 | + $this->assertSame( |
| 180 | + '1.0', |
| 181 | + $container->getParameter('sentry.release') |
| 182 | + ); |
| 183 | + } |
| 184 | + |
| 185 | + public function test_that_it_uses_array_with_kernel_parent_as_prefix_by_default() |
| 186 | + { |
| 187 | + $container = $this->getContainer(); |
| 188 | + |
| 189 | + $this->assertSame( |
| 190 | + array('kernel/root/..'), |
| 191 | + $container->getParameter('sentry.prefixes') |
| 192 | + ); |
| 193 | + } |
| 194 | + |
| 195 | + public function test_that_it_uses_prefixes_value() |
| 196 | + { |
| 197 | + $container = $this->getContainer(array( |
| 198 | + static::CONFIG_ROOT => array( |
| 199 | + 'prefixes' => array( |
| 200 | + 'dirA', |
| 201 | + 'dirB', |
| 202 | + ), |
| 203 | + ), |
| 204 | + )); |
| 205 | + |
| 206 | + $this->assertSame( |
| 207 | + array('dirA', 'dirB'), |
| 208 | + $container->getParameter('sentry.prefixes') |
| 209 | + ); |
| 210 | + } |
| 211 | + |
| 212 | + public function test_that_it_has_sentry_client_service_and_it_defaults_to_symfony_client() |
| 213 | + { |
| 214 | + $client = $this->getContainer()->get('sentry.client'); |
| 215 | + $this->assertInstanceOf('Sentry\SentryBundle\SentrySymfonyClient', $client); |
| 216 | + } |
| 217 | + |
| 218 | + public function test_that_it_has_sentry_exception_listener_and_it_defaults_to_default_exception_listener() |
| 219 | + { |
| 220 | + $client = $this->getContainer()->get('sentry.exception_listener'); |
| 221 | + $this->assertInstanceOf('Sentry\SentryBundle\EventListener\ExceptionListener', $client); |
| 222 | + } |
| 223 | + |
| 224 | + public function test_that_it_has_proper_event_listener_tags_for_exception_listener() |
| 225 | + { |
| 226 | + $containerBuilder = new ContainerBuilder(); |
| 227 | + $extension = new SentryExtension(); |
| 228 | + $extension->load(array(), $containerBuilder); |
| 229 | + |
| 230 | + $definition = $containerBuilder->getDefinition('sentry.exception_listener'); |
| 231 | + $tags = $definition->getTag('kernel.event_listener'); |
| 232 | + |
| 233 | + $this->assertSame( |
| 234 | + array( |
| 235 | + array('event' => 'kernel.request', 'method' => 'onKernelRequest'), |
| 236 | + array('event' => 'kernel.exception', 'method' => 'onKernelException'), |
| 237 | + array('event' => 'console.exception', 'method' => 'onConsoleException'), |
| 238 | + ), |
| 239 | + $tags |
| 240 | + ); |
| 241 | + } |
| 242 | + |
| 243 | + private function getContainer(array $options = array()) |
| 244 | + { |
| 245 | + $containerBuilder = new ContainerBuilder(); |
| 246 | + $containerBuilder->setParameter('kernel.root_dir', 'kernel/root'); |
| 247 | + $containerBuilder->setParameter('kernel.environment', 'test'); |
| 248 | + |
| 249 | + $extension = new SentryExtension(); |
| 250 | + |
| 251 | + $extension->load($options, $containerBuilder); |
| 252 | + |
| 253 | + $containerBuilder->compile(); |
| 254 | + |
| 255 | + return $containerBuilder; |
| 256 | + } |
| 257 | +} |
0 commit comments