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\TestCase as BaseTestCase; |
24
|
|
|
|
25
|
|
|
abstract class TestCase extends BaseTestCase |
26
|
|
|
{ |
27
|
|
|
use PhpUnitCompat; |
28
|
|
|
|
29
|
|
|
protected $client; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @before |
33
|
|
|
*/ |
34
|
|
|
protected function getClient() : Client |
35
|
|
|
{ |
36
|
|
|
return $this->client |
37
|
|
|
?? $this->client = ClientBuilder::createFromEnv()->build(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
final protected static function triggerUnexpectedResponse(Handler $handler, Request $initialRequest, int $sync = 0) : Connection |
41
|
|
|
{ |
42
|
|
|
$connection = $handler->getConnection(); |
43
|
|
|
$packer = $handler->getPacker(); |
44
|
|
|
$rawRequest = $packer->pack($initialRequest, $sync); |
45
|
|
|
|
46
|
|
|
// write a request without reading a response |
47
|
|
|
$connection->open(); |
48
|
|
|
if (!\fwrite(self::getRawStream($connection), $rawRequest)) { |
|
|
|
|
49
|
|
|
throw new CommunicationFailed('Unable to write request'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $connection; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
final public static function getRawStream(StreamConnection $connection) |
56
|
|
|
{ |
57
|
|
|
$prop = (new \ReflectionObject($connection))->getProperty('stream'); |
58
|
|
|
$prop->setAccessible(true); |
59
|
|
|
|
60
|
|
|
return $prop->getValue($connection); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.