1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the tarantool/client package. |
5
|
|
|
* |
6
|
|
|
* (c) Eugene Leonovich <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Tarantool\Client\Tests\Integration; |
15
|
|
|
|
16
|
|
|
use Tarantool\Client\Client; |
17
|
|
|
use Tarantool\Client\Connection\Connection; |
18
|
|
|
use Tarantool\Client\Connection\StreamConnection; |
19
|
|
|
use Tarantool\Client\Exception\CommunicationFailed; |
20
|
|
|
use Tarantool\Client\Handler\Handler; |
21
|
|
|
use Tarantool\Client\Request\Request; |
22
|
|
|
use Tarantool\Client\Tests\PhpUnitCompat; |
23
|
|
|
use Tarantool\PhpUnit\Annotation\Requirement\TarantoolVersionRequirement; |
24
|
|
|
use Tarantool\PhpUnit\TestCase as BaseTestCase; |
25
|
|
|
|
26
|
|
|
abstract class TestCase extends BaseTestCase |
27
|
|
|
{ |
28
|
|
|
use PhpUnitCompat; |
29
|
|
|
|
30
|
|
|
/** @var Client|null */ |
31
|
|
|
protected $client; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @before |
35
|
|
|
*/ |
36
|
|
|
protected function getClient() : Client |
37
|
|
|
{ |
38
|
|
|
return $this->client |
39
|
|
|
?? $this->client = ClientBuilder::createFromEnv()->build(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
final protected function tarantoolVersionSatisfies(string $constraints) : bool |
43
|
|
|
{ |
44
|
|
|
return null === (new TarantoolVersionRequirement($this->client))->check($constraints); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
final protected static function triggerUnexpectedResponse(Handler $handler, Request $initialRequest, int $sync = 0) : Connection |
48
|
|
|
{ |
49
|
|
|
$connection = $handler->getConnection(); |
50
|
|
|
$packer = $handler->getPacker(); |
51
|
|
|
$rawRequest = $packer->pack($initialRequest, $sync); |
52
|
|
|
|
53
|
|
|
// write a request without reading a response |
54
|
|
|
$connection->open(); |
55
|
|
|
if (!\fwrite(self::getRawStream($connection), $rawRequest)) { |
|
|
|
|
56
|
|
|
throw new CommunicationFailed('Unable to write request'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $connection; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
final public static function getRawStream(StreamConnection $connection) |
63
|
|
|
{ |
64
|
|
|
$prop = (new \ReflectionObject($connection))->getProperty('stream'); |
65
|
|
|
$prop->setAccessible(true); |
66
|
|
|
|
67
|
|
|
return $prop->getValue($connection); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: