Exemplo n.º 1
0
 public function testAppIsResetted()
 {
     Apricot::when('/', function () {
     });
     $old = Apricot::getInstance();
     Apricot::reset();
     $new = Apricot::getInstance();
     $this->assertTrue($old !== $new);
 }
Exemplo n.º 2
0
 public function testEmitCallbackGetResponse()
 {
     Apricot::reset();
     Apricot::on('foo', function ($bar) {
         return $bar;
     });
     Apricot::emit('foo', array('Bar'), function ($resp, $index) {
         $this->assertTrue('Bar' === $resp);
         $this->assertTrue(0 === $index);
     });
 }
Exemplo n.º 3
0
 /**
  * @expectedException \RuntimeException
  */
 public function testExceptionPassedThroughMiddlewares()
 {
     Apricot::reset();
     Apricot::add(function () {
         throw new \Exception();
     });
     Apricot::add(function ($e) {
         throw new \RuntimeException();
     });
     Apricot::browse('/');
 }
Exemplo n.º 4
0
 public function testUrlIsSecuredWithParams()
 {
     Apricot::reset();
     Apricot::setEnvironment('test');
     Apricot::secure('/secured', function ($token) {
         echo "Hello {$token}";
         return true;
     });
     Apricot::when('/secured/:token', function () {
     });
     $this->assertTrue('Hello F00B4z' === Apricot::browse('/secured/F00B4z'));
 }
Exemplo n.º 5
0
 public function testAccessDeniedTriggeredWithCallback()
 {
     Apricot::reset();
     Apricot::setEnvironment('test');
     Apricot::when('/', function () {
         Apricot::triggerAccessDenied();
     });
     Apricot::accessDenied(function () {
         echo 'Stop!';
     });
     $this->assertTrue('Stop!' === Apricot::browse('/'));
 }
Exemplo n.º 6
0
 /**
  * @covers Apricot\Component\Rest::resource
  */
 public function testDeepResourceRouteCreated()
 {
     Apricot::reset();
     Apricot::resource('posts', function () {
         Apricot::resource('comments', function () {
             Apricot::index(function ($post_id) {
                 echo "Post {$post_id} comments";
             });
             Apricot::show(function ($post_id, $id) {
                 echo "Comment {$id} of post {$post_id}";
             });
         });
     });
     $this->assertTrue('Post 4 comments' === Apricot::browse('/posts/4/comments'));
     $this->assertTrue('Comment 10 of post 4' === Apricot::browse('/posts/4/comments/10'));
 }
Exemplo n.º 7
0
 /**
  * @expectedException \LogicException
  * @covers Apricot\Component\DependencyInjection::freeze
  * @covers Apricot\Component\DependencyInjection::scope
  */
 public function testThrowsExceptionIfAccessFrozenScope()
 {
     Apricot::reset();
     Apricot::scope('main', function ($scope) {
     });
     Apricot::freeze('main');
     // Now trying to re-open the scope should throw an exception.
     Apricot::scope('main', function ($scope) {
     });
 }
Exemplo n.º 8
0
 public function testSecureRouteNotMatchIfNoHttps()
 {
     Apricot::reset();
     Apricot::setEnvironment('test');
     Apricot::when('/secured', Apricot::with(array('_secure' => true), function () {
         echo 'Foo';
     }));
     Apricot::notFound(function () {
         echo 'Not Found';
     });
     $this->assertTrue('Not Found' === Apricot::browse('/secured'));
 }