public static function init($uri, $method, array $params = array(), array $options = array()) { self::reset(); $uri = parse_url($uri); $method = strtoupper($method); $_SERVER['REQUEST_URI'] = $uri; $_SERVER['REQUEST_METHOD'] = $method; if (isset($uri['query'])) { $_SERVER['QUERY_STRING'] = $uri['query']; parse_str($uri['query'], $_GET); } if ($method != 'GET') { $_POST = $params; } if (isset($options['ajax']) && $options['ajax']) { self::useAjax(); } if (isset($options['header'])) { foreach ($options['header'] as $key => $val) { self::setHeader($key, $val); } } $_COOKIE = \Test\Mock\Cookie::instance()->get($uri['path']); $_REQUEST = array_merge($_GET, $_POST, $_COOKIE); }
protected function __construct() { $this->cookie = \Test\Mock\Cookie::getInstance(); $this->_server = $_SERVER; }
public function setCookie($name, $value, $expire = 0, $path = '/', $domain = null, $secure = false, $httponly = true) { \Test\Mock\Cookie::instance()->set($name, $value, $expire, $path, $domain, $secure, $httponly); }
public function testBindIpCookieContext() { $mock_cookie = \Test\Mock\Cookie::getInstance(); $mock_cookie->reset(); $config = array('token' => 'test', 'sign_salt' => 'fdajkfldsjfldsf', 'bind_ip' => true); $_SERVER['REMOTE_ADDR'] = '192.168.1.1'; $handler = new \Lysine\CookieContextHandler($config); $handler->set('test', 'abc'); $mock_cookie->apply(); $handler->reset(); $_SERVER['REMOTE_ADDR'] = '192.168.1.3'; $this->assertEquals($handler->get('test'), 'abc', '同子网IP取值'); $handler->reset(); $_SERVER['REMOTE_ADDR'] = '192.168.2.1'; $this->assertNull($handler->get('test'), '不同子网IP取值'); }