Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
duellsy committed Apr 22, 2019
2 parents 8dc4ed7 + 1e751ee commit 9e5fbdf
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 7 deletions.
16 changes: 9 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -31,5 +25,13 @@
"psr-0": {
"Venturecraft\\Revisionable": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Venturecraft\\Revisionable\\Tests\\": "tests/"
}
},
"require-dev": {
"orchestra/testbench": "~3.0"
}
}
29 changes: 29 additions & 0 deletions phpunit.xml
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>
20 changes: 20 additions & 0 deletions tests/Models/User.php
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 = [];
}
82 changes: 82 additions & 0 deletions tests/RevisionTest.php
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);
}
}

0 comments on commit 9e5fbdf

Please sign in to comment.