Skip to content

Commit 069db15

Browse files
Merge pull request #14 from staudenmeir/code
Improve /tests code
2 parents f18491b + c2520e6 commit 069db15

File tree

7 files changed

+22
-36
lines changed

7 files changed

+22
-36
lines changed

tests/Concerns/AutoloadsRelationshipsTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace LiamWiltshire\LaravelJitLoader\Tests\Concerns;
1010

11-
use Illuminate\Log\LogManager;
1211
use LiamWiltshire\LaravelJitLoader\Tests\TestCase;
1312
use LiamWiltshire\LaravelJitLoader\Tests\TraitlessModel;
1413
use LiamWiltshire\LaravelJitLoader\Tests\TraitModel;
@@ -27,7 +26,7 @@ public function testGetRelationshipFromMethodWithNonExistentRelationshipThrowsEx
2726
public function testGetRelationshipFromMethodAfterDisableAutoLoadCalledDoesntAutoLoad()
2827
{
2928
$models = TraitModel::all();
30-
$related = $models[0]->disableAutoload()->myRelationship;
29+
$models[0]->disableAutoload()->myRelationship;
3130

3231
$this->assertFalse($models[1]->relationLoaded('myRelationship'));
3332
}
@@ -36,7 +35,7 @@ public function testGetRelationshipFromMethodOverThresholdDoesntAutoLoad()
3635
{
3736
$models = TraitModel::all();
3837
$models[0]->setAutoloadThreshold(2);
39-
$related = $models[0]->myRelationship;
38+
$models[0]->myRelationship;
4039

4140
$this->assertFalse($models[1]->relationLoaded('myRelationship'));
4241
}
@@ -45,14 +44,13 @@ public function testGetRelationshipFromMethodOverThresholdDoesntAutoLoad()
4544
public function testGetRelationshipFromMethodUnderThresholdDoesAutoLoad()
4645
{
4746
$models = TraitModel::all();
48-
$related = $models[0]->myRelationship;
47+
$models[0]->myRelationship;
4948

5049
$this->assertTrue($models[1]->relationLoaded('myRelationship'));
5150
}
5251

5352
public function testGetRelationshipFromMethodUnderThresholdDoesAutoLoadWithLogging()
5453
{
55-
5654
$message = "[LARAVEL-JIT-LOADER] Relationship " . TraitModel::class . "::myRelationship was JIT-loaded. Called in " . __FILE__ . " on line " . (__LINE__ + 12);
5755

5856
$driver = $this->getMockBuilder(LoggerInterface::class)->getMock();
@@ -65,7 +63,7 @@ public function testGetRelationshipFromMethodUnderThresholdDoesAutoLoadWithLoggi
6563
$models = TraitModel::all();
6664
$models[0]->setLogging('jitLogger', $driver);
6765

68-
$related = $models[0]->myRelationship;
66+
$models[0]->myRelationship;
6967

7068
$this->assertTrue($models[1]->relationLoaded('myRelationship'));
7169
}
@@ -116,4 +114,4 @@ public function testPerformance()
116114
$this->assertTrue($traitedCount < $traitlessCount);
117115
$this->assertTrue($traitedTime < $traitlessTime);
118116
}
119-
}
117+
}

tests/CoverageCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
exit(1);
2929
}
3030

31-
echo 'Code coverage is ' . $coverage . '% - OK!' . PHP_EOL;
31+
echo 'Code coverage is ' . $coverage . '% - OK!' . PHP_EOL;

tests/DummyModel.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace LiamWiltshire\LaravelJitLoader\Tests;
44

5-
65
use LiamWiltshire\LaravelJitLoader\Model;
76

8-
class DummyModel extends Model {
9-
7+
class DummyModel extends Model
8+
{
109
protected $fillable = ['dummy_model_id'];
1110

1211
public function myRelationship()
@@ -23,4 +22,4 @@ public function setAutoloadThreshold(int $autoloadThreshold)
2322
{
2423
$this->autoloadThreshold = $autoloadThreshold;
2524
}
26-
}
25+
}

tests/ModelTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace LiamWiltshire\LaravelJitLoader\Tests;
44

5-
65
class ModelTest extends TestCase
76
{
87
public function testGetRelationshipFromMethodWithNonExistentRelationshipThrowsException()
@@ -16,7 +15,7 @@ public function testGetRelationshipFromMethodWithNonExistentRelationshipThrowsEx
1615
public function testGetRelationshipFromMethodAfterDisableAutoLoadCalledDoesntAutoLoad()
1716
{
1817
$models = DummyModel::all();
19-
$related = $models[0]->disableAutoload()->myRelationship;
18+
$models[0]->disableAutoload()->myRelationship;
2019

2120
$this->assertFalse($models[1]->relationLoaded('myRelationship'));
2221
}
@@ -25,7 +24,7 @@ public function testGetRelationshipFromMethodOverThresholdDoesntAutoLoad()
2524
{
2625
$models = DummyModel::all();
2726
$models[0]->setAutoloadThreshold(2);
28-
$related = $models[0]->myRelationship;
27+
$models[0]->myRelationship;
2928

3029
$this->assertFalse($models[1]->relationLoaded('myRelationship'));
3130
}
@@ -34,10 +33,8 @@ public function testGetRelationshipFromMethodOverThresholdDoesntAutoLoad()
3433
public function testGetRelationshipFromMethodUnderThresholdDoesAutoLoad()
3534
{
3635
$models = DummyModel::all();
37-
$related = $models[0]->myRelationship;
36+
$models[0]->myRelationship;
3837

3938
$this->assertTrue($models[1]->relationLoaded('myRelationship'));
4039
}
4140
}
42-
43-

tests/TestCase.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88

99
namespace LiamWiltshire\LaravelJitLoader\Tests;
1010

11-
12-
use Illuminate\Contracts\Foundation\Application;
13-
use Illuminate\Contracts\Http\Kernel;
1411
use Illuminate\Database\Capsule\Manager;
1512

1613
class TestCase extends \PHPUnit\Framework\TestCase
1714
{
18-
1915
public $db;
2016

2117
public $messages = [];
@@ -44,7 +40,7 @@ protected function configureDatabase()
4440

4541
public function migrateIdentitiesTable()
4642
{
47-
Manager::schema()->create('dummy_models', function($table) {
43+
Manager::schema()->create('dummy_models', function ($table) {
4844
$table->increments('id');
4945
$table->integer('dummy_model_id');
5046
$table->timestamps();
@@ -56,7 +52,7 @@ public function migrateIdentitiesTable()
5652
$x--;
5753
}
5854

59-
Manager::schema()->create('trait_models', function($table) {
55+
Manager::schema()->create('trait_models', function ($table) {
6056
$table->increments('id');
6157
$table->integer('trait_model_id');
6258
$table->timestamps();
@@ -68,7 +64,7 @@ public function migrateIdentitiesTable()
6864
$x--;
6965
}
7066

71-
Manager::schema()->create('traitless_models', function($table) {
67+
Manager::schema()->create('traitless_models', function ($table) {
7268
$table->increments('id');
7369
$table->integer('traitless_model_id');
7470
$table->timestamps();
@@ -79,7 +75,6 @@ public function migrateIdentitiesTable()
7975
TraitlessModel::create(array('traitless_model_id' => $x));
8076
$x--;
8177
}
82-
8378
}
8479

8580
public function __destruct()
@@ -91,4 +86,4 @@ public function __destruct()
9186
}
9287
parent::tearDown(); // TODO: Change the autogenerated stub
9388
}
94-
}
89+
}

tests/TraitModel.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace LiamWiltshire\LaravelJitLoader\Tests;
44

5-
65
use Illuminate\Database\Eloquent\Model;
76
use LiamWiltshire\LaravelJitLoader\Concerns\AutoloadsRelationships;
87
use Psr\Log\LoggerInterface;
98

10-
class TraitModel extends Model {
11-
9+
class TraitModel extends Model
10+
{
1211
use AutoloadsRelationships;
1312

1413
protected $fillable = ['trait_model_id'];
@@ -33,4 +32,4 @@ public function setLogging(string $channel, LoggerInterface $logger)
3332
$this->logChannel = $channel;
3433
$this->logDriver = $logger;
3534
}
36-
}
35+
}

tests/TraitlessModel.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
namespace LiamWiltshire\LaravelJitLoader\Tests;
44

5-
65
use Illuminate\Database\Eloquent\Model;
7-
use LiamWiltshire\LaravelJitLoader\Concerns\AutoloadsRelationships;
86
use Psr\Log\LoggerInterface;
97

10-
class TraitlessModel extends Model {
11-
8+
class TraitlessModel extends Model
9+
{
1210
protected $fillable = ['traitless_model_id'];
1311

1412
public function myRelationship()
@@ -31,4 +29,4 @@ public function setLogging(string $channel, LoggerInterface $logger)
3129
$this->logChannel = $channel;
3230
$this->logDriver = $logger;
3331
}
34-
}
32+
}

0 commit comments

Comments
 (0)