Skip to content

Commit

Permalink
test: update types
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Sep 16, 2024
1 parent 8c8b06d commit 26d4dee
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
2 changes: 2 additions & 0 deletions tests/app.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
app()->config('test', false);
app()->config('mode', 'TEST');

app()->get('/', function () {});

app()->script('TEST', function () {
app()->config('test', true);
});
Expand Down
25 changes: 24 additions & 1 deletion tests/middleware.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class StaticTestClassMid
});

test('leaf middleware', function () {

class AppMid extends \Leaf\Middleware
{
public function call()
Expand All @@ -30,6 +29,30 @@ public function call()
expect(StaticTestClassMid::$called)->toBe(true);
});

test('leaf middleware with next data', function () {

class AppMid2 extends \Leaf\Middleware
{
public function call()
{
$this->next([
'data' => 'Some data'
]);
}
}

$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/';

app()->use(new AppMid2());

app()->get('/', function () {});

app()->run();

expect(request()->next('data'))->toBe('Some data');
});

test('in-route middleware', function () {
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/';
Expand Down
36 changes: 28 additions & 8 deletions tests/view.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,46 @@ public static function test()
}
};

beforeEach(function () {
Leaf\Config::clear();
});

test('view attach', function () {
Leaf\View::attach(TView::class);
Leaf\Config::attachView(TView::class);

$view = Leaf\Config::get('views.tview');

expect(Leaf\View::tview())->toBeInstanceOf(TView::class);
expect($view)->toBeInstanceOf(TView::class);
});

test('view attach with name', function () {
Leaf\View::attach(TView::class, 'named');
Leaf\Config::attachView(TView::class, 'named');

expect(Leaf\View::named())->toBeInstanceOf(TView::class);
$view = Leaf\Config::get('views.named');

expect($view)->toBeInstanceOf(TView::class);
});

test('access attached view props', function () {
Leaf\View::attach(TView::class, 'named');
Leaf\Config::attachView(TView::class, 'named');

$view = Leaf\Config::get('views.named');

expect(Leaf\View::named()::$num)->toBe(TView::$num);
expect($view::$num)->toBe(TView::$num);
});

test('access attached view methods', function () {
Leaf\View::attach(TView::class, 'named');
Leaf\Config::attachView(TView::class, 'named');

$view = Leaf\Config::get('views.named');

expect($view->test())->toBe(TView::test());
});

test('access attached view using the view command', function () {
Leaf\Config::attachView(TView::class, 'named2');

$view = Leaf\Config::view('named2');

expect(Leaf\View::named()->test())->toBe(TView::test());
expect($view->test())->toBe(TView::test());
});

0 comments on commit 26d4dee

Please sign in to comment.