Skip to content

Commit

Permalink
Merge branch 'feature/add-browserkit-testing' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner committed Mar 3, 2018
2 parents b116416 + 7acad69 commit f5a403b
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 12 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"mockery/mockery": "0.9.*",
"orchestra/database": "3.6.x-dev@dev",
"orchestra/testbench": "^3.6",
"orchestra/testbench-browser-kit": "^3.6",
"php-coveralls/php-coveralls" : "*",
"phpmd/phpmd": "*",
"phpunit/phpunit": "*",
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
syntaxCheck="false"
>
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Integration">
<directory suffix="Test.php">./tests/Integration</directory>
</testsuite>
Expand Down
2 changes: 1 addition & 1 deletion src/CachedBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function paginate(
return parent::paginate($perPage, $columns, $pageName, $page);
}

$page = $page ?: 1;
$page = request("page", $page ?: 1);
$cacheKey = $this->makeCacheKey($columns, null, "-paginate_by_{$perPage}_{$pageName}_{$page}");

return $this->cachedValue(func_get_args(), $cacheKey);
Expand Down
14 changes: 14 additions & 0 deletions tests/CreatesApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,26 @@ trait CreatesApplication
{
protected $cache;

protected function cache()
{
$cache = cache();

if (config('laravel-model-caching.store')) {
$cache = $cache->store(config('laravel-model-caching.store'));
}

return $cache;
}

public function setUp()
{
parent::setUp();

require(__DIR__ . '/routes/web.php');

$this->withFactories(__DIR__ . '/database/factories');
$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
view()->addLocation(__DIR__ . '/resources/views', 'laravel-model-caching');

$this->cache = cache()
->store(config('laravel-model-caching.store'));
Expand Down
23 changes: 23 additions & 0 deletions tests/Feature/PaginationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Browser;

use GeneaLabs\LaravelModelCaching\Tests\FeatureTestCase;
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;

class PaginationTest extends FeatureTestCase
{
public function testPaginationProvidesDifferentLinksOnDifferentPages()
{
$book = (new Book)
->take(11)
->get()
->last();
$page1 = $this->visit("pagination-test");

$this->assertTrue(str_contains($page1->response->getContent(), '<li class="page-item active"><span class="page-link">1</span></li>'));

$page2 = $page1->click("2");

$this->assertTrue(str_contains($page2->response->getContent(), '<li class="page-item active"><span class="page-link">2</span></li>'));
$page2->see($book->title);
}
}
8 changes: 8 additions & 0 deletions tests/FeatureTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php namespace GeneaLabs\LaravelModelCaching\Tests;

use Orchestra\Testbench\BrowserKit\TestCase as BaseTestCase;

abstract class FeatureTestCase extends BaseTestCase
{
use CreatesApplication;
}
11 changes: 0 additions & 11 deletions tests/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,4 @@
abstract class IntegrationTestCase extends BaseTestCase
{
use CreatesApplication;

protected function cache()
{
$cache = cache();

if (config('laravel-model-caching.store')) {
$cache = $cache->store(config('laravel-model-caching.store'));
}

return $cache;
}
}
22 changes: 22 additions & 0 deletions tests/resources/views/model-caching-tests/pagination.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<body>
<table>

@foreach ($books as $book)
<tr>
<td>
{{ $book->id }}
</td>
<td>
{{ $book->title }}
</td>
</tr>
@endforeach

</table>

{{ $books->links() }}

</body>
</html>
13 changes: 13 additions & 0 deletions tests/routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;

Route::get('pagination-test', function () {
$books = (new Book)
->paginate(10);

return view("model-caching-tests.pagination")
->with(compact(
'books'
));
});

0 comments on commit f5a403b

Please sign in to comment.