Completed
Push — master ( 4e8823...6bd0b8 )
by Sébastien
04:52
created

Japha/Bridge/Driver/Pjb62/ClientTest.php (2 issues)

1
<?php
2
3
/*
4
 * Soluble Japha
5
 *
6
 * @link      https://github.com/belgattitude/soluble-japha
7
 * @copyright Copyright (c) 2013-2017 Vanvelthem Sébastien
8
 * @license   MIT License https://github.com/belgattitude/soluble-japha/blob/master/LICENSE.md
9
 */
10
11
namespace SolubleTest\Japha\Bridge\Driver\Pjb62;
12
13
use Psr\Log\NullLogger;
14
use Soluble\Japha\Bridge\Adapter;
15
use Soluble\Japha\Bridge\Driver\Pjb62\Client;
16
use Soluble\Japha\Bridge\Driver\Pjb62\PjbProxyClient;
17
use PHPUnit\Framework\TestCase;
18
use Soluble\Japha\Bridge\Driver\Pjb62\Protocol;
19
20
class ClientTest extends TestCase
21
{
22
    /**
23
     * @var string
24
     */
25
    protected $servlet_address;
26
27
    /**
28
     * @var Adapter
29
     */
30
    protected $adapter;
31
32
    /**
33
     * @var Client
34
     */
35
    protected $client;
36
37
    /**
38
     * Sets up the fixture, for example, opens a network connection.
39
     * This method is called before a test is executed.
40
     */
41 View Code Duplication
    protected function setUp()
42
    {
43
        $this->servlet_address = \SolubleTestFactories::getJavaBridgeServerAddress();
44
        $this->adapter = new Adapter([
45
            'driver' => 'Pjb62',
46
            'servlet_address' => $this->servlet_address,
47
        ]);
48
        $this->client = $this->adapter->getDriver()->getClient()->getClient();
49
    }
50
51
    /**
52
     * Tears down the fixture, for example, closes a network connection.
53
     * This method is called after a test is executed.
54
     */
55
    protected function tearDown()
56
    {
57
    }
58
59
    public function testCommon()
60
    {
61
        $conn = PjbProxyClient::parseServletUrl($this->servlet_address);
62
        $params = new \ArrayObject([
63
            Client::PARAM_JAVA_HOSTS => $conn['servlet_host'],
64
            Client::PARAM_JAVA_SERVLET => $conn['servlet_uri'],
65
            Client::PARAM_JAVA_SEND_SIZE => 4096,
66
            Client::PARAM_JAVA_RECV_SIZE => 8192,
67
            Client::PARAM_JAVA_INTERNAL_ENCODING => 'ISO-8859-1'
68
        ]);
69
70
        $client = new Client($params, new NullLogger());
71
72
        self::assertSame(4096, $client->java_send_size);
73
        self::assertSame(8192, $client->java_recv_size);
74
        self::assertSame('ISO-8859-1', $client->getParam(Client::PARAM_JAVA_INTERNAL_ENCODING));
75
        self::assertInstanceOf(NullLogger::class, $client->getLogger());
76
        //self::assertEquals($params, $client->getParams());
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
77
        self::assertEquals($conn['servlet_host'], $client->getServerName());
78
        $enc = $this->client->getParam(Client::PARAM_JAVA_INTERNAL_ENCODING);
79
        self::assertEquals('UTF-8', $enc);
80
    }
81
82
    public function testDefaults()
83
    {
84
        $conn = PjbProxyClient::parseServletUrl($this->servlet_address);
85
        $params = new \ArrayObject([
86
            'JAVA_HOSTS' => $conn['servlet_host'],
87
            'JAVA_SERVLET' => $conn['servlet_uri'],
88
        ]);
89
90
        $client = new Client($params, new NullLogger());
91
        self::assertEquals(Client::DEFAULT_PARAMS[Client::PARAM_JAVA_SEND_SIZE], $client->java_send_size);
92
        self::assertEquals(Client::DEFAULT_PARAMS[Client::PARAM_JAVA_RECV_SIZE], $client->java_recv_size);
93
    }
94
95
    public function testSetHandler()
96
    {
97
        $conn = PjbProxyClient::parseServletUrl($this->servlet_address);
98
        $params = new \ArrayObject([
99
            'JAVA_HOSTS' => $conn['servlet_host'],
100
            'JAVA_SERVLET' => $conn['servlet_uri'],
101
        ]);
102
103
        $client = new Client($params, new NullLogger());
104
        $client->setDefaultHandler();
105
106
        $this->client->setAsyncHandler();
107
        self::assertEquals($client->methodCache, $client->asyncCache);
108
    }
109
110
    public function testSetExitCode()
111
    {
112
        $conn = PjbProxyClient::parseServletUrl($this->servlet_address);
113
        $params = new \ArrayObject([
114
            'JAVA_HOSTS' => $conn['servlet_host'],
115
            'JAVA_SERVLET' => $conn['servlet_uri'],
116
            'JAVA_SEND_SIZE' => 4096,
117
            'JAVA_RECV_SIZE' => 8192
118
        ]);
119
120
        $client = new Client($params, new NullLogger());
121
        $client->setExitCode(1);
122
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
123
        $clientMock = $this->getMockBuilder(Client::class)
124
            ->disableOriginalConstructor()
125
            ->getMock();
126
127
128
        $protocolStub = $this->prophesize(Protocol::class);
129
        $protocolStub->writeExitCode()->shouldBeCalled();
130
        $protocolStub->writeExitCode();
131
132
        $clientMock->protocol = $protocolStub;
133
        $clientMock->setExitCode(0);
134
        */
135
    }
136
}
137