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
75 lines
1.7 KiB
PHP
75 lines
1.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Test\TestCase\Model\Entity;
|
|
|
|
use App\Model\Entity\{{ENTITY_NAME}};
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
/**
|
|
* App\Model\Entity\{{ENTITY_NAME}} Test Case
|
|
*/
|
|
class {{ENTITY_NAME}}Test extends TestCase
|
|
{
|
|
/**
|
|
* Test subject
|
|
*
|
|
* @var \App\Model\Entity\{{ENTITY_NAME}}
|
|
*/
|
|
protected {{ENTITY_NAME}} ${{VARIABLE_NAME}};
|
|
|
|
/**
|
|
* setUp method
|
|
*/
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->{{VARIABLE_NAME}} = new {{ENTITY_NAME}}();
|
|
}
|
|
|
|
/**
|
|
* tearDown method
|
|
*/
|
|
protected function tearDown(): void
|
|
{
|
|
unset($this->{{VARIABLE_NAME}});
|
|
parent::tearDown();
|
|
}
|
|
|
|
/**
|
|
* Test accessible fields configuration
|
|
*/
|
|
public function testAccessibleFields(): void
|
|
{
|
|
// Arrange
|
|
$data = [
|
|
'name' => 'John Doe',
|
|
'email' => 'john@example.com',
|
|
'id' => 999, // Typically non-accessible or guarded
|
|
];
|
|
|
|
// Act
|
|
$this->{{VARIABLE_NAME}}->set($data);
|
|
|
|
// Assert
|
|
$this->assertSame('John Doe', $this->{{VARIABLE_NAME}}->name);
|
|
$this->assertSame('john@example.com', $this->{{VARIABLE_NAME}}->email);
|
|
}
|
|
|
|
/**
|
|
* Test virtual fields if present
|
|
*/
|
|
public function testVirtualProperties(): void
|
|
{
|
|
// Arrange
|
|
$this->{{VARIABLE_NAME}}->set([
|
|
'first_name' => 'John',
|
|
'last_name' => 'Doe',
|
|
]);
|
|
|
|
// Act & Assert
|
|
$fullName = $this->{{VARIABLE_NAME}}->full_name ?? ($this->{{VARIABLE_NAME}}->first_name . ' ' . $this->{{VARIABLE_NAME}}->last_name);
|
|
$this->assertSame('John Doe', $fullName);
|
|
}
|
|
}
|