Skip to content

Commit

Permalink
Merge pull request #325 from spira/analysis-zR3wK8
Browse files Browse the repository at this point in the history
Applied fixes from StyleCI
  • Loading branch information
zakhenry committed Dec 17, 2015
2 parents 3b29ed2 + dcb74b4 commit 6eedd3d
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 27 deletions.
4 changes: 2 additions & 2 deletions api/app/Console/Commands/CreateUserCommand.php
Expand Up @@ -60,7 +60,7 @@ public function handle()
$validator = Validator::make($userData, $validationRules);

if ($validator->fails()) {
$this->error("Validation failed:");
$this->error('Validation failed:');
// @codeCoverageIgnoreStart
if (env('APP_ENV') != 'testing') {
(new Dumper)->dump($validator->errors()->toArray());
Expand All @@ -76,7 +76,7 @@ public function handle()

$user->setCredential(new UserCredential(['password' => $password]));

$this->info("Successfully created user:");
$this->info('Successfully created user:');

// @codeCoverageIgnoreStart
if (env('APP_ENV') != 'testing') {
Expand Down
2 changes: 1 addition & 1 deletion api/app/Models/User.php
Expand Up @@ -66,7 +66,7 @@ class User extends IndexedModel implements AuthenticatableContract, SocialiteAut
];

/**
* Model validation
* Model validation.
* @param null $entityId
* @return array
*/
Expand Down
8 changes: 4 additions & 4 deletions api/app/Providers/AuthDriverServiceProvider.php
Expand Up @@ -37,10 +37,10 @@ protected function getPayloadGenerators()

return $transformer->transformItem($user);
},
'method' => function (SocialiteAuthenticatable $user) { return $user->getCurrentAuthMethod() ?: 'password';},
'iss' => function () use ($request) { return $request->getHttpHost();},
'aud' => function () use ($request) { return str_replace('api.', '', $request->getHttpHost());},
'sub' => function (Authenticatable $user) {return $user->getAuthIdentifier();},
'method' => function (SocialiteAuthenticatable $user) { return $user->getCurrentAuthMethod() ?: 'password'; },
'iss' => function () use ($request) { return $request->getHttpHost(); },
'aud' => function () use ($request) { return str_replace('api.', '', $request->getHttpHost()); },
'sub' => function (Authenticatable $user) {return $user->getAuthIdentifier(); },
]
);
}
Expand Down
10 changes: 5 additions & 5 deletions api/src/Auth/Providers/JWTAuthDriverServiceProvider.php
Expand Up @@ -261,11 +261,11 @@ protected function getPayloadGenerators()
$request = $this->app['request'];

return [
'iss' => function () use ($request) { return $request->url();},
'iat' => function () { return Carbon::now()->format('U');},
'exp' => function () { return Carbon::now()->addMinutes($this->ttl)->format('U');},
'nbf' => function () { return Carbon::now()->format('U');},
'jti' => function () { return str_random(16);},
'iss' => function () use ($request) { return $request->url(); },
'iat' => function () { return Carbon::now()->format('U'); },
'exp' => function () { return Carbon::now()->addMinutes($this->ttl)->format('U'); },
'nbf' => function () { return Carbon::now()->format('U'); },
'jti' => function () { return str_random(16); },
];
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/Rbac/Access/Gate.php
Expand Up @@ -118,7 +118,7 @@ public function check($itemName, $arguments = [])
*/
public function forUser(Authenticatable $user)
{
return new static($this->getStorage(), function () use ($user) {return $user;}, $this->defaultRoles);
return new static($this->getStorage(), function () use ($user) {return $user; }, $this->defaultRoles);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion api/tests/Auth/PayloadFactoryTest.php
Expand Up @@ -26,7 +26,7 @@ public function testFactory()
$user = m::mock(Authenticatable::class);
$this->assertEquals($array, $factory->createFromUser($user));

$factory->addPayloadGenerator('user', function ($user) {return $user;});
$factory->addPayloadGenerator('user', function ($user) {return $user; });

$array['user'] = $user;

Expand Down
8 changes: 4 additions & 4 deletions api/tests/Auth/PayloadValidatorFactoryTest.php
Expand Up @@ -17,21 +17,21 @@ public function testFactory()
{
$payload = ['one' => true, 'two' => 'two'];
$closure = [
'one' => function ($payload) {return $payload['one'];},
'one' => function ($payload) {return $payload['one']; },
];

$factory = new PayloadValidationFactory($closure);
$this->assertNull($factory->validatePayload($payload));

$factory->addValidationRule('two', function ($payload) {return $payload['two'] == 'two';});
$factory->addValidationRule('two', function ($payload) {return $payload['two'] == 'two'; });
$this->assertNull($factory->validatePayload($payload));
}

public function testRuleFailed()
{
$payload = ['one' => true, 'two' => 'two'];
$closure = [
'one' => function () {return false;},
'one' => function () {return false; },
];

$factory = new PayloadValidationFactory($closure);
Expand All @@ -42,7 +42,7 @@ public function testRuleFailed()
public function testMissingRule()
{
$closure = [
'three' => function ($payload) {return true;},
'three' => function ($payload) {return true; },
];

$factory = new PayloadValidationFactory($closure);
Expand Down
10 changes: 3 additions & 7 deletions api/tests/CommandTest.php
Expand Up @@ -45,7 +45,6 @@ public function testGenerateKeysCommandMakeDirectory()

public function testCreateUserCommand()
{

$email = 'john.command.example@example.com';
$name = 'John';
$username = 'john';
Expand All @@ -67,17 +66,15 @@ public function testCreateUserCommand()
$this->assertEquals($name, $userCreated->first_name);
$this->assertEquals($username, $userCreated->username);

$this->assertTrue($userCreated->roles->contains(function ($key, Role $roleModel) use ($role){
$this->assertTrue($userCreated->roles->contains(function ($key, Role $roleModel) use ($role) {
return $roleModel->key == $role;
}), 'Role is applied');

$this->assertTrue(Auth::attempt(['email' => $email, 'password' => $password]), 'Credentials work.');

}

public function testCreateInvalidUserCommand()
{

$email = 'invalid-email';
$name = 'John';
$username = 'john';
Expand All @@ -101,7 +98,7 @@ public function testCreateInvalidUserCommand()
private function mockUserCreateCommand($email, $name, $username, $password, $role)
{
/** @var CreateUserCommand $cmd */
$cmd = Mockery::mock(CreateUserCommand::class . "[ask, secret, choice, info, error]");
$cmd = Mockery::mock(CreateUserCommand::class.'[ask, secret, choice, info, error]');

$cmd->shouldReceive('ask')
->with('Enter email')
Expand All @@ -127,8 +124,7 @@ private function mockUserCreateCommand($email, $name, $username, $password, $rol
->with('What roles should be applied? (comma separate options)', ROLE::$roles, null, null, true)
->once()
->andReturn([$role]);

return $cmd;
}


}
4 changes: 2 additions & 2 deletions api/tests/integration/AuthTest.php
Expand Up @@ -550,8 +550,8 @@ public function testValidateCustomPayload()
{
/** @var Guard $guard */
$guard = $this->app['auth'];
$guard->getPayloadFactory()->addPayloadGenerator('foo', function () {return 'foo';});
$guard->getValidationFactory()->addValidationRule('foo', function () { return false;});
$guard->getPayloadFactory()->addPayloadGenerator('foo', function () {return 'foo'; });
$guard->getValidationFactory()->addValidationRule('foo', function () { return false; });

$user = $this->createUser();
$token = $this->tokenFromUser($user);
Expand Down

0 comments on commit 6eedd3d

Please sign in to comment.