Skip to content

Commit

Permalink
Merge pull request #104 from CyberiaResurrection/Tests-with-SQLite-Me…
Browse files Browse the repository at this point in the history
…mory

Tests with sqlite in-memory
  • Loading branch information
chintanbanugaria authored Jul 21, 2016
2 parents 41a0640 + 4bd6ee2 commit 18fcaa9
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 18 deletions.
14 changes: 14 additions & 0 deletions app/config/testing/database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

return array(

'default' => 'sqlite',

'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => ''
),
)
);
14 changes: 0 additions & 14 deletions app/tests/ExampleTest.php

This file was deleted.

5 changes: 2 additions & 3 deletions app/tests/InstallControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ public function testPostDatabaseSuperGut()
];

//Mock it... yeah, mock it..
DB::shouldReceive('unprepared')->withAnyArgs()->andReturnNull()->once();
Artisan::shouldReceive('migrate')->withAnyArgs()->andReturnNull()->once();
Artisan::shouldReceive('db:seed')->withAnyArgs()->andReturnNull()->once();
Artisan::shouldReceive('call')->withArgs(['migrate'])->andReturnNull()->once();
Artisan::shouldReceive('call')->withArgs(['db:seed'])->andReturnNull()->once();

$externalMock = \Mockery::mock('overload:October\Rain\Config\Rewrite');
$externalMock->shouldReceive('toFile')->withArgs([$expectedPath, $expectedFeed])->andReturnNull()->once();
Expand Down
48 changes: 48 additions & 0 deletions app/tests/JoinTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

class JoinTest extends \TestCase
{
public function testJoinUsersOnGroups()
{
// dig out group to assign
$group = Sentry::findGroupByName('admin');
$groupID = $group->getId();

// set up sample users
$aliceCredentials = array(
'first_name' => 'Alice',
'last_name' => 'Example',
'email' => '[email protected]',
'password' => 'bruceschneier',
'activated' => true,
);
$bobCredentials = array(
'first_name' => 'Bob',
'last_name' => 'Demonstration',
'email' => '[email protected]',
'password' => 'oursharedsecret',
'activated' => true,
);

$alice = Sentry::createUser($aliceCredentials);
$bob = Sentry::createUser($bobCredentials);

$alice->addGroup($group);
$bob->addGroup($group);

//now try joining alice and bob on admin group
$result = DB::table('users')
->join('users_groups', 'users.id', '=', 'users_groups.user_id')
->select('users.id', 'users_groups.group_id')
->where('users.id', '=', $alice->id)
->orWhere('users.id', '=', $bob->id)
->orderBy('users.id')
->get();

//if we've joined correctly, retrieved group ID for both cases should be admin group's ID,
//since that was only thing retrieved
$this->assertEquals(2, sizeof($result));
$this->assertEquals($groupID, $result[0]->group_id);
$this->assertEquals($groupID, $result[1]->group_id);
}
}
34 changes: 34 additions & 0 deletions app/tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,38 @@ public function createApplication()
$testEnvironment = 'testing';
return require __DIR__.'/../../bootstrap/start.php';
}

public function testTrivial()
{
$this->assertTrue(true);
}

/**
* Default preparation for each test
*
*/
public function setUp()
{
parent::setUp(); // Don't forget this!

$this->prepareForTests();
}

/**
* Migrates the database and set the mailer to 'pretend'.
* This will cause the tests to run quickly.
*
*/
private function prepareForTests()
{
Artisan::call('migrate');
Artisan::call('db:seed');
Mail::pretend(true);
}

public function tearDown()
{
parent::TearDown();
\Mockery::close();
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"kmd/logviewer": "1.1.*"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
"phpunit/phpunit": "4.8.*",
"mockery/mockery": "0.9.*"
},
"autoload": {
Expand Down

0 comments on commit 18fcaa9

Please sign in to comment.