Passed
Push — master ( 8dceab...2d1996 )
by Benjamin
15:07 queued 12:31
created

IgnoreErrorTransportWrapperTest::buildTransport()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Gelf\Test\Transport;
5
6
use Gelf\MessageInterface;
7
use Gelf\Transport\IgnoreErrorTransportWrapper;
8
use Gelf\Transport\TransportInterface;
9
use PHPUnit\Framework\MockObject\MockObject;
10
use PHPUnit\Framework\TestCase;
11
use RuntimeException;
12
13
class IgnoreErrorTransportWrapperTest extends TestCase
14
{
15
    public function testSend(): void
16
    {
17
        $expectedMessage   = $this->buildMessage();
18
        $expectedException = new RuntimeException();
19
20
        $transport = $this->buildTransport();
21
        $wrapper   = new IgnoreErrorTransportWrapper($transport);
22
23
        $transport->expects($this->once())
24
                  ->method('send')
25
                  ->with($expectedMessage)
26
                  ->willThrowException($expectedException);
27
28
        $bytes = $wrapper->send($expectedMessage);
29
        $lastError = $wrapper->getLastError();
30
31
        self::assertEquals(0, $bytes);
32
        self::assertSame($expectedException, $lastError);
33
    }
34
35
    private function buildTransport(): MockObject|TransportInterface
36
    {
37
        return $this->createMock(TransportInterface::class);
38
    }
39
40
    private function buildMessage(): MockObject|MessageInterface
41
    {
42
        return $this->createMock(MessageInterface::class);
43
    }
44
}
45