Skip to content

Commit

Permalink
Merge pull request #7 from ARCANEDEV/update-laravel_5.8
Browse files Browse the repository at this point in the history
Adding Laravel 5.8 support
  • Loading branch information
arcanedev-maroc authored Feb 28, 2019
2 parents 96aadef + 8df2cc9 commit f72bc3f
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 157 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: php

sudo: false

php:
- 7.1.3
- 7.1
Expand Down
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Feel free to check out the [releases](https://github.com/ARCANEDEV/LaravelImpers

### Features

* Laravel `5.4` to `5.7` are supported.
* Laravel `5.4` to `5.8` are supported.
* Easy setup & configuration.
* Well documented & IDE Friendly.
* Well tested with maximum code quality.
Expand All @@ -30,13 +30,6 @@ Feel free to check out the [releases](https://github.com/ARCANEDEV/LaravelImpers
2. [Configuration](_docs/2-Configuration.md)
3. [Usage](_docs/3-Usage.md)

## TODO

- [ ] Adding Laravel `5.1 | 5.2 | 5.3` Support ?
- [ ] Adding Blade directives.
- [ ] Complete the model factories.
- [ ] Complete the documentation.

## Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Expand All @@ -51,7 +44,7 @@ Any ideas are welcome. Feel free to submit any issues or pull requests, please c
- [All Contributors][link-contributors]

[badge_license]: https://img.shields.io/packagist/l/arcanedev/laravel-impersonator.svg?style=flat-square
[badge_laravel]: https://img.shields.io/badge/Laravel-5.4%20to%205.7-orange.svg?style=flat-square
[badge_laravel]: https://img.shields.io/badge/Laravel-5.4%20to%205.8-orange.svg?style=flat-square
[badge_build]: https://img.shields.io/travis/ARCANEDEV/LaravelImpersonator.svg?style=flat-square
[badge_coverage]: https://img.shields.io/scrutinizer/coverage/g/ARCANEDEV/LaravelImpersonator.svg?style=flat-square
[badge_quality]: https://img.shields.io/scrutinizer/g/ARCANEDEV/LaravelImpersonator.svg?style=flat-square
Expand Down
10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
"license": "MIT",
"require": {
"php": ">=7.1.3",
"arcanedev/support": "~4.4.0",
"arcanesoft/contracts": "~3.0.0"
"arcanedev/support": "~4.5.0"
},
"require-dev": {
"phpunit/phpcov": "~5.0",
"phpunit/phpunit": "~7.0",
"orchestra/testbench": "~3.7.0",
"orchestra/database": "~3.7.0"
"orchestra/testbench": "~3.8.0",
"phpunit/phpcov": "~5.0|~6.0",
"phpunit/phpunit": "~7.0|~8.0"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
<env name="DB_CONNECTION" value="testing"/>
<env name="SESSION_DRIVER" value="array"/>
</php>
<logging>
Expand Down
14 changes: 6 additions & 8 deletions src/Contracts/Impersonatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@ interface Impersonatable extends Authenticatable
/**
* Impersonate the given user.
*
* @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable $impersonated
* @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable $impersonated
*
* @return bool
* @return bool
*/
public function impersonate(Impersonatable $impersonated);

/**
* Leave the current impersonation.
*
* @param void
*
* @return bool
* @return bool
*/
public function stopImpersonation();

Expand All @@ -41,21 +39,21 @@ public function stopImpersonation();
/**
* Check if the current modal can impersonate other models.
*
* @return bool
* @return bool
*/
public function canImpersonate();

/**
* Check if the current model can be impersonated.
*
* @return bool
* @return bool
*/
public function canBeImpersonated();

/**
* Check if impersonation is ongoing.
*
* @return bool
* @return bool
*/
public function isImpersonated();
}
22 changes: 11 additions & 11 deletions tests/EventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EventsTest extends TestCase
| -----------------------------------------------------------------
*/

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand All @@ -38,14 +38,14 @@ public function it_must_dispatches_events_when_starting_and_stopping_impersonati
$admin = $this->getAdminUser();
$user = $this->getRegularUSer();

$this->assertTrue($admin->impersonate($user));
$this->assertTrue($user->stopImpersonation());
static::assertTrue($admin->impersonate($user));
static::assertTrue($user->stopImpersonation());

$this->assertImpersonationStartedEventDispatched($admin, $user);
$this->assertLoginEventNotDispatched();
static::assertImpersonationStartedEventDispatched($admin, $user);
static::assertLoginEventNotDispatched();

$this->assertImpersonationStoppedEventDispatched($admin, $user);
$this->assertLogoutEventNotDispatched();
static::assertImpersonationStoppedEventDispatched($admin, $user);
static::assertLogoutEventNotDispatched();
}

/* -----------------------------------------------------------------
Expand Down Expand Up @@ -73,24 +73,24 @@ protected function getRegularUSer()
return User::find(2);
}

protected function assertLoginEventNotDispatched()
protected static function assertLoginEventNotDispatched()
{
Event::assertNotDispatched(Login::class);
}

private function assertLogoutEventNotDispatched()
private static function assertLogoutEventNotDispatched()
{
Event::assertNotDispatched(Logout::class);
}

protected function assertImpersonationStartedEventDispatched($impersonater, $impersonated)
protected static function assertImpersonationStartedEventDispatched($impersonater, $impersonated)
{
Event::assertDispatched(ImpersonationStarted::class, function ($event) use ($impersonater, $impersonated) {
return $event->impersonater->id == $impersonater->id && $event->impersonated->id == $impersonated->id;
});
}

protected function assertImpersonationStoppedEventDispatched($impersonater, $impersonated)
protected static function assertImpersonationStoppedEventDispatched($impersonater, $impersonated)
{
Event::assertDispatched(ImpersonationStopped::class, function ($event) use ($impersonater, $impersonated) {
return $event->impersonater->id == $impersonater->id && $event->impersonated->id == $impersonated->id;
Expand Down
49 changes: 22 additions & 27 deletions tests/ImpersonationPoliciesTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace Arcanedev\LaravelImpersonator\Tests;

use Symfony\Component\HttpFoundation\Response;

/**
* Class ImpersonationPoliciesTest
*
Expand All @@ -18,59 +20,53 @@ public function it_can_allow_access_to_impersonator()
{
$this->loginWithId(1);

$response = $this->get(route('auth::impersonator.start', [2]));

$response->assertSuccessful();
$response->assertSessionHas('impersonator_id');
$response->assertSeeText('Impersonation started');
$this->get(route('auth::impersonator.start', [2]))
->assertSuccessful()
->assertSessionHas('impersonator_id')
->assertSeeText('Impersonation started');
}

/** @test */
public function it_can_deny_access_to_impersonator()
{
$this->loginWithId(2);

$response = $this->get(route('auth::impersonator.start', [3]));

$response->assertStatus(403);
$this->get(route('auth::impersonator.start', [3]))
->assertStatus(Response::HTTP_FORBIDDEN);
}

/** @test */
public function it_can_deny_access_if_impersonated_can_not_be_impersonated()
{
$this->loginWithId(1);

$response = $this->get(route('auth::impersonator.start', [4]));

$response->assertStatus(403);
$this->get(route('auth::impersonator.start', [4]))
->assertStatus(Response::HTTP_FORBIDDEN);
}

/** @test */
public function it_can_stop_ongoing_impersonation()
{
$this->loginWithId(1);

$response = $this->get(route('auth::impersonator.start', [2]));
$this->get(route('auth::impersonator.start', [2]))
->assertSuccessful()
->assertSessionHas('impersonator_id')
->assertSeeText('Impersonation started');

$response->assertSuccessful();
$response->assertSessionHas('impersonator_id');
$response->assertSeeText('Impersonation started');

$response = $this->get(route('auth::impersonator.stop'));

$response->assertSuccessful();
$response->assertSessionMissing('impersonator_id');
$response->assertSeeText('Impersonation stopped');
$this->get(route('auth::impersonator.stop'))
->assertSuccessful()
->assertSessionMissing('impersonator_id')
->assertSeeText('Impersonation stopped');
}

/** @test */
public function it_can_redirect_if_impersonation_not_started()
{
$this->loginWithId(1);

$response = $this->get(route('auth::impersonator.stop'));

$response->assertStatus(302);
$this->get(route('auth::impersonator.stop'))
->assertStatus(Response::HTTP_FOUND);
}

/** @test */
Expand All @@ -80,8 +76,7 @@ public function it_can_deny_access_if_impersonation_is_disabled()

$this->loginWithId(1);

$response = $this->get(route('auth::impersonator.start', [2]));

$response->assertStatus(403);
$this->get(route('auth::impersonator.start', [2]))
->assertStatus(Response::HTTP_FORBIDDEN);
}
}
22 changes: 11 additions & 11 deletions tests/ImpersonationTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ public function it_can_impersonate()
{
$admin = $this->loginWithId(1);

$this->assertTrue($admin->canImpersonate());
static::assertTrue($admin->canImpersonate());
}

/** @test */
public function it_can_not_impersonate()
{
$user = $this->loginWithId(2);

$this->assertFalse($user->canImpersonate());
static::assertFalse($user->canImpersonate());
}

/** @test */
public function it_can_be_impersonated()
{
$user = $this->loginWithId(2);

$this->assertTrue($user->canBeImpersonated());
static::assertTrue($user->canBeImpersonated());
}

/** @test */
public function it_can_not_be_impersonated()
{
$admin = $this->loginWithId(1);

$this->assertFalse($admin->canBeImpersonated());
static::assertFalse($admin->canBeImpersonated());
}

/** @test */
Expand All @@ -51,21 +51,21 @@ public function it_can_start_and_stop_the_impersonation()
/** @var \Arcanedev\LaravelImpersonator\Tests\Stubs\Models\User $admin */
$admin = $this->loginWithId(1);

$this->assertFalse($admin->isImpersonated());
static::assertFalse($admin->isImpersonated());

/** @var \Arcanedev\LaravelImpersonator\Tests\Stubs\Models\User $user */
$user = $this->impersonator()->findUserById(2);

$admin->impersonate($user);

$this->assertTrue($user->isImpersonated());
$this->assertSame($user->id, $this->getAuthenticatedUser()->getKey());
$this->assertSame($admin->id, $this->impersonator()->getImpersonatorId());
static::assertTrue($user->isImpersonated());
static::assertSame($user->id, $this->getAuthenticatedUser()->getKey());
static::assertSame($admin->id, $this->impersonator()->getImpersonatorId());

$admin->stopImpersonation();

$this->assertFalse($user->isImpersonated());
$this->assertSame($admin->id, $this->getAuthenticatedUser()->getKey());
$this->assertNotSame($user->id, $this->getAuthenticatedUser()->getKey());
static::assertFalse($user->isImpersonated());
static::assertSame($admin->id, $this->getAuthenticatedUser()->getKey());
static::assertNotSame($user->id, $this->getAuthenticatedUser()->getKey());
}
}
8 changes: 4 additions & 4 deletions tests/ImpersonatorServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class ImpersonatorServiceProviderTest extends TestCase
| -----------------------------------------------------------------
*/

protected function setUp()
protected function setUp(): void
{
parent::setUp();

$this->provider = $this->app->getProvider(ImpersonatorServiceProvider::class);
}

protected function tearDown()
protected function tearDown(): void
{
unset($this->provider);

Expand All @@ -53,7 +53,7 @@ public function it_can_be_instantiated()
];

foreach ($expectations as $expected) {
$this->assertInstanceOf($expected, $this->provider);
static::assertInstanceOf($expected, $this->provider);
}
}

Expand All @@ -64,6 +64,6 @@ public function it_can_provides()
\Arcanedev\LaravelImpersonator\Contracts\Impersonator::class,
];

$this->assertSame($expected, $this->provider->provides());
static::assertSame($expected, $this->provider->provides());
}
}
Loading

0 comments on commit f72bc3f

Please sign in to comment.