From fd8341ec4bcf46b21624d654dc266d1af3382098 Mon Sep 17 00:00:00 2001 From: Luke Kuzmish Date: Wed, 17 Jul 2024 19:58:46 -0400 Subject: [PATCH 1/2] automatically set statsclient --- composer.json | 5 ++-- src/StatsClientAwareServiceProvider.php | 26 ++++++++++++++++++ tests/AbstractTestCase.php | 8 ++++++ tests/Fixtures/WantsStatsClient.php | 17 ++++++++++++ tests/StatsClientAwareServiceProviderTest.php | 27 +++++++++++++++++++ 5 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 src/StatsClientAwareServiceProvider.php create mode 100644 tests/Fixtures/WantsStatsClient.php create mode 100644 tests/StatsClientAwareServiceProviderTest.php diff --git a/composer.json b/composer.json index 11b5590..ba34154 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "require": { "php": "^8.2", - "cosmastech/statsd-client-adapter": "^0.2.0", + "cosmastech/statsd-client-adapter": "dev-stats-aware-interface", "illuminate/support": "^10.0|^11.0", "illuminate/contracts": "^10.0|^11.0" }, @@ -45,7 +45,8 @@ "extra": { "laravel": { "providers": [ - "Cosmastech\\LaravelStatsDAdapter\\StatsDAdapterServiceProvider" + "Cosmastech\\LaravelStatsDAdapter\\StatsDAdapterServiceProvider", + "Cosmastech\\LaravelStatsDAdapter\\StatsClientAwareServiceProvider" ], "aliases": { "Stats": "Cosmastech\\LaravelStatsDAdapter\\Stats" diff --git a/src/StatsClientAwareServiceProvider.php b/src/StatsClientAwareServiceProvider.php new file mode 100644 index 0000000..9fd7c4c --- /dev/null +++ b/src/StatsClientAwareServiceProvider.php @@ -0,0 +1,26 @@ +app->afterResolving( + StatsClientAwareInterface::class, + function (StatsClientAwareInterface $wantsStatsClient, Application $application): void { + $wantsStatsClient->setStatsClient($application->make(StatsDClientAdapter::class)); + } + ); + } +} diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index 924f948..af849e3 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -3,6 +3,7 @@ namespace Cosmastech\LaravelStatsDAdapter\Tests; use Cosmastech\LaravelStatsDAdapter\AdapterManager; +use Cosmastech\LaravelStatsDAdapter\StatsClientAwareServiceProvider; use Illuminate\Config\Repository; use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\TestCase; @@ -11,6 +12,13 @@ class AbstractTestCase extends TestCase { use WithWorkbench; + protected $enablesPackageDiscoveries = true; + + protected function getPackageProviders($app) + { + return [StatsClientAwareServiceProvider::class]; + } + protected function getEnvironmentSetUp($app) { /** @var Repository $config */ diff --git a/tests/Fixtures/WantsStatsClient.php b/tests/Fixtures/WantsStatsClient.php new file mode 100644 index 0000000..d34f2ef --- /dev/null +++ b/tests/Fixtures/WantsStatsClient.php @@ -0,0 +1,17 @@ +statsClient; + } +} diff --git a/tests/StatsClientAwareServiceProviderTest.php b/tests/StatsClientAwareServiceProviderTest.php new file mode 100644 index 0000000..5d17e82 --- /dev/null +++ b/tests/StatsClientAwareServiceProviderTest.php @@ -0,0 +1,27 @@ +app->make(WantsStatsClient::class); + + // Then + self::assertSame( + $this->app->make(StatsDClientAdapter::class), + $wantsStatsClient->getStatsClient() + ); + } +} From ac70a46a3e09b09b31943e3a70024404fc53dfb2 Mon Sep 17 00:00:00 2001 From: Luke Kuzmish <42181698+cosmastech@users.noreply.github.com> Date: Fri, 19 Jul 2024 06:57:45 -0400 Subject: [PATCH 2/2] use tagged release --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ba34154..ad0fb8c 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "require": { "php": "^8.2", - "cosmastech/statsd-client-adapter": "dev-stats-aware-interface", + "cosmastech/statsd-client-adapter": "^0.3", "illuminate/support": "^10.0|^11.0", "illuminate/contracts": "^10.0|^11.0" },