Skip to content

Commit

Permalink
apply more cs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
znck committed Nov 17, 2015
1 parent 0750446 commit 310abe7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
2 changes: 0 additions & 2 deletions src/Traits/BelongsToThrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ trait BelongsToThrough
* @param string|null $localKey
*
* @return \Znck\Eloquent\Relations\BelongsToThrough
*
* @throws \Exception
*/
public function belongsToThrough($related, $through, $localKey = null)
{
Expand Down
43 changes: 21 additions & 22 deletions tests/BelongsToThroughTest.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
<?php

use Illuminate\Database\Eloquent\Model as Eloquent;
use Znck\Eloquent\Traits\BelongsToThrough;
use Illuminate\Support\Str;

/**
* Test BelongsToThrough
* Test BelongsToThrough.
*/
class BelongsToThroughTest extends \Orchestra\Testbench\TestCase
{

/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
*
* @return void
* @param \Illuminate\Foundation\Application $app
*/
protected function getEnvironmentSetUp($app)
{
// Setup default database to use sqlite :memory:
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
'driver' => 'sqlite',
'database' => __DIR__ . '/database.sqlite',
'prefix' => '',
'driver' => 'sqlite',
'database' => __DIR__.'/database.sqlite',
'prefix' => '',
]);
}


public function test_through_one()
{
$district = Stub_Test_Model_District::where('id', 1)->first();
Expand All @@ -36,7 +33,6 @@ public function test_through_one()
$this->assertEquals(1, $district->country->id);
}


public function test_through_two()
{
$city = Stub_Test_Model_City::where('id', 1)->first();
Expand All @@ -45,7 +41,6 @@ public function test_through_two()
$this->assertEquals(1, $city->country->id);
}


public function test_eager_loading()
{
$cities = Stub_Test_Model_City::with('country')->where('id', '<', 17)->get();
Expand All @@ -57,7 +52,8 @@ public function test_eager_loading()
}
}

public function test_has_relation() {
public function test_has_relation()
{
$cities_with_country = Stub_Test_Model_City::has('country')->get();
$all_cities = Stub_Test_Model_City::all();

Expand All @@ -66,16 +62,20 @@ public function test_has_relation() {
}
}

class Stub_Parent_Model extends Eloquent {
public function getForeignKey() {
return Str::singular($this->getTable()).'_id';
}
class Stub_Parent_Model extends Eloquent
{
public function getForeignKey()
{
return Str::singular($this->getTable()).'_id';
}
}

class Stub_Test_Model_Contient extends Stub_Parent_Model {
class Stub_Test_Model_Contient extends Stub_Parent_Model
{
protected $table = 'continents';

public function countries() {
public function countries()
{
return $this->hasMany(Stub_Test_Model_Country::class);
}
}
Expand All @@ -84,7 +84,8 @@ class Stub_Test_Model_Country extends Stub_Parent_Model
{
protected $table = 'countries';

public function continent() {
public function continent()
{
return $this->belongsTo(Stub_Test_Model_Contient::class);
}
}
Expand All @@ -96,7 +97,6 @@ class Stub_Test_Model_State extends Stub_Parent_Model

class Stub_Test_Model_District extends Stub_Parent_Model
{

use BelongsToThrough;

protected $table = 'districts';
Expand All @@ -109,13 +109,12 @@ public function country()

class Stub_Test_Model_City extends Stub_Parent_Model
{

use BelongsToThrough;

protected $table = 'cities';

public function country()
{
return $this->belongsToThrough(Stub_Test_Model_Country::class, [ Stub_Test_Model_State::class, Stub_Test_Model_District::class ]);
return $this->belongsToThrough(Stub_Test_Model_Country::class, [Stub_Test_Model_State::class, Stub_Test_Model_District::class]);
}
}

0 comments on commit 310abe7

Please sign in to comment.