Skip to content

Commit e914d4f

Browse files
authored
Added event of release connection for hyperf/pool. (#6613)
1 parent 4cbb957 commit e914d4f

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

tests/RedisConnectionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use PHPUnit\Framework\Attributes\CoversNothing;
2929
use PHPUnit\Framework\TestCase;
3030
use Psr\Container\ContainerInterface;
31+
use Psr\EventDispatcher\EventDispatcherInterface;
3132

3233
/**
3334
* @internal
@@ -111,6 +112,9 @@ public function testRedisConnectionLog()
111112
$container = Mockery::mock(ContainerInterface::class);
112113
$container->shouldReceive('has')->with(StdoutLoggerInterface::class)->andReturnTrue();
113114
$container->shouldReceive('get')->with(StdoutLoggerInterface::class)->andReturn($logger = Mockery::mock(StdoutLoggerInterface::class));
115+
$container->shouldReceive('has')->with(StdoutLoggerInterface::class)->andReturnFalse();
116+
$container->shouldReceive('has')->with(EventDispatcherInterface::class)->andReturnFalse();
117+
114118
$logger->shouldReceive('log')->once();
115119

116120
$conn = new RedisConnectionStub($container, Mockery::mock(Pool::class), []);
@@ -192,6 +196,9 @@ private function getRedisPool()
192196
return new Channel($args['size']);
193197
});
194198

199+
$container->shouldReceive('has')->with(StdoutLoggerInterface::class)->andReturnFalse();
200+
$container->shouldReceive('has')->with(EventDispatcherInterface::class)->andReturnFalse();
201+
195202
ApplicationContext::setContainer($container);
196203

197204
return new RedisPoolStub($container, 'default');

tests/RedisProxyTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Mockery;
2828
use PHPUnit\Framework\Attributes\CoversNothing;
2929
use PHPUnit\Framework\TestCase;
30+
use Psr\EventDispatcher\EventDispatcherInterface;
3031
use RedisCluster;
3132

3233
use function Hyperf\Coroutine\go;
@@ -230,6 +231,9 @@ private function getRedis($optinos = [])
230231
$container->shouldReceive('make')->with(PoolOption::class, Mockery::any())->andReturnUsing(function ($class, $args) {
231232
return new PoolOption(...array_values($args));
232233
});
234+
$container->shouldReceive('has')->with(StdoutLoggerInterface::class)->andReturnFalse();
235+
$container->shouldReceive('has')->with(EventDispatcherInterface::class)->andReturnFalse();
236+
233237
ApplicationContext::setContainer($container);
234238

235239
$factory = new PoolFactory($container);

tests/RedisTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Hyperf\Context\ApplicationContext;
1616
use Hyperf\Context\Context;
1717
use Hyperf\Contract\ConfigInterface;
18+
use Hyperf\Contract\StdoutLoggerInterface;
1819
use Hyperf\Coroutine\Coroutine;
1920
use Hyperf\Di\Container;
2021
use Hyperf\Engine\Channel as Chan;
@@ -31,6 +32,7 @@
3132
use Mockery;
3233
use PHPUnit\Framework\Attributes\CoversNothing;
3334
use PHPUnit\Framework\TestCase;
35+
use Psr\EventDispatcher\EventDispatcherInterface;
3436
use RedisCluster;
3537
use RedisSentinel;
3638
use ReflectionClass;
@@ -293,6 +295,8 @@ private function getContainer()
293295
$container->shouldReceive('make')->with(Channel::class, Mockery::any())->andReturnUsing(function ($class, $args) {
294296
return new Channel($args['size']);
295297
});
298+
$container->shouldReceive('has')->with(StdoutLoggerInterface::class)->andReturnFalse();
299+
$container->shouldReceive('has')->with(EventDispatcherInterface::class)->andReturnFalse();
296300
return $container;
297301
}
298302
}

tests/Stub/ContainerStub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Hyperf\Redis\Pool\RedisPool;
2525
use Hyperf\Redis\Redis;
2626
use Mockery;
27+
use Psr\EventDispatcher\EventDispatcherInterface;
2728

2829
use function Hyperf\Support\value;
2930

@@ -74,6 +75,7 @@ public static function mockContainer()
7475
$container->shouldReceive('get')->with(StdoutLoggerInterface::class)->andReturn(value(function () {
7576
return Mockery::mock(StdoutLoggerInterface::class);
7677
}));
78+
$container->shouldReceive('has')->with(EventDispatcherInterface::class)->andReturnFalse();
7779

7880
ApplicationContext::setContainer($container);
7981
return $container;

0 commit comments

Comments
 (0)