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

WebSocketSslClientTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A it_sends_msg_over_ssl() 0 19 2
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
}