RavenTest.php in Raven: Sentry Integration 3.x
File
tests/src/Functional/RavenTest.php
View source
<?php
namespace Drupal\Tests\raven\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;
class RavenTest extends BrowserTestBase {
use StringTranslationTrait;
protected $defaultTheme = 'stark';
protected static $modules = [
'raven',
'raven_test',
];
public function testRavenConfigAndHooks() {
$admin_user = $this
->drupalCreateUser([
'administer site configuration',
]);
$this
->drupalLogin($admin_user);
$config['raven[php][client_key]'] = 'https://user@sentry.test/123456';
$config['raven[php][fatal_error_handler]'] = 1;
foreach (range(1, 8) as $level) {
$config["raven[php][log_levels][{$level}]"] = '1';
}
$this
->drupalGet('admin/config/development/logging');
$this
->submitForm($config, $this
->t('Save configuration'));
$this
->assertSession()
->responseHeaderEquals('X-Logged', 'Logged');
$this
->assertSession()
->responseHeaderEquals('X-Not-Logged', NULL);
$path = $this->container
->has('extension.path.resolver') ? $this->container
->get('extension.path.resolver')
->getPath('module', 'raven_test') : drupal_get_path('module', 'raven_test');
$this
->assertSession()
->responseHeaderEquals('X-Stacktrace-File', "/{$path}/raven_test.module");
$memory_limit = mt_rand(16000000, 17999999);
$url = $admin_user
->toUrl()
->setOption('query', [
'memory_limit' => $memory_limit,
]);
$this
->assertEquals($memory_limit, $this
->drupalGet($url));
$config = [
'raven[php][ignored_channels]' => "X-Logged\r\n",
];
$this
->drupalGet('admin/config/development/logging');
$this
->submitForm($config, $this
->t('Save configuration'));
$this
->assertSession()
->responseHeaderEquals('X-Logged', NULL);
unserialize(serialize($this->container
->get('logger.raven')));
\Sentry\captureException(new \Exception('This is a test.'));
}
}