Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdimsr committed Jul 10, 2022
2 parents c4eb449 + ab5284c commit fd91553
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/ActionPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public static function builder(): ActionPolicyBuilder

public function run(): Response
{
if ($this->runPolicy()->allowed() and $this->getModelMethod() !== null) {
if ($this->authorizePolicy()->allowed() and $this->getModelMethod() !== null) {
$this->runModel();
}

return $this->runPolicy();
return $this->authorizePolicy();
}
}
2 changes: 1 addition & 1 deletion src/Decorator/BaseActionPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getPolicyArguments(): array
return $this->policyArguments;
}

public function runPolicy(): Response
public function authorizePolicy(): Response
{
return call_user_func_array([$this->getPolicy(),$this->getPolicyMethod()], $this->getPolicyArguments());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Decorator/Interfaces/RunAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface RunAction
{
public function runModel(): mixed;

public function runPolicy(): Response;
public function authorizePolicy(): Response;

public function run(): Response;
}
8 changes: 4 additions & 4 deletions tests/unit/ActionPolicyResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
use Msr\ActionPolicy\Tests\assets\TestPolicy;

it('get Response policy function', function () {
$response = ActionPolicy::builder()->policy(TestPolicy::class)->policyMethod('canSetName')->build()->runPolicy();
$response = ActionPolicy::builder()->policy(TestPolicy::class)->policyMethod('canSetName')->build()->authorizePolicy();

$this->assertInstanceOf(\Illuminate\Auth\Access\Response::class, $response);
});

it('get allowed Response policy function with one argument', function () {
$response = ActionPolicy::builder()->policy(TestPolicy::class)->policyMethod('canSetJohn', 'John')->build()->runPolicy();
$response = ActionPolicy::builder()->policy(TestPolicy::class)->policyMethod('canSetJohn', 'John')->build()->authorizePolicy();

$this->assertTrue($response->allowed());
});

it('get denied Response policy function with one argument', function () {
$response = ActionPolicy::builder()->policy(TestPolicy::class)->policyMethod('canSetJohn', 'Max')->build()->runPolicy();
$response = ActionPolicy::builder()->policy(TestPolicy::class)->policyMethod('canSetJohn', 'Max')->build()->authorizePolicy();

$this->assertTrue($response->denied());
});

it('get denied Response policy function with some arguments', function () {
$response = ActionPolicy::builder()->policy(TestPolicy::class)->policyMethod('canBeFriend', 'Max', 'Peter', 'Alex')->build()->runPolicy();
$response = ActionPolicy::builder()->policy(TestPolicy::class)->policyMethod('canBeFriend', 'Max', 'Peter', 'Alex')->build()->authorizePolicy();

$this->assertTrue($response->allowed());
});
Expand Down

0 comments on commit fd91553

Please sign in to comment.