feat: decouple Laravel and CakePHP installers, remove SonarQube artifacts, and enforce complete unit testing standards
- 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
This commit is contained in:
@@ -6,6 +6,7 @@ namespace Tests\Unit\{{Namespace}};
|
||||
|
||||
use Tests\TestCase;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use {{TargetClassFullName}};
|
||||
|
||||
@@ -22,35 +23,63 @@ class {{ClassName}}Test extends TestCase
|
||||
#[Test]
|
||||
public function it_authorizes_request_appropriately(): void
|
||||
{
|
||||
// Assert authorize() returns expected boolean
|
||||
// Assert: Xác minh phương thức authorize() cho phép thực thi
|
||||
$this->assertTrue($this->request->authorize());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_passes_validation_with_valid_payload(): void
|
||||
{
|
||||
// Arrange
|
||||
// 1. Arrange: Chuẩn bị dữ liệu hợp lệ thỏa mãn toàn bộ rules
|
||||
$validPayload = [
|
||||
// Cung cấp dữ liệu chuẩn
|
||||
'name' => 'John Doe',
|
||||
'email' => 'john@example.com',
|
||||
'status' => 'active',
|
||||
];
|
||||
|
||||
// Act
|
||||
// 2. Act
|
||||
$validator = Validator::make($validPayload, $this->request->rules());
|
||||
|
||||
// Assert
|
||||
$this->assertFalse($validator->fails());
|
||||
// 3. Assert
|
||||
$this->assertFalse($validator->fails(), 'Validation should pass with valid payload');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_fails_validation_when_required_fields_are_missing(): void
|
||||
{
|
||||
// Arrange
|
||||
// 1. Arrange: Payload rỗng thiếu toàn bộ trường bắt buộc
|
||||
$emptyPayload = [];
|
||||
|
||||
// Act
|
||||
// 2. Act
|
||||
$validator = Validator::make($emptyPayload, $this->request->rules());
|
||||
|
||||
// Assert
|
||||
// 3. Assert
|
||||
$this->assertTrue($validator->fails(), 'Validation must fail when required fields are missing');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[DataProvider('invalidPayloadDataProvider')]
|
||||
public function it_fails_validation_for_specific_invalid_rules(array $invalidPayload, string $expectedFailedField): void
|
||||
{
|
||||
// Act
|
||||
$validator = Validator::make($invalidPayload, $this->request->rules());
|
||||
|
||||
// Assert: Bắt buộc xác minh lỗi vi phạm đúng trường mong đợi
|
||||
$this->assertTrue($validator->fails());
|
||||
$this->assertArrayHasKey($expectedFailedField, $validator->errors()->toArray());
|
||||
}
|
||||
|
||||
public static function invalidPayloadDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'invalid email format' => [
|
||||
['name' => 'John Doe', 'email' => 'invalid-email-format'],
|
||||
'email',
|
||||
],
|
||||
'whitespace name' => [
|
||||
['name' => ' ', 'email' => 'john@example.com'],
|
||||
'name',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user