1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BasicTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use CommonTestClass; |
7
|
|
|
use kalanis\RemoteRequest\Connection; |
8
|
|
|
use kalanis\RemoteRequest\Interfaces\ISchema; |
9
|
|
|
use kalanis\RemoteRequest\Protocols; |
10
|
|
|
use kalanis\RemoteRequest\RequestException; |
11
|
|
|
use kalanis\RemoteRequest\Translations; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
class ConnectionParamsTest extends CommonTestClass |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @throws RequestException |
18
|
|
|
*/ |
19
|
|
|
public function testInit(): void |
20
|
|
|
{ |
21
|
|
|
$lang = new Translations(); |
22
|
|
|
$this->assertInstanceOf('\kalanis\RemoteRequest\Connection\Params\File', Connection\Params\Factory::getForSchema($lang, ISchema::SCHEMA_FILE)); |
23
|
|
|
$this->assertInstanceOf('\kalanis\RemoteRequest\Connection\Params\Php', Connection\Params\Factory::getForSchema($lang, ISchema::SCHEMA_PHP)); |
24
|
|
|
$this->assertInstanceOf('\kalanis\RemoteRequest\Connection\Params\Tcp', Connection\Params\Factory::getForSchema($lang, ISchema::SCHEMA_TCP)); |
25
|
|
|
$this->assertInstanceOf('\kalanis\RemoteRequest\Connection\Params\Udp', Connection\Params\Factory::getForSchema($lang, ISchema::SCHEMA_UDP)); |
26
|
|
|
$this->assertInstanceOf('\kalanis\RemoteRequest\Connection\Params\Ssl', Connection\Params\Factory::getForSchema($lang, ISchema::SCHEMA_SSL)); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testSimple(): void |
30
|
|
|
{ |
31
|
|
|
$schema = new Connection\Params\Tcp(); |
32
|
|
|
$schema->setTarget(''); |
33
|
|
|
$this->assertEmpty($schema->getHost()); |
34
|
|
|
$this->assertEquals('tcp://', $schema->getSchema()); |
35
|
|
|
$this->assertEquals(SOL_TCP, $schema->getProtocolVersion()); |
36
|
|
|
$schema->setTarget(Connection\Params\Php::HOST_TEMP); |
37
|
|
|
$this->assertEquals('tcp://', $schema->getSchema()); |
38
|
|
|
$this->assertEquals('temp', $schema->getHost()); |
39
|
|
|
$this->assertEquals(1, $schema->getPort()); |
40
|
|
|
$this->assertEquals(30, $schema->getTimeout()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testHttp(): void |
44
|
|
|
{ |
45
|
|
|
$schema = new Connection\Params\Tcp(); |
46
|
|
|
$lineSett = new Protocols\Http\Query(); |
47
|
|
|
$schema->setRequest($lineSett->setHost(Connection\Params\Php::HOST_MEMORY)->setPort(123456)); |
48
|
|
|
$this->assertEquals('memory', $schema->getHost()); |
49
|
|
|
$this->assertEquals(123456, $schema->getPort()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testUdp(): void |
53
|
|
|
{ |
54
|
|
|
$schema = new Connection\Params\Udp(); |
55
|
|
|
$this->assertEquals('udp://', $schema->getSchema()); |
56
|
|
|
$this->assertEquals(SOL_UDP, $schema->getProtocolVersion()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testSsl(): void |
60
|
|
|
{ |
61
|
|
|
$schema = new Connection\Params\Ssl(); |
62
|
|
|
$this->assertEquals('ssl://', $schema->getSchema()); |
63
|
|
|
$this->assertEquals(SOL_TCP, $schema->getProtocolVersion()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testPhp(): void |
67
|
|
|
{ |
68
|
|
|
$schema = new Connection\Params\Php(); |
69
|
|
|
$this->assertEquals('php://', $schema->getSchema()); |
70
|
|
|
$this->assertEquals(0, $schema->getProtocolVersion()); |
71
|
|
|
$this->assertNull($schema->getPort()); |
|
|
|
|
72
|
|
|
$this->assertNull($schema->getTimeout()); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testFile(): void |
76
|
|
|
{ |
77
|
|
|
$schema = new Connection\Params\File(); |
78
|
|
|
$this->assertEquals('file://', $schema->getSchema()); |
79
|
|
|
$this->assertEquals(0, $schema->getProtocolVersion()); |
80
|
|
|
$this->assertNull($schema->getPort()); |
|
|
|
|
81
|
|
|
$this->assertNull($schema->getTimeout()); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @throws RequestException |
86
|
|
|
*/ |
87
|
|
|
public function testFail(): void |
88
|
|
|
{ |
89
|
|
|
$this->expectException(RequestException::class); |
90
|
|
|
Connection\Params\Factory::getForSchema(new Translations(), 'unknown'); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.