示例#1
0
 public function testAppIsResetted()
 {
     Apricot::when('/', function () {
     });
     $old = Apricot::getInstance();
     Apricot::reset();
     $new = Apricot::getInstance();
     $this->assertTrue($old !== $new);
 }
示例#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);
     });
 }
示例#3
0
 /**
  * @expectedException \RuntimeException
  */
 public function testExceptionPassedThroughMiddlewares()
 {
     Apricot::reset();
     Apricot::add(function () {
         throw new \Exception();
     });
     Apricot::add(function ($e) {
         throw new \RuntimeException();
     });
     Apricot::browse('/');
 }
示例#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'));
 }
示例#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('/'));
 }
示例#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'));
 }
 /**
  * @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) {
     });
 }
示例#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'));
 }