php Slim-Environment类(方法)实例源码

下面列出了php Slim-Environment 类(方法)源码代码实例,从而了解它的用法。

作者:hochan    项目:slim-test-helper   
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();
 }

作者:petebrown    项目:slim-layout-vie   
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));
 }

作者:urshofe    项目:slim-aut   
/**
  * @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'));
 }

作者:neophyt    项目:flaming-arche   
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']);
 }

作者:narikenabill    项目:generator-angular-ph   
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());
 }

作者:andela-bkagi    项目:php-checkpoint   
/**
  * 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);
 }

作者:dwsl    项目:dea   
public function testRespond()
 {
     Environment::mock(array('REQUEST_METHOD' => 'GET'));
     $deal = new Deal();
     $deal->respond('test');
     $this->assertEquals('test', unserialize($deal->response()->body()));
 }

作者:bistr    项目:swel   
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:"));
 }

作者:konstantin-p    项目:Se   
protected function setUp()
 {
     define('SERVER_SCRIPT', 'unittest');
     \Slim\Environment::mock();
     \Application\Bootstrap::init();
     \Library\SFacebook::init();
 }

作者:h-inuzuk    项目:qui   
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();
 }

作者:andrearrud    项目:Farol-Sign-UOL-Fee   
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));
 }

作者:katymd    项目:thermal-ap   
/**
  * 
  * @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();
 }

作者:dwsl    项目:dea   
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());
 }

作者:aigdoni    项目:Slim-Ligh   
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();
 }

作者:emeka-osuagw    项目:sweetemoj   
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();
 }

作者:kuslahn    项目:TextPres   
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');
 }

作者:BCalda    项目:Slim-Middlewar   
public function testBestFormatWithPriorities()
 {
     \Slim\Environment::mock(array('ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'negotiation.priorities' => array('xml')));
     $s = new \Slim\Slim();
     $s->add(new ContentNegotiation());
     $s->run();
     $env = \Slim\Environment::getInstance();
     $bestFormat = $env['request.best_format'];
     $this->assertNotNull($bestFormat);
     $this->assertEquals('xml', $bestFormat);
 }

作者:narikenabill    项目:generator-angular-ph   
public function testUnkownHttpStatusExceptionGenerates500()
 {
     $app = new Application();
     $app->get('/api/test/undefined-exception', function () {
         throw new Exception('Exception with unknown HTTP status', 999);
     });
     Environment::mock(array('PATH_INFO' => '/api/test/undefined-exception'));
     $response = $app->invoke();
     $this->assertEquals(json_encode(array('status' => 500, 'statusText' => 'Internal Server Error', 'description' => 'Exception with unknown HTTP status')), $response->getBody());
     $this->assertEquals(500, $response->getStatus());
 }

作者:prolificinteractiv    项目:mab   
public function setUpApp($env = array(), $withCache = false)
 {
     \Slim\Environment::mock($env);
     $this->app = new App();
     $this->dataConnectionMock = $this->getMock('\\MABI\\Testing\\MockDataConnection', array('findOneByField', 'query', 'insert', 'save', 'deleteByField', 'clearAll', 'getNewId', 'findAll', 'findAllByField'));
     $this->app->addDataConnection('default', $this->dataConnectionMock);
     if ($withCache) {
         $this->app->addCacheRepository('system', 'file', array('path' => 'TestApp/cache'));
     }
     $this->app->getErrorResponseDictionary()->overrideErrorResponses(new Errors());
 }

作者:katymd    项目:thermal-ap   
public function testBadRoute()
 {
     \Slim\Environment::mock(array('REQUEST_METHOD' => 'GET', 'PATH_INFO' => Voce\Thermal\get_api_base() . 'v1/foobar'));
     $app = new \Slim\Slim();
     $apiTest = new API_Test_v1($app);
     ob_start();
     $apiTest->app->run();
     ob_end_clean();
     $response = $apiTest->app->response();
     $this->assertObjectHasAttribute('error', json_decode($response->body()));
 }


问题


面经


文章

微信
公众号

扫码关注公众号