-
Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathGearmanConnectionFactoryConfigTest.php
104 lines (87 loc) · 2.53 KB
/
GearmanConnectionFactoryConfigTest.php
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace Enqueue\Gearman\Tests;
use Enqueue\Gearman\GearmanConnectionFactory;
use Enqueue\Test\ClassExtensionTrait;
use PHPUnit\Framework\TestCase;
/**
* The class contains the factory tests dedicated to configuration.
*/
class GearmanConnectionFactoryConfigTest extends TestCase
{
use ClassExtensionTrait;
use SkipIfGearmanExtensionIsNotInstalledTrait;
public function testThrowNeitherArrayStringNorNullGivenAsConfig()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The config must be either an array of options, a DSN string or null');
new GearmanConnectionFactory(new \stdClass());
}
public function testThrowIfSchemeIsNotGearmanAmqp()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The given DSN scheme "http" is not supported. Could be "gearman" only.');
new GearmanConnectionFactory('http://example.com');
}
public function testThrowIfDsnCouldNotBeParsed()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Failed to parse DSN "gearman://:@/"');
new GearmanConnectionFactory('gearman://:@/');
}
/**
* @dataProvider provideConfigs
*
* @param mixed $config
* @param mixed $expectedConfig
*/
public function testShouldParseConfigurationAsExpected($config, $expectedConfig)
{
$factory = new GearmanConnectionFactory($config);
$this->assertAttributeEquals($expectedConfig, 'config', $factory);
}
public static function provideConfigs()
{
yield [
null,
[
'host' => 'localhost',
'port' => 4730,
],
];
yield [
'gearman:',
[
'host' => 'localhost',
'port' => 4730,
],
];
yield [
[],
[
'host' => 'localhost',
'port' => 4730,
],
];
yield [
'gearman://theHost:1234',
[
'host' => 'theHost',
'port' => 1234,
],
];
yield [
['host' => 'theHost', 'port' => 1234],
[
'host' => 'theHost',
'port' => 1234,
],
];
yield [
['host' => 'theHost'],
[
'host' => 'theHost',
'port' => 4730,
],
];
}
}