本文整理汇总了PHP中Slim\Environment::mock方法的典型用法代码示例。如果您正苦于以下问题:PHP Environment::mock方法的具体用法?PHP Environment::mock怎么用?PHP Environment::mock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Environment
的用法示例。
在下文中一共展示了Environment::mock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: request
private function request($method, $path, $data = array(), $optionalHeaders = array())
{
// Capture STDOUT
ob_start();
$options = array('REQUEST_METHOD' => strtoupper($method), 'PATH_INFO' => $path, 'SERVER_NAME' => 'local.dev');
if ($method === 'get') {
$options['QUERY_STRING'] = http_build_query($data);
} elseif (is_array($data)) {
$options['slim.input'] = http_build_query($data);
} else {
$options['slim.input'] = $data;
}
// Prepare a mock environment
Slim\Environment::mock(array_merge($options, $optionalHeaders));
$env = Slim\Environment::getInstance();
$this->app->router = new NoCacheRouter($this->app->router);
$this->app->request = new Slim\Http\Request($env);
// Custom headers
$this->app->request->headers = new Slim\Http\Headers($env);
$this->app->response = new Slim\Http\Response();
// Establish some useful references to the slim app properties
$this->request = $this->app->request();
$this->response = $this->app->response();
// Execute our app
$this->app->run();
// Return the application output. Also available in `response->body()`
return ob_get_clean();
}
示例2: setUp
protected function setUp()
{
define('SERVER_SCRIPT', 'unittest');
\Slim\Environment::mock();
\Application\Bootstrap::init();
\Library\SFacebook::init();
}
示例3: testRouteAuthentication
/**
* @dataProvider authenticationDataProvider
*/
public function testRouteAuthentication($requestMethod, $path, $location, $hasIdentity, $identity, $httpStatus)
{
\Slim\Environment::mock(array('REQUEST_METHOD' => $requestMethod, 'PATH_INFO' => $path));
$this->auth->expects($this->once())->method('hasIdentity')->will($this->returnValue($hasIdentity));
$this->auth->expects($this->once())->method('getIdentity')->will($this->returnValue($identity));
$app = new \Slim\Slim(array('debug' => false));
$app->error(function (\Exception $e) use($app) {
// Example of handling Auth Exceptions
if ($e instanceof AuthException) {
$app->response->setStatus($e->getCode());
$app->response->setBody($e->getMessage());
}
});
$app->get('/', function () {
});
$app->get('/member', function () {
});
$app->delete('/member/photo/:id', function ($id) {
});
$app->get('/admin', function () {
});
$app->map('/login', function () {
})->via('GET', 'POST')->name('login');
$app->add($this->middleware);
ob_start();
$app->run();
ob_end_clean();
$this->assertEquals($httpStatus, $app->response->status());
$this->assertEquals($location, $app->response->header('location'));
}
示例4: testAdminNavigation
public function testAdminNavigation()
{
\Slim\Environment::mock(array('SCRIPT_NAME' => '', 'PATH_INFO' => '/admin'));
$app = new \Slim\Slim();
$app->view(new \Slim\View());
$app->get('/admin', function () {
echo 'Success';
});
$auththenticationService = $this->getMock('Zend\\Authentication\\AuthenticationService');
$auththenticationService->expects($this->once())->method('hasIdentity')->will($this->returnValue(true));
$mw = new Navigation($auththenticationService);
$mw->setApplication($app);
$mw->setNextMiddleware($app);
$mw->call();
$response = $app->response();
$navigation = $app->view()->getData('navigation');
$this->assertNotNull($navigation);
$this->assertInternalType('array', $navigation);
$this->assertEquals(4, count($navigation));
$this->assertEquals('Home', $navigation[0]['caption']);
$this->assertEquals('/', $navigation[0]['href']);
$this->assertEquals('', $navigation[0]['class']);
$this->assertEquals('Admin', $navigation[1]['caption']);
$this->assertEquals('/admin', $navigation[1]['href']);
$this->assertEquals('active', $navigation[1]['class']);
$this->assertEquals('Settings', $navigation[2]['caption']);
$this->assertEquals('/admin/settings', $navigation[2]['href']);
$this->assertEquals('', $navigation[2]['class']);
$this->assertEquals('Logout', $navigation[3]['caption']);
$this->assertEquals('/logout', $navigation[3]['href']);
$this->assertEquals('', $navigation[3]['class']);
}
示例5: testDefaultLayoutFromAppConfiguration
public function testDefaultLayoutFromAppConfiguration()
{
\Slim\Environment::mock();
$this->app = new \Slim\Slim(array('layout' => 'layout_from_app.php'));
$output = $this->view->fetch('simple.php');
$this->assertEquals("<div>Hello World\n</div>", trim($output));
}
示例6: testRespond
public function testRespond()
{
Environment::mock(array('REQUEST_METHOD' => 'GET'));
$deal = new Deal();
$deal->respond('test');
$this->assertEquals('test', unserialize($deal->response()->body()));
}
示例7: testUnknownFeatureGets404
public function testUnknownFeatureGets404()
{
Environment::mock(array('PATH_INFO' => '/features/unknown'));
$response = $this->app->invoke();
$this->assertEquals(json_encode(array("status" => 404, "statusText" => "Not Found", "description" => "Resource /features/unknown using GET method does not exist.")), $response->getBody());
$this->assertEquals(404, $response->getStatus());
}
示例8: req
public function req($path = '/', $method = 'GET', $input = '', $option = [])
{
// $app->post() が $_POSTにfallbackするので対応
$_POST_OLD = [];
if ($method === 'POST') {
$_POST_OLD = $_POST;
parse_str($input, $_POST);
}
// create slim mock with settings.
\Slim\Environment::mock(array_merge(['REQUEST_METHOD' => $method, 'PATH_INFO' => $path, 'slim.input' => $input, 'SCRIPT_NAME' => '', 'QUERY_STRING' => '', 'SERVER_NAME' => 'localhost', 'SERVER_PORT' => 80, 'ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'ACCEPT_LANGUAGE' => 'ja,en;q=0.7,zh;q=0.3', 'ACCEPT_CHARSET' => 'UTF-8', 'USER_AGENT' => 'PHP UnitTest', 'REMOTE_ADDR' => '127.0.0.1', 'slim.url_scheme' => 'http', 'slim.errors' => @fopen('php://stderr', 'w')], $option));
$app = static::createSlim();
// \Slim\Slim::getInstance() response only FIRST MADE instance now(2014/05/27).
// slim constructor DON'T overwrite \Slim\Slim::$apps when new slim instance
// bellow code, force overwrite cached instance.
// This is important when you use \Slim\Slim::getInstance().
// (I was falling in hole, when use Class controllers(slim>=2.4.0))
$app->setName('default');
// registration route to slim.
static::registrationRoute($app);
ob_start();
$app->run();
if ($method === 'POST') {
$_POST = $_POST_OLD;
}
return ob_get_clean();
}
示例9: setUp
public function setUp()
{
parent::setUp();
/** Mock the Environment (taken from the Slim tests...) **/
\Slim\Environment::mock(array('SCRIPT_NAME' => '/foo', 'PATH_INFO' => '/bar', 'QUERY_STRING' => 'one=foo&two=bar', 'SERVER_NAME' => 'slimframework.com'));
$this->app = new \Bistro\Swell\App(array('web.path' => '/subdirectory', 'database.dsn' => "sqlite::memory:"));
}
示例10: test_can_reject_login
/**
* invalid credentials should be rejected
**/
public function test_can_reject_login()
{
\Slim\Environment::mock(['PATH_INFO' => '/auth/login', 'REQUEST_METHOD' => 'POST', 'slim.input' => 'username=dubious&password=incorrect']);
$this->kernel->app->call();
$status = $this->kernel->app->response->getStatus();
$this->assertEquals(401, $status);
}
示例11: setUrl
protected function setUrl($path, $params = '', $config = array())
{
Environment::mock(array('REQUEST_METHOD' => 'GET', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '', 'PATH_INFO' => $path, 'QUERY_STRING' => $params, 'SERVER_NAME' => 'slim', 'SERVER_PORT' => 80, 'slim.url_scheme' => 'http', 'slim.input' => '', 'slim.errors' => fopen('php://stderr', 'w'), 'HTTP_HOST' => 'slim'));
$this->env = Environment::getInstance();
$this->req = new Request($this->env);
$this->res = new Response();
$this->app = new Slim(array_merge(array('controller.class_prefix' => '\\SlimController\\Tests\\Fixtures\\Controller', 'controller.class_suffix' => 'Controller', 'controller.method_suffix' => 'Action', 'controller.template_suffix' => 'php', 'templates.path' => __DIR__ . '/Fixtures/templates'), $config));
}
示例12: _getResponse
/**
*
* @return array ['status', 'headers', 'body']
*/
protected function _getResponse($envArgs)
{
\Slim\Environment::mock($envArgs);
$app = new \Slim\Slim();
new \Voce\Thermal\v1\API($app);
$app->call();
return $app->response()->finalize();
}
示例13: testAuthenticateBad
public function testAuthenticateBad()
{
Environment::mock(array('PHP_AUTH_USER' => 'foo', 'PHP_AUTH_PW' => 'sizle'));
$deal = new Deal();
$storage = new None();
$auth = new HttpAuth($storage, $deal);
$auth->generateKeyPair('foo', 'bar');
$this->assertFalse($auth->authenticate());
}
示例14: request
protected function request($method, $path, $options = array())
{
ob_start();
\Slim\Environment::mock(array_merge(array('REQUEST_METHOD' => $method, 'PATH_INFO' => $path, 'SERVER_NAME' => 'local.dev'), $options));
$this->request = $this->app->request();
$this->response = $this->app->response();
$this->app->run();
return ob_get_clean();
}
示例15: setUp
public function setUp()
{
//Remove environment mode if set
unset($_ENV['SLIM_MODE']);
//Reset session
$_SESSION = array();
//Prepare default environment variables
\Slim\Environment::mock(array('PATH_INFO' => '/bar', 'QUERY_STRING' => 'one=foo&two=bar', 'SERVER_NAME' => 'slimframework.com'));
date_default_timezone_set('Asia/Dubai');
}