Passed
Pull Request — master (#63)
by Eugene
02:57
created

ParseGreetingTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 23
dl 0
loc 47
rs 10
c 1
b 0
f 1
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testParseGreetingWithInvalidSalt() 0 14 1
A testParseGreetingWithInvalidServerName() 0 23 3
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\Connection;
15
16
use Tarantool\Client\Exception\CommunicationFailed;
17
use Tarantool\Client\Tests\Integration\ClientBuilder;
18
use Tarantool\Client\Tests\Integration\FakeServer\FakeServerBuilder;
0 ignored issues
show
Bug introduced by
The type Tarantool\Client\Tests\I...erver\FakeServerBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Tarantool\Client\Tests\Integration\FakeServer\Handler\WriteHandler;
20
use Tarantool\Client\Tests\Integration\TestCase;
21
22
final class ParseGreetingTest extends TestCase
23
{
24
    /**
25
     * @dataProvider \Tarantool\Client\Tests\GreetingDataProvider::provideGreetingsWithInvalidServerName
26
     */
27
    public function testParseGreetingWithInvalidServerName(string $greeting) : void
28
    {
29
        $clientBuilder = ClientBuilder::createFromEnvForTheFakeServer();
30
31
        FakeServerBuilder::create(new WriteHandler($greeting))
32
            ->setUri($clientBuilder->getUri())
33
            ->start();
34
35
        $client = $clientBuilder->build();
36
37
        try {
38
            $client->ping();
39
        } catch (CommunicationFailed $e) {
40
            self::assertSame('Unable to read greeting.', $e->getMessage());
41
42
            return;
43
        } catch (\RuntimeException $e) {
44
            self::assertSame('Unable to recognize Tarantool server.', $e->getMessage());
45
46
            return;
47
        }
48
49
        self::fail();
50
    }
51
52
    /**
53
     * @dataProvider \Tarantool\Client\Tests\GreetingDataProvider::provideGreetingsWithInvalidSalt
54
     */
55
    public function testParseGreetingWithInvalidSalt(string $greeting) : void
56
    {
57
        $clientBuilder = ClientBuilder::createFromEnvForTheFakeServer();
58
59
        FakeServerBuilder::create(new WriteHandler($greeting))
60
            ->setUri($clientBuilder->getUri())
61
            ->start();
62
63
        $client = $clientBuilder->setOptions(['username' => 'guest'])->build();
64
65
        $this->expectException(\RuntimeException::class);
66
        $this->expectExceptionMessageRegExp('/(Unable to decode salt|Salt is too short)\./');
67
68
        $client->ping();
69
    }
70
}
71