当前位置: 首页>>代码示例>>PHP>>正文


PHP Slim\Environment类代码示例

本文整理汇总了PHP中Slim\Environment的典型用法代码示例。如果您正苦于以下问题:PHP Environment类的具体用法?PHP Environment怎么用?PHP Environment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Environment类的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();
 }
开发者ID:hochanh,项目名称:slim-test-helpers,代码行数:28,代码来源:WebTestClient.php

示例2: 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));
 }
开发者ID:petebrowne,项目名称:slim-layout-view,代码行数:7,代码来源:LayoutViewTest.php

示例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'));
 }
开发者ID:urshofer,项目名称:slim-auth,代码行数:33,代码来源:AuthorizationTest.php

示例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']);
 }
开发者ID:neophyt3,项目名称:flaming-archer,代码行数:32,代码来源:NavigationTest.php

示例5: 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());
 }
开发者ID:narikenabilli,项目名称:generator-angular-php,代码行数:7,代码来源:FeaturesTest.php

示例6: 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);
 }
开发者ID:andela-bkagia,项目名称:php-checkpoints,代码行数:10,代码来源:AuthControllerTest.php

示例7: testRespond

 public function testRespond()
 {
     Environment::mock(array('REQUEST_METHOD' => 'GET'));
     $deal = new Deal();
     $deal->respond('test');
     $this->assertEquals('test', unserialize($deal->response()->body()));
 }
开发者ID:dwsla,项目名称:deal,代码行数:7,代码来源:DealTest.php

示例8: 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:"));
 }
开发者ID:bistro,项目名称:swell,代码行数:7,代码来源:AppTest.php

示例9: setUp

 protected function setUp()
 {
     define('SERVER_SCRIPT', 'unittest');
     \Slim\Environment::mock();
     \Application\Bootstrap::init();
     \Library\SFacebook::init();
 }
开发者ID:konstantin-pr,项目名称:Ses,代码行数:7,代码来源:DBTest.php

示例10: 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();
 }
开发者ID:h-inuzuka,项目名称:quiz,代码行数:26,代码来源:MockSlimClient.php

示例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));
 }
开发者ID:andrearruda,项目名称:Farol-Sign-UOL-Feed,代码行数:8,代码来源:TestCase.php

示例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();
 }
开发者ID:katymdc,项目名称:thermal-api,代码行数:12,代码来源:APITestCase.php

示例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());
 }
开发者ID:dwsla,项目名称:deal,代码行数:9,代码来源:HttpAuthTest.php

示例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();
 }
开发者ID:aigdonia,项目名称:Slim-Light,代码行数:9,代码来源:ResourceControllerTest.php

示例15: request

 public function request($method, $path, $options = array())
 {
     ob_start();
     Environment::mock(array_merge(array('PATH_INFO' => $path, 'SERVER_NAME' => 'slim-test.dev', 'REQUEST_METHOD' => $method), $options));
     $app = new Slim();
     $this->app = $app;
     $this->request = $app->request();
     $this->response = $app->response();
     return ob_get_clean();
 }
开发者ID:emeka-osuagwu,项目名称:sweetemoji,代码行数:10,代码来源:RouteTest.php


注:本文中的Slim\Environment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。