Completed
Push — master ( 0f7687...6db947 )
by Arthur
01:19
created

WebSocketSslClientTest::it_sends_msg_over_ssl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
4
namespace WSSCTEST;
5
6
7
use PHPUnit\Framework\TestCase;
8
use WSSC\Components\ClientConfig;
9
use WSSC\Exceptions\BadOpcodeException;
10
use WSSC\WebSocketClient;
11
12
class WebSocketSslClientTest extends TestCase
13
{
14
    private const WS_SCHEME = 'wss://';
15
    private const WS_HOST = 'localhost';
16
    private const WS_PORT = ':8888';
17
    private const WS_URI = '/notifications/messanger/vkjsndfvjn23243';
18
19
    private $url;
20
21
    public function setUp()/* The :void return type declaration that should be here would cause a BC issue */
22
    {
23
        $this->url = self::WS_SCHEME . self::WS_HOST . self::WS_PORT . self::WS_URI;
24
    }
25
26
    /**
27
     * @test
28
     * @throws \Exception
29
     */
30
    public function it_sends_msg_over_ssl()
31
    {
32
        $recvMsg = '{"user_id" : 123}';
33
        $client = new WebSocketClient($this->url, (new ClientConfig())->setContextOptions([
34
            'ssl' => [
35
                'allow_self_signed' => true,
36
                'verify_peer' => false,
37
//                'cafile' => './tests/certs/cert.pem',
38
                'local_cert' => './tests/certs/cert.pem',
39
            ]
40
        ]));
41
        try {
42
            $client->send($recvMsg);
43
        } catch (BadOpcodeException $e) {
44
            echo 'Couldn`t sent: ' . $e->getMessage();
45
        }
46
        $recv = $client->receive();
47
        $this->assertEquals($recv, $recvMsg);
48
    }
49
}