. */ declare(strict_types=1); namespace Tests\Unit\Middleware; use FireflyIII\Http\Middleware\Range; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Route; use Symfony\Component\HttpFoundation\Response; use Tests\TestCase; /** * Class RangeTest */ class RangeTest extends TestCase { /** * @covers \FireflyIII\Http\Middleware\Range */ public function testMiddlewareAuthenticated() { $repository = $this->mock(JournalRepositoryInterface::class); $repository->shouldReceive('first')->andReturn(TransactionJournal::first()); $this->withoutExceptionHandling(); $this->be($this->user()); $response = $this->get('/_test/range'); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); // view has list length $response->assertSeeText('list-length: 10'); // assert some session stuff? } /** * @covers \FireflyIII\Http\Middleware\Range */ public function testMiddlewareNotAuthenticated() { $this->withoutExceptionHandling(); $response = $this->get('/_test/range'); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); } /** * Set up test */ protected function setUp() { parent::setUp(); Route::middleware(Range::class)->any( '/_test/range', function () { return view('test.test'); } ); } }