Repository navigation
Expand file tree
/
Copy pathDriverTest.php
More file actions
73 lines (62 loc) · 2.26 KB
/
Copy pathDriverTest.php
File metadata and controls
73 lines (62 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\AsyncQueue;
use Hyperf\AsyncQueue\Driver\ChannelConfig;
use Hyperf\Di\Container;
use Hyperf\Redis\RedisFactory;
use Hyperf\Utils\ApplicationContext;
use Hyperf\Utils\Coroutine\Concurrent;
use Hyperf\Utils\Packer\PhpSerializerPacker;
use HyperfTest\AsyncQueue\Stub\Redis;
use HyperfTest\AsyncQueue\Stub\RedisDriverStub;
use Mockery;
use PHPUnit\Framework\TestCase;
use Psr\EventDispatcher\EventDispatcherInterface;
/**
* @internal
* @coversNothing
*/
class DriverTest extends TestCase
{
protected function tearDown()
{
Mockery::close();
}
public function testConcurrent()
{
$container = $this->getContainer();
$driver = new RedisDriverStub($container, []);
$this->assertNull($driver->getConcurrent());
$driver = new RedisDriverStub($container, ['concurrent' => [
'limit' => 100,
]]);
$this->assertInstanceOf(Concurrent::class, $driver->getConcurrent());
$this->assertSame(100, $driver->getConcurrent()->getLimit());
}
protected function getContainer()
{
$container = Mockery::mock(Container::class);
$container->shouldReceive('has')->andReturn(false);
$container->shouldReceive('get')->with(\Redis::class)->andReturn(new Redis());
$container->shouldReceive('get')->with(PhpSerializerPacker::class)->andReturn(new PhpSerializerPacker());
$container->shouldReceive('get')->with(EventDispatcherInterface::class)->andReturn(null);
$container->shouldReceive('make')->with(ChannelConfig::class, Mockery::any())->andReturnUsing(function ($class, $args) {
return new ChannelConfig($args['channel']);
});
$container->shouldReceive('get')->with(RedisFactory::class)->andReturnUsing(function ($_) {
$factory = Mockery::mock(RedisFactory::class);
$factory->shouldReceive('get')->with('default')->andReturn(new Redis());
return $factory;
});
ApplicationContext::setContainer($container);
return $container;
}
}