-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,7 @@ | |
"authors": [ | ||
{ | ||
"name": "Chris Duell", | ||
"email": "[email protected]", | ||
"role": "Original Developer" | ||
}, | ||
{ | ||
"name": "Austin Stierler", | ||
"email": "[email protected]", | ||
"role": "Developer/Maintainer" | ||
"email": "[email protected]" | ||
} | ||
], | ||
"support": { | ||
|
@@ -31,5 +25,13 @@ | |
"psr-0": { | ||
"Venturecraft\\Revisionable": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Venturecraft\\Revisionable\\Tests\\": "tests/" | ||
} | ||
}, | ||
"require-dev": { | ||
"orchestra/testbench": "~3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="true" | ||
> | ||
|
||
<testsuites> | ||
<testsuite name="Testbench Test Suite"> | ||
<directory suffix="Test.php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist addUncoveredFilesFromWhitelist="false"> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Venturecraft\Revisionable\Tests\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Venturecraft\Revisionable\RevisionableTrait; | ||
|
||
/** | ||
* Add a revisionable model for testing purposes | ||
* I've chosen User, purely because the migration will already exist | ||
* | ||
* Class User | ||
* @package Venturecraft\Revisionable\Tests\Models | ||
*/ | ||
class User extends Model | ||
{ | ||
use RevisionableTrait; | ||
|
||
protected $guarded = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace Venturecraft\Revisionable\Tests; | ||
|
||
use Venturecraft\Revisionable\Tests\Models\User; | ||
|
||
class RevisionTest extends \Orchestra\Testbench\TestCase | ||
{ | ||
/** | ||
* Setup the test environment. | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->loadLaravelMigrations(['--database' => 'testing']); | ||
|
||
// call migrations specific to our tests, e.g. to seed the db | ||
// the path option should be an absolute path. | ||
$this->loadMigrationsFrom([ | ||
'--database' => 'testing', | ||
'--path' => realpath(__DIR__.'/../src/migrations'), | ||
]); | ||
} | ||
|
||
/** | ||
* Define environment setup. | ||
* | ||
* @param \Illuminate\Foundation\Application $app | ||
* @return void | ||
*/ | ||
protected function getEnvironmentSetUp($app) | ||
{ | ||
// Setup default database to use sqlite :memory: | ||
$app['config']->set('database.default', 'testbench'); | ||
$app['config']->set('database.connections.testbench', array( | ||
'driver' => 'sqlite', | ||
'database' => ':memory:', | ||
'prefix' => '', | ||
)); | ||
} | ||
|
||
/** | ||
* Test we can interact with the database | ||
*/ | ||
public function testUsersTable() | ||
{ | ||
User::create([ | ||
'name' => 'James Judd', | ||
'email' => '[email protected]', | ||
'password' => \Hash::make('456'), | ||
]); | ||
|
||
$users = User::findOrFail(1); | ||
$this->assertEquals('[email protected]', $users->email); | ||
$this->assertTrue(\Hash::check('456', $users->password)); | ||
} | ||
|
||
/** | ||
* Make sure revisions are created | ||
*/ | ||
public function testRevisionsStored() | ||
{ | ||
$user = User::create([ | ||
'name' => 'James Judd', | ||
'email' => '[email protected]', | ||
'password' => \Hash::make('456'), | ||
]); | ||
|
||
// change to my nickname | ||
$user->update([ | ||
'name' => 'Judd' | ||
]); | ||
|
||
// change to my forename | ||
$user->update([ | ||
'name' => 'James' | ||
]); | ||
|
||
// we should have two revisions to my name | ||
$this->assertCount(2, $user->revisionHistory); | ||
} | ||
} |