Skip to content

Commit 0caf67d

Browse files
committed
mocked tests
1 parent dd0e6f0 commit 0caf67d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/Tracing/Cache/TraceableTagAwareCacheAdapterTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
namespace Sentry\SentryBundle\Tests\Tracing\Cache;
66

77
use Sentry\SentryBundle\Tracing\Cache\TraceableTagAwareCacheAdapter;
8+
use Sentry\SentryBundle\Tracing\Cache\TraceableTagAwareCacheAdapterForV3WithNamespace;
89
use Sentry\Tracing\Transaction;
910
use Sentry\Tracing\TransactionContext;
1011
use Symfony\Component\Cache\Adapter\AdapterInterface;
1112
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
13+
use Symfony\Contracts\Cache\NamespacedPoolInterface;
14+
15+
interface TagAwareNamespacedPoolInterface extends TagAwareAdapterInterface, NamespacedPoolInterface
16+
{
17+
}
1218

1319
/**
1420
* @phpstan-extends AbstractTraceableCacheAdapterTest<TraceableTagAwareCacheAdapter, TagAwareAdapterInterface>
@@ -42,6 +48,49 @@ public function testInvalidateTags(): void
4248
$this->assertNotNull($spans[1]->getEndTimestamp());
4349
}
4450

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+
4594
/**
4695
* {@inheritdoc}
4796
*/

0 commit comments

Comments
 (0)