File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed
tests/Adapters/StatsClientAware Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Cosmastech \StatsDClientAdapter \Adapters \Concerns ;
4+
5+ use Cosmastech \StatsDClientAdapter \Adapters \StatsDClientAdapter ;
6+
7+ trait StatsClientAwareTrait
8+ {
9+ protected StatsDClientAdapter $ statsClient ;
10+
11+ public function setStatsClient (StatsDClientAdapter $ statsDClientAdapter ): void
12+ {
13+ $ this ->statsClient = $ statsDClientAdapter ;
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Cosmastech \StatsDClientAdapter \Adapters \Contracts ;
4+
5+ use Cosmastech \StatsDClientAdapter \Adapters \StatsDClientAdapter ;
6+
7+ interface StatsClientAwareInterface
8+ {
9+ public function setStatsClient (StatsDClientAdapter $ statsDClientAdapter ): void ;
10+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Cosmastech \StatsDClientAdapter \Tests \Adapters \StatsClientAware ;
4+
5+ use Cosmastech \StatsDClientAdapter \Adapters \Concerns \StatsClientAwareTrait ;
6+ use Cosmastech \StatsDClientAdapter \Adapters \Contracts \StatsClientAwareInterface ;
7+ use Cosmastech \StatsDClientAdapter \Adapters \InMemory \InMemoryClientAdapter ;
8+ use Cosmastech \StatsDClientAdapter \Adapters \StatsDClientAdapter ;
9+ use Cosmastech \StatsDClientAdapter \Tests \BaseTestCase ;
10+ use PHPUnit \Framework \Attributes \Test ;
11+
12+ class StatsClientAwareTraitTest extends BaseTestCase
13+ {
14+ #[Test]
15+ public function classHasStatsClientAware_canSetStatsClient (): void
16+ {
17+ // Given
18+ $ wantsStatsClient = self ::makeWantsStatsClientClass ();
19+
20+ // And
21+ $ statsDClientAdapter = new InMemoryClientAdapter ();
22+
23+ // When
24+ $ wantsStatsClient ->setStatsClient ($ statsDClientAdapter );
25+
26+ // Then
27+ self ::assertSame (
28+ $ statsDClientAdapter ,
29+ $ wantsStatsClient ->getStatsClient () /** @phpstan-ignore method.notFound (this is a method on an anonymous class) */
30+ );
31+ }
32+
33+ private static function makeWantsStatsClientClass (): StatsClientAwareInterface
34+ {
35+ return new class () implements StatsClientAwareInterface {
36+ use StatsClientAwareTrait;
37+ public function getStatsClient (): StatsDClientAdapter
38+ {
39+ return $ this ->statsClient ;
40+ }
41+ };
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments