Skip to content

Commit 1d044d2

Browse files
fragkpKevin Pohl
authored andcommitted
Fix custom alias (#263)
* add failing test * fix custom alias Co-authored-by: Kevin Pohl <[email protected]>
1 parent 043b294 commit 1d044d2

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

src/Sentry/Laravel/ServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ServiceProvider extends IlluminateServiceProvider
2525
*/
2626
public function boot(): void
2727
{
28-
$this->app->make(self::$abstract);
28+
$this->app->make(static::$abstract);
2929

3030
if ($this->hasDsnSet()) {
3131
$this->bindEvents($this->app);
@@ -128,7 +128,7 @@ protected function configureAndRegisterClient(): void
128128
return Hub::getCurrent();
129129
});
130130

131-
$this->app->alias(self::$abstract, HubInterface::class);
131+
$this->app->alias(static::$abstract, HubInterface::class);
132132
}
133133

134134
/**

test/Sentry/ServiceProviderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function testIsBound()
3232
{
3333
$this->assertTrue(app()->bound('sentry'));
3434
$this->assertInstanceOf(Hub::class, app('sentry'));
35+
$this->assertSame(app('sentry'), Facade::getFacadeRoot());
3536
}
3637

3738
/**
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace Sentry\Laravel\Tests;
4+
5+
use Sentry\State\Hub;
6+
use Sentry\Laravel\Facade;
7+
use Sentry\Laravel\ServiceProvider;
8+
9+
class ServiceProviderWithCustomAliasTest extends \Orchestra\Testbench\TestCase
10+
{
11+
protected function getEnvironmentSetUp($app)
12+
{
13+
$app['config']->set('custom-sentry.dsn', 'http://publickey:[email protected]/123');
14+
$app['config']->set('custom-sentry.error_types', E_ALL ^ E_DEPRECATED ^ E_USER_DEPRECATED);
15+
}
16+
17+
protected function getPackageProviders($app)
18+
{
19+
return [
20+
CustomSentryServiceProvider::class,
21+
];
22+
}
23+
24+
protected function getPackageAliases($app)
25+
{
26+
return [
27+
'CustomSentry' => CustomSentryFacade::class,
28+
];
29+
}
30+
31+
public function testIsBound()
32+
{
33+
$this->assertTrue(app()->bound('custom-sentry'));
34+
$this->assertInstanceOf(Hub::class, app('custom-sentry'));
35+
$this->assertSame(app('custom-sentry'), CustomSentryFacade::getFacadeRoot());
36+
}
37+
38+
/**
39+
* @depends testIsBound
40+
*/
41+
public function testEnvironment()
42+
{
43+
$this->assertEquals('testing', app('custom-sentry')->getClient()->getOptions()->getEnvironment());
44+
}
45+
46+
/**
47+
* @depends testIsBound
48+
*/
49+
public function testDsnWasSetFromConfig()
50+
{
51+
/** @var \Sentry\Options $options */
52+
$options = app('custom-sentry')->getClient()->getOptions();
53+
54+
$this->assertEquals('http://sentry.dev', $options->getDsn());
55+
$this->assertEquals(123, $options->getProjectId());
56+
$this->assertEquals('publickey', $options->getPublicKey());
57+
$this->assertEquals('secretkey', $options->getSecretKey());
58+
}
59+
60+
/**
61+
* @depends testIsBound
62+
*/
63+
public function testErrorTypesWasSetFromConfig()
64+
{
65+
$this->assertEquals(
66+
E_ALL ^ E_DEPRECATED ^ E_USER_DEPRECATED,
67+
app('custom-sentry')->getClient()->getOptions()->getErrorTypes()
68+
);
69+
}
70+
}
71+
72+
class CustomSentryServiceProvider extends ServiceProvider
73+
{
74+
public static $abstract = 'custom-sentry';
75+
}
76+
77+
class CustomSentryFacade extends Facade
78+
{
79+
protected static function getFacadeAccessor()
80+
{
81+
return 'custom-sentry';
82+
}
83+
}

0 commit comments

Comments
 (0)