WebSocketSslClientTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 19
dl 0
loc 36
rs 10
c 1
b 1
f 0
wmc 3

2 Methods

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