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
53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\{{Namespace}};
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Mockery;
|
|
use {{TargetClassFullName}};
|
|
|
|
class {{ClassName}}Test extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
Mockery::close();
|
|
parent::tearDown();
|
|
}
|
|
|
|
#[Test]
|
|
public function it_handles_job_execution_successfully(): void
|
|
{
|
|
// 1. Arrange: Khởi tạo Job và Mock các dịch vụ phụ thuộc
|
|
$dependencyMock = Mockery::mock('DependencyService');
|
|
$dependencyMock
|
|
->shouldReceive('execute')
|
|
->once()
|
|
->andReturn(true);
|
|
|
|
$job = new {{ClassName}}('sample-payload-data');
|
|
|
|
// 2. Act: BẮT BUỘC thực thi method handle()
|
|
$job->handle($dependencyMock);
|
|
|
|
// 3. Assert: Verify thông qua Mockery expectations và trạng thái xử lý
|
|
$this->addToAssertionCount(1);
|
|
}
|
|
|
|
#[Test]
|
|
public function it_handles_job_failure_cleanly(): void
|
|
{
|
|
// 1. Arrange: Chuẩn bị exception giả lập
|
|
$job = new {{ClassName}}('sample-payload-data');
|
|
$exception = new \RuntimeException('Processing failed permanently');
|
|
|
|
// 2. Act: BẮT BUỘC kiểm thử method failed(Throwable $e)
|
|
$job->failed($exception);
|
|
|
|
// 3. Assert: Xác minh việc dọn dẹp hoặc ghi log khi job thất bại hoàn toàn
|
|
$this->addToAssertionCount(1);
|
|
}
|
|
}
|