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
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\{{Namespace}};
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Mockery;
|
|
use Mockery\MockInterface;
|
|
use {{TargetClassFullName}};
|
|
|
|
class {{ClassName}}Test extends TestCase
|
|
{
|
|
private MockInterface $dependencyMock;
|
|
private {{ClassName}} $action;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->dependencyMock = Mockery::mock('ActionDependencyInterface');
|
|
$this->action = new {{ClassName}}($this->dependencyMock);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Mockery::close();
|
|
parent::tearDown();
|
|
}
|
|
|
|
#[Test]
|
|
public function it_handles_action_invocation_successfully(): void
|
|
{
|
|
// 1. Arrange: Chuẩn bị payload/DTO đầu vào
|
|
$payload = ['key' => 'value'];
|
|
$expectedResult = 'success_result';
|
|
|
|
$this->dependencyMock
|
|
->shouldReceive('process')
|
|
->once()
|
|
->with($payload)
|
|
->andReturn($expectedResult);
|
|
|
|
// 2. Act: Thực thi invokable Action
|
|
$actualResult = ($this->action)($payload);
|
|
|
|
// 3. Assert: Kiểm tra chặt chẽ giá trị trả về
|
|
$this->assertSame($expectedResult, $actualResult);
|
|
}
|
|
}
|