|
5 | 5 | namespace Sentry\SentryBundle\Tests\Tracing\Cache; |
6 | 6 |
|
7 | 7 | use Sentry\SentryBundle\Tracing\Cache\TraceableTagAwareCacheAdapter; |
| 8 | +use Sentry\SentryBundle\Tracing\Cache\TraceableTagAwareCacheAdapterForV3WithNamespace; |
8 | 9 | use Sentry\Tracing\Transaction; |
9 | 10 | use Sentry\Tracing\TransactionContext; |
10 | 11 | use Symfony\Component\Cache\Adapter\AdapterInterface; |
11 | 12 | use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface; |
| 13 | +use Symfony\Contracts\Cache\NamespacedPoolInterface; |
| 14 | + |
| 15 | +interface TagAwareNamespacedPoolInterface extends TagAwareAdapterInterface, NamespacedPoolInterface |
| 16 | +{ |
| 17 | +} |
12 | 18 |
|
13 | 19 | /** |
14 | 20 | * @phpstan-extends AbstractTraceableCacheAdapterTest<TraceableTagAwareCacheAdapter, TagAwareAdapterInterface> |
@@ -42,6 +48,49 @@ public function testInvalidateTags(): void |
42 | 48 | $this->assertNotNull($spans[1]->getEndTimestamp()); |
43 | 49 | } |
44 | 50 |
|
| 51 | + public function testWithSubNamespaceThrowsWhenNotNamespaced(): void |
| 52 | + { |
| 53 | + if (!interface_exists(NamespacedPoolInterface::class)) { |
| 54 | + $this->markTestSkipped('Namespaced caches are not supported by this Symfony version.'); |
| 55 | + } |
| 56 | + |
| 57 | + $decoratedAdapter = $this->createMock(TagAwareAdapterInterface::class); |
| 58 | + $adapter = new TraceableTagAwareCacheAdapterForV3WithNamespace($this->hub, $decoratedAdapter); |
| 59 | + |
| 60 | + $this->expectException(\BadMethodCallException::class); |
| 61 | + $this->expectExceptionMessage('withSubNamespace() method is not supported'); |
| 62 | + |
| 63 | + $adapter->withSubNamespace('foo'); |
| 64 | + } |
| 65 | + |
| 66 | + public function testWithSubNamespaceReturnsNamespacedAdapter(): void |
| 67 | + { |
| 68 | + if (!interface_exists(NamespacedPoolInterface::class)) { |
| 69 | + $this->markTestSkipped('Namespaced caches are not supported by this Symfony version.'); |
| 70 | + } |
| 71 | + |
| 72 | + $decoratedAdapter = $this->createMock(TagAwareNamespacedPoolInterface::class); |
| 73 | + $namespacedAdapter = $this->createMock(TagAwareNamespacedPoolInterface::class); |
| 74 | + |
| 75 | + $decoratedAdapter |
| 76 | + ->expects($this->once()) |
| 77 | + ->method('withSubNamespace') |
| 78 | + ->with('foo') |
| 79 | + ->willReturn($namespacedAdapter); |
| 80 | + |
| 81 | + $adapter = new TraceableTagAwareCacheAdapterForV3WithNamespace($this->hub, $decoratedAdapter); |
| 82 | + |
| 83 | + $result = $adapter->withSubNamespace('foo'); |
| 84 | + |
| 85 | + $this->assertInstanceOf(NamespacedPoolInterface::class, $result); |
| 86 | + $this->assertNotSame($adapter, $result); |
| 87 | + |
| 88 | + $ref = new \ReflectionProperty($result, 'decoratedAdapter'); |
| 89 | + $ref->setAccessible(true); |
| 90 | + |
| 91 | + $this->assertSame($namespacedAdapter, $ref->getValue($result)); |
| 92 | + } |
| 93 | + |
45 | 94 | /** |
46 | 95 | * {@inheritdoc} |
47 | 96 | */ |
|
0 commit comments