da1bd48444
- Decouple framework installation: add install-laravel.sh and install-cakephp.sh, isolate skills and docs per framework, and auto-clean leftover artifacts - Remove all SonarQube configs, templates, and references - Enforce comprehensive test completeness: 100% public methods, edge cases, full branch coverage, exception paths, and state assertions - Replace all placeholder assertions in PHPUnit and Pest templates with full realistic implementations - Rename and update 10-comprehensive-test-coverage-guide.md
56 lines
1.2 KiB
PHP
56 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\{{Namespace}};
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use {{TargetClassFullName}};
|
|
use App\Models\User;
|
|
|
|
class {{ClassName}}Test extends TestCase
|
|
{
|
|
private {{ClassName}} $policy;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->policy = new {{ClassName}}();
|
|
}
|
|
|
|
#[Test]
|
|
public function it_allows_authorized_user_to_perform_action(): void
|
|
{
|
|
// 1. Arrange: User sở hữu tài nguyên hoặc có quyền hạn
|
|
$user = new User();
|
|
$user->id = 1;
|
|
|
|
$resource = new \stdClass();
|
|
$resource->user_id = 1;
|
|
|
|
// 2. Act
|
|
$result = $this->policy->view($user, $resource);
|
|
|
|
// 3. Assert
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
#[Test]
|
|
public function it_denies_unauthorized_user_from_performing_action(): void
|
|
{
|
|
// 1. Arrange: User khác không có quyền hạn
|
|
$user = new User();
|
|
$user->id = 2;
|
|
|
|
$resource = new \stdClass();
|
|
$resource->user_id = 1;
|
|
|
|
// 2. Act
|
|
$result = $this->policy->update($user, $resource);
|
|
|
|
// 3. Assert
|
|
$this->assertFalse($result);
|
|
}
|
|
}
|