public function testAppIsResetted() { Apricot::when('/', function () { }); $old = Apricot::getInstance(); Apricot::reset(); $new = Apricot::getInstance(); $this->assertTrue($old !== $new); }
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); }); }
/** * @expectedException \RuntimeException */ public function testExceptionPassedThroughMiddlewares() { Apricot::reset(); Apricot::add(function () { throw new \Exception(); }); Apricot::add(function ($e) { throw new \RuntimeException(); }); Apricot::browse('/'); }
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')); }
public function testAccessDeniedTriggeredWithCallback() { Apricot::reset(); Apricot::setEnvironment('test'); Apricot::when('/', function () { Apricot::triggerAccessDenied(); }); Apricot::accessDenied(function () { echo 'Stop!'; }); $this->assertTrue('Stop!' === Apricot::browse('/')); }
/** * @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) { }); }
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')); }