Skip to content

Commit

Permalink
feat: add getGateMock test assertion method
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Jul 12, 2023
1 parent 95d68f0 commit 69eeff7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Traits/TestTraits/PhpUnit/TestAssertionHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,32 @@
namespace Apiato\Core\Traits\TestTraits\PhpUnit;

use Apiato\Core\Abstracts\Models\Model;
use Illuminate\Auth\Access\Gate;
use Illuminate\Support\Collection;
use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;

trait TestAssertionHelperTrait
{
/**
* Assert that the Gate::allows() method is called once with the given arguments.
*
* @param string $policyMethodName
* @param ...$args
* @return Gate|(Gate&MockObject)|MockObject
* @throws Exception
*/
protected function getGateMock(string $policyMethodName, ...$args)
{
$gateMock = $this->createMock(Gate::class);
$gateMock->expects($this->once())
->method('allows')
->with($policyMethodName, ...$args)
->willReturn(true);

return $gateMock;
}

/**
* Assert that the model casts field is empty.
* By default, the model casts will have 'id' and 'deleted_at' fields (given model is soft deletable).
Expand Down

0 comments on commit 69eeff7

Please sign in to comment.