Skip to content

Commit

Permalink
Merge pull request #25 from dragonfire1119/master
Browse files Browse the repository at this point in the history
Fix the mockEvents for the tests to pass
  • Loading branch information
weotch authored Sep 20, 2019
2 parents a8c9c68 + 2088b6c commit 0f16b54
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
use Mockery as m;
use VirtualFileSystem\FileSystem as Vfs;

class FunctionalTest extends PHPUnit_Framework_TestCase {
class FunctionalTest extends PHPUnit_Framework_TestCase
{

private $article;

protected function initUpchuck() {
protected function initUpchuck()
{

// Setup filesystem
$fs = new Vfs;
Expand All @@ -48,30 +50,36 @@ protected function initUpchuck() {
);
}

protected function mockEvents() {
return m::mock('Illuminate\Events\Dispatcher', [ 'dispatch' => null ]);
/**
* @return mixed
*/
protected function mockEvents()
{
return m::mock('Illuminate\Contracts\Events\Dispatcher', ['dispatch' => null]);
}

// https://github.com/laracasts/TestDummy/blob/master/tests/FactoryTest.php#L18
protected function setUpDatabase() {
protected function setUpDatabase()
{
$db = new DB;

$db->addConnection([
'driver' => 'sqlite',
'database' => ':memory:'
'driver' => 'sqlite',
'database' => ':memory:'
], 'default');

$db->addConnection([
'driver' => 'sqlite',
'database' => ':memory:'
'driver' => 'sqlite',
'database' => ':memory:'
], 'alt');

$db->bootEloquent();
$db->setAsGlobal();
}

// https://github.com/laracasts/TestDummy/blob/master/tests/FactoryTest.php#L31
protected function migrateTables($connection = 'default') {
protected function migrateTables($connection = 'default')
{
DB::connection($connection)->getSchemaBuilder()->create('articles', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
Expand Down Expand Up @@ -113,7 +121,8 @@ protected function migrateTables($connection = 'default') {
});
}

protected function seed() {
protected function seed()
{
Article::unguard();
$this->article = Article::create([
'title' => 'Test',
Expand Down Expand Up @@ -141,7 +150,8 @@ protected function seed() {
}

// Test that a record is created in the same database
function testExists() {
function testExists()
{
$this->initUpchuck();
$this->setUpDatabase();
$this->migrateTables();
Expand Down Expand Up @@ -205,7 +215,8 @@ function testExists() {
// use eloquent because Laravel has issues with relationships on models in
// a different connection
// https://github.com/laravel/framework/issues/9355
function testExistsInAltDatabaseAndFilesystem() {
function testExistsInAltDatabaseAndFilesystem()
{
$this->initUpchuck();
$this->setUpDatabase();
$this->migrateTables();
Expand All @@ -227,7 +238,7 @@ function testExistsInAltDatabaseAndFilesystem() {
// Test that the new article was created
$this->assertEquals(1, DB::connection('alt')->table('articles')->count());
$clone = DB::connection('alt')->table('articles')->first();
$this->assertEquals(1 , $clone->id);
$this->assertEquals(1, $clone->id);
$this->assertEquals('Test', $clone->title);

// Test that many to many failed
Expand Down

0 comments on commit 0f16b54

Please sign in to comment.