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
105 lines
2.3 KiB
PHP
105 lines
2.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Test\TestCase\Model\Table;
|
|
|
|
use App\Model\Table\{{TABLE_NAME}}Table;
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
/**
|
|
* App\Model\Table\{{TABLE_NAME}}Table Test Case
|
|
*/
|
|
class {{TABLE_NAME}}TableTest extends TestCase
|
|
{
|
|
/**
|
|
* Test subject
|
|
*
|
|
* @var \App\Model\Table\{{TABLE_NAME}}Table
|
|
*/
|
|
protected {{TABLE_NAME}}Table ${{VARIABLE_NAME}};
|
|
|
|
/**
|
|
* Fixtures
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected array $fixtures = [
|
|
'app.{{TABLE_NAME}}',
|
|
];
|
|
|
|
/**
|
|
* setUp method
|
|
*/
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$config = $this->getTableLocator()->exists('{{TABLE_NAME}}') ? [] : ['className' => {{TABLE_NAME}}Table::class];
|
|
$this->{{VARIABLE_NAME}} = $this->getTableLocator()->get('{{TABLE_NAME}}', $config);
|
|
}
|
|
|
|
/**
|
|
* tearDown method
|
|
*/
|
|
protected function tearDown(): void
|
|
{
|
|
unset($this->{{VARIABLE_NAME}});
|
|
parent::tearDown();
|
|
}
|
|
|
|
/**
|
|
* Test validationDefault method with valid data
|
|
*/
|
|
public function testValidationDefaultSuccess(): void
|
|
{
|
|
// Arrange
|
|
$data = [
|
|
'name' => 'Valid Title',
|
|
'status' => 'active',
|
|
];
|
|
|
|
// Act
|
|
$entity = $this->{{VARIABLE_NAME}}->newEntity($data);
|
|
|
|
// Assert
|
|
$this->assertEmpty($entity->getErrors());
|
|
}
|
|
|
|
/**
|
|
* Test validationDefault method with missing required fields
|
|
*/
|
|
public function testValidationDefaultFailsOnRequiredFields(): void
|
|
{
|
|
// Arrange
|
|
$data = [];
|
|
|
|
// Act
|
|
$entity = $this->{{VARIABLE_NAME}}->newEntity($data);
|
|
|
|
// Assert
|
|
$this->assertNotEmpty($entity->getErrors());
|
|
$this->assertArrayHasKey('name', $entity->getErrors());
|
|
}
|
|
|
|
/**
|
|
* Test save and find
|
|
*/
|
|
public function testSaveAndFind(): void
|
|
{
|
|
// Arrange
|
|
$entity = $this->{{VARIABLE_NAME}}->newEntity([
|
|
'name' => 'Sample Record',
|
|
'status' => 'active',
|
|
]);
|
|
|
|
// Act
|
|
$result = $this->{{VARIABLE_NAME}}->save($entity);
|
|
|
|
// Assert
|
|
$this->assertNotFalse($result);
|
|
$this->assertNotNull($result->id);
|
|
|
|
$saved = $this->{{VARIABLE_NAME}}->get($result->id);
|
|
$this->assertSame('Sample Record', $saved->name);
|
|
}
|
|
}
|