Skip to content

Commit bff3714

Browse files
committed
Changes
- Add a migration file to use - Remove .sqlite files and run in memory - Remove statements psalm states are unnecessary
1 parent d8d7919 commit bff3714

File tree

6 files changed

+60
-66
lines changed

6 files changed

+60
-66
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,17 @@ The final result would look like:
618618

619619
- [x] Bootstrap 4 Template
620620
- [x] Bootstrap 5 Template
621-
- [ ] Sorting By Relationships
622-
- [ ] Test Suite
621+
- [x] Sorting By Relationships
622+
- [ ] Test Suite (WIP)
623623
- [ ] Column Search
624624
- [ ] Greater Configurability
625625

626+
## Testing
627+
628+
```bash
629+
composer test
630+
```
631+
626632
## Changelog
627633

628634
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

tests.sqlite

-24 KB
Binary file not shown.

tests/DataTableComponentTest.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Rappasoft\LaravelLivewireTables\Tests;
44

55
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
6-
use Illuminate\Database\Eloquent\Builder;
76
use Rappasoft\LaravelLivewireTables\DataTableComponent;
87
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;
98

@@ -15,34 +14,25 @@ public function setUp(): void
1514
{
1615
parent::setUp();
1716

18-
$this->table = $table = new PetsTable();
17+
$this->table = new PetsTable();
1918
}
2019

2120
/** @test */
22-
public function bootstrap_test_datatable()
21+
public function bootstrap_test_datatable(): void
2322
{
2423
$this->assertInstanceOf(DataTableComponent::class, $this->table);
2524
}
2625

2726
/** @test */
28-
public function test_query()
29-
{
30-
$query = $this->table->query();
31-
32-
$this->assertInstanceOf(Builder::class, $query);
33-
}
34-
35-
/** @test */
36-
public function test_columns()
27+
public function test_columns(): void
3728
{
3829
$columns = $this->table->columns();
3930

40-
$this->assertIsArray($columns);
4131
$this->assertCount(5, $columns);
4232
}
4333

4434
/** @test */
45-
public function test_rows()
35+
public function test_rows(): void
4636
{
4737
$rows = $this->table->rows;
4838

@@ -51,22 +41,22 @@ public function test_rows()
5141
}
5242

5343
/** @test */
54-
public function test_search_filter()
44+
public function test_search_filter(): void
5545
{
5646
$this->table->filters['search'] = 'Cartman';
5747
$this->assertEquals(1, $this->table->getRowsProperty()->total());
5848
}
5949

6050
/** @test */
61-
public function test_search_filter_reset()
51+
public function test_search_filter_reset(): void
6252
{
6353
$this->table->filters['search'] = 'Cartman';
6454
$this->table->resetFilters();
6555
$this->assertEquals(1, $this->table->rows->total());
6656
}
6757

6858
/** @test */
69-
public function test_search_filter_remove()
59+
public function test_search_filter_remove(): void
7060
{
7161
$this->table->filters['search'] = 'Cartman';
7262
$this->table->removeFilter('search');

tests/TestCase.php

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Tests;
44

5-
use Illuminate\Database\Capsule\Manager as DB;
6-
use Illuminate\Database\Schema\Blueprint;
7-
use Livewire\LivewireServiceProvider;
85
use Orchestra\Testbench\TestCase as Orchestra;
96
use Rappasoft\LaravelLivewireTables\LaravelLivewireTablesServiceProvider;
7+
use Rappasoft\LaravelLivewireTables\Tests\Database\Migrations\CreateTestTables;
108
use Rappasoft\LaravelLivewireTables\Tests\Models\Breed;
119
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet;
1210
use Rappasoft\LaravelLivewireTables\Tests\Models\Species;
1311

1412
class TestCase extends Orchestra
1513
{
16-
protected $db;
1714

1815
/**
1916
* Setup the test environment.
@@ -22,40 +19,13 @@ protected function setUp(): void
2219
{
2320
parent::setUp();
2421

25-
$this->db = $db = new DB;
26-
27-
// grab database
28-
$database = $this->app['config']['database']['connections']['sqlite']['database'];
29-
30-
// setup connection
31-
$db->addConnection([
32-
'driver' => 'sqlite',
33-
'database' => $database,
34-
]);
35-
36-
$db->setAsGlobal();
37-
38-
// setup species table
39-
$this->db->connection()->getSchemaBuilder()->create('species', function (Blueprint $table) {
40-
$table->id();
41-
$table->string('name');
42-
});
43-
4422
Species::insert([
4523
[ 'id' => 1, 'name' => 'Cat', ],
4624
[ 'id' => 2, 'name' => 'Dog', ],
4725
[ 'id' => 3, 'name' => 'Horse', ],
4826
[ 'id' => 4, 'name' => 'Bird', ],
4927
]);
5028

51-
// setup breeds table
52-
$this->db->connection()->getSchemaBuilder()->create('breeds', function (Blueprint $table) {
53-
$table->id();
54-
$table->string('name');
55-
$table->integer('species_id')->unsigned();
56-
$table->foreign('species_id')->references('id')->on('species');
57-
});
58-
5929
Breed::insert([
6030
[ 'id' => 1, 'name' => 'American Shorthair', 'species_id' => 1, ],
6131
[ 'id' => 2, 'name' => 'Maine Coon', 'species_id' => 1, ],
@@ -69,18 +39,6 @@ protected function setUp(): void
6939
[ 'id' => 202, 'name' => 'Mustang', 'species_id' => 3, ],
7040
]);
7141

72-
// setup user table
73-
$this->db->connection()->getSchemaBuilder()->create('pets', function (Blueprint $table) {
74-
$table->id();
75-
$table->string('name')->index();
76-
$table->string('age')->nullable();
77-
$table->date('last_visit')->nullable();
78-
$table->integer('species_id')->unsigned()->nullable();
79-
$table->integer('breed_id')->unsigned()->nullable();
80-
$table->foreign('species_id')->references('id')->on('species');
81-
$table->foreign('breed_id')->references('id')->on('breeds');
82-
});
83-
8442
Pet::insert([
8543
[ 'id' => 1, 'name' => 'Cartman', 'age' => 22, 'species_id' => 1, 'breed_id' => 4 ],
8644
[ 'id' => 2, 'name' => 'Tux', 'age' => 8, 'species_id' => 1, 'breed_id' => 4 ],
@@ -93,20 +51,19 @@ protected function setUp(): void
9351
protected function getPackageProviders($app)
9452
{
9553
return [
96-
//LivewireServiceProvider::class,
9754
LaravelLivewireTablesServiceProvider::class,
9855
];
9956
}
10057

10158
public function getEnvironmentSetUp($app)
10259
{
103-
$app['config']->set('app.debug', true);
10460
$app['config']->set('database.default', 'sqlite');
10561
$app['config']->set('database.connections.sqlite', [
10662
'driver' => 'sqlite',
107-
//'database' => 'tests/tests.sqlite',
108-
'database' => tempnam(sys_get_temp_dir(), 'LaravelLivewireTables'),
63+
'database' => ':memory:',
10964
'prefix' => '',
11065
]);
66+
67+
resolve(CreateTestTables::class)->up();
11168
}
11269
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Tests\Database\Migrations;
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
class CreateTestTables extends Migration
10+
{
11+
/**
12+
* Run the migrations.
13+
*
14+
* @return void
15+
*/
16+
public function up()
17+
{
18+
Schema::create('species', function (Blueprint $table) {
19+
$table->id();
20+
$table->string('name');
21+
});
22+
23+
Schema::create('breeds', function (Blueprint $table) {
24+
$table->id();
25+
$table->string('name');
26+
$table->integer('species_id')->unsigned();
27+
$table->foreign('species_id')->references('id')->on('species');
28+
});
29+
30+
Schema::create('pets', function (Blueprint $table) {
31+
$table->id();
32+
$table->string('name')->index();
33+
$table->string('age')->nullable();
34+
$table->date('last_visit')->nullable();
35+
$table->integer('species_id')->unsigned()->nullable();
36+
$table->integer('breed_id')->unsigned()->nullable();
37+
$table->foreign('species_id')->references('id')->on('species');
38+
$table->foreign('breed_id')->references('id')->on('breeds');
39+
});
40+
}
41+
}

tests/tests.sqlite

-24 KB
Binary file not shown.

0 commit comments

Comments
 (0)