Skip to content

Commit

Permalink
fixed login browser by creating own DuskServiceProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
mattKendon committed Aug 24, 2017
1 parent b8bbe79 commit 80cfdd0
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 10 deletions.
1 change: 0 additions & 1 deletion app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Contracts\Session\Session;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use TheRestartProject\RepairDirectory\Application\Auth\FixometerSessionGuard;

Expand Down
6 changes: 6 additions & 0 deletions docker/bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ case "$1" in
docker-compose -f docker-compose.yml -f docker-compose.testing.yml run --rm php php vendor/bin/phpunit --testsuite=Unit "${@:2}"
cd ..
;;
'integration')
cd docker
docker-compose -f docker-compose.yml up -d database_testing
docker-compose -f docker-compose.yml -f docker-compose.testing.yml run --rm php php vendor/bin/phpunit --testsuite=Integration "${@:2}"
cd ..
;;
'feature')
cd docker
docker-compose -f docker-compose.yml up -d database_testing
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>

<testsuite name="Integration">
<directory suffix="Test.php">./tests/Integration</directory>
</testsuite>

<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
Expand Down
10 changes: 9 additions & 1 deletion src/Application/Auth/FixometerSessionGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function user()
return $this->user;
}

$id = $this->session->get($this->getName());
$id = $this->getUserIdFromSession();

// First we will try to load the user using the identifier in the session if
// one exists. Otherwise we will check for a "remember me" cookie in this
Expand Down Expand Up @@ -773,4 +773,12 @@ public function setRequest(Request $request)

return $this;
}

/**
* @return mixed
*/
protected function getUserIdFromSession()
{
return $this->session->get($this->getName());
}
}
68 changes: 68 additions & 0 deletions tests/Integration/Application/Auth/FixometerSessionGuardTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace TheRestartProject\RepairDirectory\Tests\Integration\Application\Auth;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Auth;
use TheRestartProject\RepairDirectory\Application\Auth\FixometerSessionGuard;
use TheRestartProject\RepairDirectory\Domain\Models\User;
use TheRestartProject\RepairDirectory\Testing\DatabaseMigrations;
use TheRestartProject\RepairDirectory\Tests\IntegrationTestCase;

class FixometerSessionGuardTest extends IntegrationTestCase
{
use DatabaseMigrations;

/**
* @test
*/
public function it_can_login_an_existing_user()
{
/**
* The Created user that implements Authenticable
*
* @var Authenticatable $user
*/
$user = entity(User::class)->create();

$this->guard()->login($user);

$this->assertLoggedInAs($user);
}

/**
* @test
*/
public function it_can_log_out_a_logged_in_user()
{
/**
* The Created user that implements Authenticable
*
* @var Authenticatable $user
*/
$user = entity(User::class)->create();

$this->guard()->login($user);

$this->assertLoggedInAs($user);
}

/**
* @return FixometerSessionGuard
*/
protected function guard()
{
return $this->app->make('auth')->guard();
}

/**
* @param $user
*/
protected function assertLoggedInAs($user)
{
$loggedInUser = $this->guard()->user();

self::assertInstanceOf(Authenticatable::class, $loggedInUser);
self::assertEquals($user->getAuthIdentifier(), $loggedInUser->getAuthIdentifier());
}
}
19 changes: 11 additions & 8 deletions tests/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace TheRestartProject\RepairDirectory\Tests;

use Illuminate\Support\Facades\Artisan;
use TheRestartProject\RepairDirectory\Testing\DatabaseMigrations;
use TheRestartProject\RepairDirectory\Tests\TestCase;

/**
Expand All @@ -27,19 +28,21 @@ abstract class IntegrationTestCase extends TestCase
public function setUp()
{
parent::setUp();
Artisan::call('doctrine:migrations:refresh');
Artisan::call('db:seed');
}

/**
* Rollback the database migrations so tests are idempotent.
* Boot the testing helper traits.
*
* @return void
* @return array
*/
public function tearDown()
protected function setUpTraits()
{
Artisan::call('doctrine:migrations:reset');
parent::tearDown();
}
$uses = parent::setUpTraits();

if (isset($uses[DatabaseMigrations::class])) {
$this->runDatabaseMigrations();
}

return $uses;
}
}

0 comments on commit 80cfdd0

Please sign in to comment.