Completed
Pull Request — master (#12)
by Harry
02:19
created

SendTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 23
rs 10
c 1
b 0
f 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testSendFailure() 0 20 1
1
<?php
2
/**
3
 * This file is part of graze/dog-statsd
4
 *
5
 * Copyright (c) 2017 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/dog-statsd/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/dog-statsd
12
 */
13
14
namespace Graze\DogStatsD\Test\Unit;
15
16
use Graze\DogStatsD\Client;
17
use Graze\DogStatsD\Test\TestCase;
18
use ReflectionProperty;
19
20
class SendTest extends TestCase
21
{
22
    public function testSendFailure()
23
    {
24
        // create a connection, kill the udp connection (without changing the socket), attempt to send, should re-connect and send again
25
        $client = new Client();
26
        $client->configure(['host' => '127.0.0.1']);
27
28
        // create the connection
29
        $client->increment('metric', 1);
30
31
        // close the socket
32
        $reflector = new ReflectionProperty(Client::class, 'socket');
33
        $reflector->setAccessible(true);
34
        $socket = $reflector->getValue($client);
35
        fclose($socket);
36
37
        $client->increment('reconnect', 1);
38
        $this->assertEquals('reconnect:1|c', $client->getLastMessage());
39
40
        $this->assertAttributeInternalType('resource', 'socket', $client);
41
    }
42
}
43