7425b263d5
- Add 4 CakePHP Claude Code skills: cakephp-unit-test, cakephp-test-setup, cakephp-test-review, cakephp-mock-helper - Add 11 CakePHP PHPUnit component templates (Table, Entity, Controller, Service, Command, Component, Middleware, Mailer, Form, Behavior, Helper) - Add CakePHP configs (phpunit.xml.dist, app_local.test.php for SQLite in-memory) - Add comprehensive CakePHP documentation and component guides - Update test-runner.sh and installer to auto-detect Laravel and CakePHP - Add CakePHP CI/CD templates for GitHub Actions and GitLab CI - Update system prompt, verification checklist, and README with dedicated guides
78 lines
1.7 KiB
PHP
78 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
|
|
if ($this->{{VARIABLE_NAME}}->has('full_name')) {
|
|
$this->assertSame('John Doe', $this->{{VARIABLE_NAME}}->full_name);
|
|
} else {
|
|
$this->assertTrue(true);
|
|
}
|
|
}
|
|
}
|