示例#1
0
 /**
  * @covers ::get
  */
 public function testGetNonexistent()
 {
     $this->expectException(ConfigurationNonexistentException::class);
     $this->expectExceptionMessage('Configuration foo is nonexistent');
     $configuration = new Configuration();
     $configuration->get('foo');
 }
示例#2
0
 public function setUp()
 {
     $this->pdo = new \PDO("mysql:host=127.0.0.1;dbname=tests", 'root', '');
     $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     $this->pdo->exec('SET NAMES utf8');
     $this->configuration = new Configuration();
     $this->configuration->set('App.Path', '/var/www/html/');
     $this->request = new Request(new Cookie($this->configuration));
 }
示例#3
0
 /**
  * @covers ::dispatch
  */
 public function testDispatch()
 {
     $router = new Router();
     $router->connect('\\/cars', CarsController::class, 'index');
     $configuration = new Configuration();
     $configuration->set('Router', $router);
     $configuration->set('App.Path', realpath(dirname(__FILE__)) . '/../../src/');
     $dispatcher = new Dispatcher($this->pdo, $configuration);
     $cookie = new Cookie($configuration);
     $request = new Request($cookie, ['REQUEST_URI' => '/cars'], []);
     $response = $dispatcher->dispatch($request);
     $this->assertSame(['content-type' => 'Content-Type: text/html; charset=utf-8'], $response->getHeaders());
     $this->assertSame($cookie, $response->getCookie());
     $this->assertSame('<h1>Auto</h1><p>Ford Model T</p><p>Ford Model A</p>', $response->getOutput());
 }
示例#4
0
文件: Cookie.php 项目: zortje/mvc
 /**
  * Validates token for cookie and returns values if valid
  *
  * @param string $token
  *
  * @return array
  */
 protected function parseAndValidateToken(string $token)
 {
     try {
         $token = (new Parser())->parse($token);
         // @todo How to test: It will use the current time to validate (iat, nbf and exp)
         $data = new ValidationData();
         $data->setIssuer(self::ISSUER);
         $values = [];
         if ($token->validate($data) && $token->verify(new Sha256(), $this->configuration->get('Cookie.Signer.Key'))) {
             /**
              * @var Claim $claim
              */
             $ignored = array_fill_keys(['iss', 'exp'], true);
             foreach ($token->getClaims() as $claim) {
                 if (isset($ignored[$claim->getName()])) {
                     continue;
                 }
                 $values[$claim->getName()] = $claim->getValue();
             }
         }
         return $values;
     } catch (\InvalidArgumentException $e) {
         return [];
     }
 }
示例#5
0
文件: Controller.php 项目: zortje/mvc
 /**
  * Get view template
  *
  * @return string View template file path
  */
 protected function getViewTemplate() : string
 {
     $view = $this->view;
     if (empty($view)) {
         $view = sprintf('View/%s/%s', $this->getShortName(), $this->action);
     }
     return "{$this->configuration->get('App.Path')}{$view}.view";
 }