File tree Expand file tree Collapse file tree 5 files changed +81
-2
lines changed Expand file tree Collapse file tree 5 files changed +81
-2
lines changed Original file line number Diff line number Diff line change 2424 },
2525 "require" : {
2626 "php" : " ^8.2" ,
27- "cosmastech/statsd-client-adapter" : " ^0.2.0 " ,
27+ "cosmastech/statsd-client-adapter" : " ^0.3 " ,
2828 "illuminate/support" : " ^10.0|^11.0" ,
2929 "illuminate/contracts" : " ^10.0|^11.0"
3030 },
4545 "extra" : {
4646 "laravel" : {
4747 "providers" : [
48- " Cosmastech\\ LaravelStatsDAdapter\\ StatsDAdapterServiceProvider"
48+ " Cosmastech\\ LaravelStatsDAdapter\\ StatsDAdapterServiceProvider" ,
49+ " Cosmastech\\ LaravelStatsDAdapter\\ StatsClientAwareServiceProvider"
4950 ],
5051 "aliases" : {
5152 "Stats" : " Cosmastech\\ LaravelStatsDAdapter\\ Stats"
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Cosmastech \LaravelStatsDAdapter ;
4+
5+ use Cosmastech \StatsDClientAdapter \Adapters \Contracts \StatsClientAwareInterface ;
6+ use Cosmastech \StatsDClientAdapter \Adapters \StatsDClientAdapter ;
7+ use Illuminate \Contracts \Foundation \Application ;
8+ use Illuminate \Support \ServiceProvider ;
9+
10+ class StatsClientAwareServiceProvider extends ServiceProvider
11+ {
12+ public function register (): void
13+ {
14+ //
15+ }
16+
17+ public function boot (): void
18+ {
19+ $ this ->app ->afterResolving (
20+ StatsClientAwareInterface::class,
21+ function (StatsClientAwareInterface $ wantsStatsClient , Application $ application ): void {
22+ $ wantsStatsClient ->setStatsClient ($ application ->make (StatsDClientAdapter::class));
23+ }
24+ );
25+ }
26+ }
Original file line number Diff line number Diff line change 33namespace Cosmastech \LaravelStatsDAdapter \Tests ;
44
55use Cosmastech \LaravelStatsDAdapter \AdapterManager ;
6+ use Cosmastech \LaravelStatsDAdapter \StatsClientAwareServiceProvider ;
67use Illuminate \Config \Repository ;
78use Orchestra \Testbench \Concerns \WithWorkbench ;
89use Orchestra \Testbench \TestCase ;
@@ -11,6 +12,13 @@ class AbstractTestCase extends TestCase
1112{
1213 use WithWorkbench;
1314
15+ protected $ enablesPackageDiscoveries = true ;
16+
17+ protected function getPackageProviders ($ app )
18+ {
19+ return [StatsClientAwareServiceProvider::class];
20+ }
21+
1422 protected function getEnvironmentSetUp ($ app )
1523 {
1624 /** @var Repository $config */
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Cosmastech \LaravelStatsDAdapter \Tests \Fixtures ;
4+
5+ use Cosmastech \StatsDClientAdapter \Adapters \Concerns \StatsClientAwareTrait ;
6+ use Cosmastech \StatsDClientAdapter \Adapters \Contracts \StatsClientAwareInterface ;
7+ use Cosmastech \StatsDClientAdapter \Adapters \StatsDClientAdapter ;
8+
9+ class WantsStatsClient implements StatsClientAwareInterface
10+ {
11+ use StatsClientAwareTrait;
12+
13+ public function getStatsClient (): StatsDClientAdapter
14+ {
15+ return $ this ->statsClient ;
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Cosmastech \LaravelStatsDAdapter \Tests ;
4+
5+ use Cosmastech \LaravelStatsDAdapter \Tests \Fixtures \WantsStatsClient ;
6+ use Cosmastech \StatsDClientAdapter \Adapters \StatsDClientAdapter ;
7+ use Illuminate \Support \Facades \Config ;
8+ use PHPUnit \Framework \Attributes \Test ;
9+
10+ class StatsClientAwareServiceProviderTest extends AbstractTestCase
11+ {
12+ #[Test]
13+ public function appResolvesStatsClientAwareInterfaceClass_classHasStatsClientSet (): void
14+ {
15+ // Given
16+ Config::set ("statsd-adapter.default " , "memory " );
17+
18+ // When
19+ $ wantsStatsClient = $ this ->app ->make (WantsStatsClient::class);
20+
21+ // Then
22+ self ::assertSame (
23+ $ this ->app ->make (StatsDClientAdapter::class),
24+ $ wantsStatsClient ->getStatsClient ()
25+ );
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments