Пример #1
0
 public function testTraitError()
 {
     $this->setExpectedException("RuntimeException");
     $request = \FabysCore\Component\HTTP\ServerRequest::createNew([], [], [], [], ["HTTP_USER_AGENT" => "test", "REMOTE_ADDR" => "127.0.0.1", "REQUEST_METHOD" => "GET", "HTTP_HOST" => "localhost", "REQUEST_URI" => "/", "SCRIPT_NAME" => "index.php"]);
     $traitUser = new SessionTraitUser();
     $traitUser->getSession($request);
 }
Пример #2
0
function main()
{
    /* create application */
    $cacheStorage = new FileStorage(__DIR__ . "/../var/cache/");
    $logHandler = new StreamHandler(__DIR__ . "/../var/logs/fabyscore.log");
    $app = new Application($cacheStorage, $logHandler, \Psr\Log\LogLevel::INFO);
    /* enable debug mode */
    $app->enableDebugMode();
    /* application setup */
    $app->setup(function () use($app) {
        /* parameters */
        $app->addParameter("secret", "IamASecretString");
        /* services */
        $app->addService("controller.example", ExampleController::class, ["@kernel.container"]);
        $app->addService("controller.error", ErrorController::class);
        /* middleware */
        $app->error(["@controller.error", "errorAction"]);
        $app->before(["@controller.example", "beforeAction"]);
        $app->after(["@controller.example", "afterAction"]);
        /* routes */
        $app->get("/{name}", ["@controller.example", "indexAction"], [-1024 => ["@controller.example", "beforeRouteAction"]], [["@controller.example", "afterRouteAction"]]);
        $app->post("/{name}", ["@controller.example", "indexAction"]);
    });
    /* run application */
    $request = ServerRequest::createNew($_GET, $_POST, $_FILES, $_COOKIE, $_SERVER, $_ENV);
    $app->run($request);
}
Пример #3
0
 public function testTraitError()
 {
     $this->setExpectedException("RuntimeException");
     $request = \FabysCore\Component\HTTP\ServerRequest::createNew([], [], [], [], ["REQUEST_METHOD" => "GET", "HTTP_HOST" => "localhost", "REQUEST_URI" => "/", "SCRIPT_NAME" => "index.php"]);
     $traitUser = new DatabaseTraitUser();
     $traitUser->getDatabase($request);
 }
Пример #4
0
 public function testStartInvalidFingerprint()
 {
     $handler = new \FabysCore\Component\Session\Handler\NativeSessionHandler();
     $arraySession = new \FabysCore\Component\Session\Type\ArraySession($handler);
     $arraySession->set("test", "value");
     $request = \FabysCore\Component\HTTP\ServerRequest::createNew([], [], [], [], ["HTTP_USER_AGENT" => "test", "REMOTE_ADDR" => "127.0.0.1", "REQUEST_METHOD" => "GET", "HTTP_HOST" => "localhost", "REQUEST_URI" => "/", "SCRIPT_NAME" => "index.php"]);
     $response = new \FabysCore\Component\HTTP\Response();
     $session = new \FabysCore\Component\Session\Session($arraySession, 60);
     $called = false;
     $session->init($request, $response, function (\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response) use(&$called) {
         $called = true;
     });
     $this->assertTrue($called);
     $this->assertTrue($session->start());
     $this->assertEquals("value", $session->get("test"));
     $fingerPrint = $session->get("fabyscore._sessfingerprint");
     $this->assertNotEmpty($fingerPrint);
     $request = \FabysCore\Component\HTTP\ServerRequest::createNew([], [], [], [], ["HTTP_USER_AGENT" => "changed", "REMOTE_ADDR" => "127.0.0.1", "REQUEST_METHOD" => "GET", "HTTP_HOST" => "localhost", "REQUEST_URI" => "/", "SCRIPT_NAME" => "index.php"]);
     $session2 = new \FabysCore\Component\Session\Session($arraySession, 60);
     $called = false;
     $session2->init($request, $response, function (\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response) use(&$called) {
         $called = true;
     });
     $this->assertTrue($called);
     $this->assertTrue($session2->start());
     $this->assertNull($session->get("test"));
     $this->assertNotEquals($fingerPrint, $session->get("fabyscore._sessfingerprint"));
 }
 public function testRunReturn()
 {
     $runner = new \FabysCore\Kernel\MiddlewareRunner((function () {
         (yield ["RunnerService", "middlewareReturns"]);
         (yield ["RunnerService", "middleware"]);
     })(), $this->app);
     $request = \FabysCore\Component\HTTP\ServerRequest::createNew([], [], [], [], []);
     $response = $runner->run($request, new \FabysCore\Component\HTTP\Response());
     $response->getBody()->rewind();
     $this->assertEquals($response->getBody()->getContents(), "return");
 }
 public function setUp()
 {
     $this->request = \FabysCore\Component\HTTP\ServerRequest::createNew([], [], [], [], ["HTTP_USER_AGENT" => "test", "REMOTE_ADDR" => "127.0.0.1", "REQUEST_METHOD" => "GET", "HTTP_HOST" => "localhost", "REQUEST_URI" => "/", "SCRIPT_NAME" => "index.php"]);
     $this->response = new \FabysCore\Component\HTTP\Response();
     $sessionStub = $this->getMockBuilder('FabysCore\\Component\\Session\\Session')->disableOriginalConstructor()->getMock();
     $this->sessionStub = $sessionStub;
     $this->request = $this->request->withAttribute(\FabysCore\Component\Session\Session::REQUEST_ATTRIBUTE, $this->sessionStub);
     $cache = new \FabysCore\Component\Cache\Cache(new \FabysCore\Component\Cache\Storage\FileStorage(__DIR__ . "/"));
     $config = new \FabysCore\Kernel\Configuration($cache);
     $config->setParameter("login_success_route", "/login_success");
     $config->setParameter("login_route", "/login");
     $config->setParameter("logout_route", "/logout_success");
     $this->request = $this->request->withAttribute(\FabysCore\Kernel\Configuration::REQUEST_ATTRIBUTE, $config);
     $this->securityController = new \FabysCore\Component\Security\Controller();
 }
 public function testInit()
 {
     $request = \FabysCore\Component\HTTP\ServerRequest::createNew([], [], [], [], ["REQUEST_METHOD" => "GET", "HTTP_HOST" => "localhost", "REQUEST_URI" => "/", "SCRIPT_NAME" => "index.php"]);
     $response = new \FabysCore\Component\HTTP\Response();
     $called = false;
     $this->authenticationManager->init($request, $response, function (\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response) use(&$called) {
         $called = true;
         $this->assertInstanceOf(AuthenticationManager::class, $request->getAttribute(AuthenticationManager::REQUEST_ATTRIBUTE));
     });
     $this->assertTrue($called);
 }
Пример #8
0
 /**
  * @runInSeparateProcess
  */
 public function testRunSendHeaders()
 {
     $this->expectOutputString("testcontent");
     $app = $this->app;
     $app->setup(function () use($app) {
         $app->parameter("testparam", "value");
         $app->addService("app.service", "AppService", ["@kernel.container", "%testparam", "teststring"]);
         $app->get("/", ["AppController", "indexAction"]);
     });
     $request = \FabysCore\Component\HTTP\ServerRequest::createNew([], [], [], [], ["HTTP_HOST" => "localhost", "REQUEST_URI" => "/", "SCRIPT_NAME" => "index.php"]);
     $app->run($request);
 }