Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

Commit

Permalink
Added more tests for code coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
dimsav committed Jun 20, 2014
1 parent 82125f7 commit a06747f
Showing 1 changed file with 45 additions and 15 deletions.
60 changes: 45 additions & 15 deletions tests/TestCoreModelExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@

class TestCoreModelExtension extends TestsBase {

// Saving

/**
* @test
*/
public function it_saves_empty_instances()
{
$company = new Company;
$company->save();
$this->assertGreaterThan(0, $company->id);

$country = new Continent;
$country->save();
$this->assertGreaterThan(0, $country->id);
}

/**
* @test
*/
public function it_saves_translations_when_existing_and_dirty()
{
$country = Country::find(1);
$country->iso = 'make_model_dirty';
$country->name = 'abc';
$this->assertTrue($country->save());
$country = Country::find(1);
$this->assertEquals($country->name, 'abc');
}

// Failing saving

/**
Expand Down Expand Up @@ -40,7 +69,7 @@ public function it_throws_query_exception_if_saving_and_name_is_null()
/**
* @test
*/
public function it_returns_false_if_parent_save_was_not_successful()
public function it_returns_false_if_exists_and_dirty_and_parent_save_returns_false()
{
$that = $this;
$event = App::make('events');
Expand All @@ -54,6 +83,21 @@ public function it_returns_false_if_parent_save_was_not_successful()
$this->assertFalse($country->save());
}

/**
* @test
*/
public function it_returns_false_if_does_not_exist_and_parent_save_returns_false()
{
$that = $this;
$event = App::make('events');
$event->listen('eloquent*', function($model) use ($that) {
return get_class($model) == 'Dimsav\Translatable\Test\Model\Continent' ? false : true;
});

$continent = new Continent;
$this->assertFalse($continent->save());
}

// Filling

/**
Expand Down Expand Up @@ -144,18 +188,4 @@ public function it_passes_the_N_plus_1_problem()
$this->assertGreaterThan(2, count($countries));
$this->assertEquals(2, $this->queriesCount);
}

/**
* @test
*/
public function it_saves_empty_instances()
{
$company = new Company;
$company->save();
$this->assertGreaterThan(0, $company->id);

$country = new Continent;
$country->save();
$this->assertGreaterThan(0, $country->id);
}
}

0 comments on commit a06747f

Please sign in to comment.