99use Sentry \Tracing \Transaction ;
1010use Sentry \Tracing \TransactionContext ;
1111use Symfony \Component \Cache \Adapter \AdapterInterface ;
12+ use Symfony \Component \Cache \Adapter \ArrayAdapter ;
13+ use Symfony \Component \Cache \Adapter \TagAwareAdapter ;
1214use Symfony \Component \Cache \Adapter \TagAwareAdapterInterface ;
1315use Symfony \Contracts \Cache \NamespacedPoolInterface ;
1416
15- if (interface_exists (NamespacedPoolInterface::class)) {
16- interface TagAwareNamespacedPoolInterface extends TagAwareAdapterInterface, NamespacedPoolInterface
17- {
18- }
19- }
20-
2117/**
2218 * @phpstan-extends AbstractTraceableCacheAdapterTest<TraceableTagAwareCacheAdapter, TagAwareAdapterInterface>
2319 */
@@ -71,14 +67,8 @@ public function testWithSubNamespaceReturnsNamespacedAdapter(): void
7167 $ this ->markTestSkipped ('Namespaced caches are not supported by this Symfony version. ' );
7268 }
7369
74- $ decoratedAdapter = $ this ->createMock (TagAwareNamespacedPoolInterface::class);
75- $ namespacedAdapter = $ this ->createMock (TagAwareNamespacedPoolInterface::class);
76-
77- $ decoratedAdapter
78- ->expects ($ this ->once ())
79- ->method ('withSubNamespace ' )
80- ->with ('foo ' )
81- ->willReturn ($ namespacedAdapter );
70+ $ decoratedAdapter = new TagAwareAdapter (new ArrayAdapter (), new ArrayAdapter ());
71+ $ namespacedAdapter = $ decoratedAdapter ->withSubNamespace ('foo ' );
8272
8373 $ adapter = new TraceableTagAwareCacheAdapterForV3WithNamespace ($ this ->hub , $ decoratedAdapter );
8474
@@ -90,7 +80,63 @@ public function testWithSubNamespaceReturnsNamespacedAdapter(): void
9080 $ ref = new \ReflectionProperty ($ result , 'decoratedAdapter ' );
9181 $ ref ->setAccessible (true );
9282
93- $ this ->assertSame ($ namespacedAdapter , $ ref ->getValue ($ result ));
83+ $ this ->assertEquals ($ namespacedAdapter , $ ref ->getValue ($ result ));
84+ }
85+
86+ public function testNamespaceIsAddedToSpanData (): void
87+ {
88+ if (!interface_exists (NamespacedPoolInterface::class)) {
89+ $ this ->markTestSkipped ('Namespaced caches are not supported by this Symfony version. ' );
90+ }
91+
92+ $ transaction = new Transaction (new TransactionContext (), $ this ->hub );
93+ $ transaction ->initSpanRecorder ();
94+
95+ $ this ->hub ->expects ($ this ->any ())
96+ ->method ('getSpan ' )
97+ ->willReturn ($ transaction );
98+
99+ $ decoratedAdapter = new TagAwareAdapter (new ArrayAdapter (), new ArrayAdapter ());
100+ $ adapter = new TraceableTagAwareCacheAdapterForV3WithNamespace ($ this ->hub , $ decoratedAdapter );
101+
102+ $ namespaced = $ adapter ->withSubNamespace ('foo ' )->withSubNamespace ('bar ' );
103+
104+ $ namespaced ->delete ('example ' );
105+ $ this ->assertNotNull ($ transaction ->getSpanRecorder ());
106+
107+ $ spans = $ transaction ->getSpanRecorder ()->getSpans ();
108+
109+ $ this ->assertCount (2 , $ spans );
110+ $ this ->assertSame ('cache.remove ' , $ spans [1 ]->getOp ());
111+ $ this ->assertSame ('foo.bar ' , $ spans [1 ]->getData ()['cache.namespace ' ]);
112+ }
113+
114+ public function testSingleNamespaceIsAddedToSpanData (): void
115+ {
116+ if (!interface_exists (NamespacedPoolInterface::class)) {
117+ $ this ->markTestSkipped ('Namespaced caches are not supported by this Symfony version. ' );
118+ }
119+
120+ $ transaction = new Transaction (new TransactionContext (), $ this ->hub );
121+ $ transaction ->initSpanRecorder ();
122+
123+ $ this ->hub ->expects ($ this ->any ())
124+ ->method ('getSpan ' )
125+ ->willReturn ($ transaction );
126+
127+ $ decoratedAdapter = new TagAwareAdapter (new ArrayAdapter (), new ArrayAdapter ());
128+ $ adapter = new TraceableTagAwareCacheAdapterForV3WithNamespace ($ this ->hub , $ decoratedAdapter );
129+
130+ $ namespaced = $ adapter ->withSubNamespace ('foo ' );
131+
132+ $ namespaced ->delete ('example ' );
133+ $ this ->assertNotNull ($ transaction ->getSpanRecorder ());
134+
135+ $ spans = $ transaction ->getSpanRecorder ()->getSpans ();
136+
137+ $ this ->assertCount (2 , $ spans );
138+ $ this ->assertSame ('cache.remove ' , $ spans [1 ]->getOp ());
139+ $ this ->assertSame ('foo ' , $ spans [1 ]->getData ()['cache.namespace ' ]);
94140 }
95141
96142 /**
0 commit comments