Skip to content

Commit

Permalink
Merge pull request #125 from owen-it/tests
Browse files Browse the repository at this point in the history
[3.1] Fixing auditing get table name
  • Loading branch information
anteriovieira authored Oct 15, 2016
2 parents deec613 + 7b3a9ff commit 40b750c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
4 changes: 2 additions & 2 deletions config/auditing.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
|--------------------------------------------------------------------------
|
| This option allows you to control if the operations that audit your models
| with your auditors are queued. When this is set to "true" then all models
| auditable will get queued for better performance.
| are queued. When this is set to "true" then all models auditable will get
| queued for better performance.
|
*/

Expand Down
4 changes: 2 additions & 2 deletions src/Auditing.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ public function getTable()
{
$table = Config::get('auditing.table');

if ($table) {
if (!empty($table)) {
return $table;
}

return str_replace('\\', '', Str::snake(Str::plural(class_basename($this))));
return parent::getTable();
}
}
35 changes: 34 additions & 1 deletion tests/AuditingTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Config;
use OwenIt\Auditing\Auditing;

class AuditingTest extends PHPUnit_Framework_TestCase
Expand All @@ -10,7 +11,11 @@ public function tearDown()
Mockery::close();
}

public function testItGetsCallbackMethos()
public function tearUp()
{
}

public function testItGetsCustomMessages()
{
$auditing = new Auditing();

Expand All @@ -25,6 +30,34 @@ public function testItGetsCallbackMethos()
$this->assertEquals('The title was defined as no title.', $defaultValue);
$this->assertEquals('The title was defined as awesome.', $callbackMethod);
}

public function testItGetTableInConfig()
{
$this->setConfigTable('auditing');

$auditing = new Auditing();
$table = $auditing->getTable();

$this->assertEquals('auditing', $table);
}

public function testItGetTableWithoutConfig()
{
$this->setConfigTable(null);

$auditing = new Auditing();
$table = $auditing->getTable();

$this->assertEquals('audits', $table);
}

public function setConfigTable($table)
{
Config::shouldReceive('get')
->once()
->with('auditing.table')
->andReturn($table);
}
}

class EloquentModelStub extends Model
Expand Down
17 changes: 17 additions & 0 deletions tests/stubs/EloquentModelStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Tests\Stubs;

use Illuminate\Database\Eloquent\Model;

class EloquentModelStub extends Model
{
public static $auditCustomFields = [
'title' => 'The title was defined as "{new.title||getNewTitle}"',
];

public function getNewTitle($stub)
{
return 'new title';
}
}

0 comments on commit 40b750c

Please sign in to comment.