-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathServerAddressTest.php
63 lines (57 loc) · 1.67 KB
/
ServerAddressTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\HTTP\Test\Unit\PhpEnvironment;
class ServerAddressTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Framework\HTTP\PhpEnvironment\ServerAddress
*/
protected $_serverAddress;
/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Request\Http
*/
protected $_request;
protected function setUp()
{
$this->_request = $this->getMockBuilder(
'Magento\Framework\App\Request\Http'
)->disableOriginalConstructor()->setMethods(
['getServer']
)->getMock();
$objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
$this->_serverAddress = $objectManager->getObject(
'Magento\Framework\HTTP\PhpEnvironment\ServerAddress',
['httpRequest' => $this->_request]
);
}
/**
* @dataProvider getServerAddressProvider
*/
public function testGetServerAddress($serverVar, $expected, $ipToLong)
{
$this->_request->expects(
$this->atLeastOnce()
)->method(
'getServer'
)->with(
'SERVER_ADDR'
)->will(
$this->returnValue($serverVar)
);
$this->assertEquals($expected, $this->_serverAddress->getServerAddress($ipToLong));
}
/**
* @return array
*/
public function getServerAddressProvider()
{
return [
[null, false, false],
['192.168.0.1', '192.168.0.1', false],
['192.168.1.1', ip2long('192.168.1.1'), true]
];
}
}