Example #1
0
 public function testFailureCallbackIsCalled()
 {
     Apricot::fail(function ($e) {
         echo "Failed: " . $e->getMessage();
     });
     Apricot::when('/', function () {
         throw new \Exception("Whow!");
     });
     $this->assertTrue(Apricot::browse('/') === "Failed: Whow!");
 }
Example #2
0
 /**
  * @expectedException \RuntimeException
  */
 public function testExceptionPassedThroughMiddlewares()
 {
     Apricot::reset();
     Apricot::add(function () {
         throw new \Exception();
     });
     Apricot::add(function ($e) {
         throw new \RuntimeException();
     });
     Apricot::browse('/');
 }
Example #3
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'));
 }
Example #4
0
 public function testAccessDeniedTriggeredWithCallback()
 {
     Apricot::reset();
     Apricot::setEnvironment('test');
     Apricot::when('/', function () {
         Apricot::triggerAccessDenied();
     });
     Apricot::accessDenied(function () {
         echo 'Stop!';
     });
     $this->assertTrue('Stop!' === Apricot::browse('/'));
 }
Example #5
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'));
 }
Example #6
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'));
 }