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:
@@ -10,18 +10,18 @@ use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
use {{TargetClassFullName}};
|
||||
// use {{DependencyInterfaceFullName}};
|
||||
|
||||
class {{ClassName}}Test extends TestCase
|
||||
{
|
||||
// private {{DependencyInterface}}&MockInterface $dependencyMock;
|
||||
private MockInterface $dependencyMock;
|
||||
private {{ClassName}} $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
// $this->dependencyMock = Mockery::mock({{DependencyInterface}}::class);
|
||||
// $this->service = new {{ClassName}}($this->dependencyMock);
|
||||
// Giả lập dependencies qua Mockery
|
||||
$this->dependencyMock = Mockery::mock('DependencyInterface');
|
||||
$this->service = new {{ClassName}}($this->dependencyMock);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
@@ -31,24 +31,58 @@ class {{ClassName}}Test extends TestCase
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_executes_successfully_under_normal_conditions(): void
|
||||
public function it_executes_successfully_with_valid_input(): void
|
||||
{
|
||||
// 1. Arrange
|
||||
$input = 'valid_input';
|
||||
$expectedResult = 'expected_output';
|
||||
|
||||
$this->dependencyMock
|
||||
->shouldReceive('execute')
|
||||
->once()
|
||||
->with($input)
|
||||
->andReturn($expectedResult);
|
||||
|
||||
// 2. Act
|
||||
$actualResult = $this->service->process($input);
|
||||
|
||||
// 3. Assert
|
||||
$this->assertTrue(true);
|
||||
$this->assertSame($expectedResult, $actualResult);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_throws_exception_when_input_is_invalid(): void
|
||||
public function it_handles_edge_cases_with_null_or_empty_input(): void
|
||||
{
|
||||
// 1. Arrange
|
||||
// 1. Arrange - Test kịch bản biên với giá trị rỗng/mặc định
|
||||
$fallbackResult = 'default_fallback';
|
||||
|
||||
$this->dependencyMock
|
||||
->shouldReceive('execute')
|
||||
->once()
|
||||
->with('')
|
||||
->andReturn($fallbackResult);
|
||||
|
||||
// 2. Act
|
||||
$result = $this->service->process('');
|
||||
|
||||
// 3. Assert - Xác minh xử lý đúng giá trị biên
|
||||
$this->assertSame($fallbackResult, $result);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_throws_exception_and_handles_error_when_dependency_fails(): void
|
||||
{
|
||||
// 1. Arrange - Ép mock ném ngoại lệ để kiểm thử khối catch / exception handling
|
||||
$this->dependencyMock
|
||||
->shouldReceive('execute')
|
||||
->once()
|
||||
->andThrow(new \RuntimeException('Service unavailable'));
|
||||
|
||||
// 2. Assert Expectation
|
||||
// $this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectExceptionMessage('Service unavailable');
|
||||
|
||||
// 3. Act
|
||||
$this->service->process('invalid_trigger');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user