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.1 KiB
PHP
105 lines
2.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Test\TestCase\Controller;
|
|
|
|
use Cake\TestSuite\IntegrationTestTrait;
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
/**
|
|
* App\Controller\{{CONTROLLER_NAME}}Controller Test Case
|
|
*
|
|
* @uses \App\Controller\{{CONTROLLER_NAME}}Controller
|
|
*/
|
|
class {{CONTROLLER_NAME}}ControllerTest extends TestCase
|
|
{
|
|
use IntegrationTestTrait;
|
|
|
|
/**
|
|
* Fixtures
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected array $fixtures = [
|
|
'app.{{MODEL_NAME}}',
|
|
];
|
|
|
|
/**
|
|
* Test index method
|
|
*/
|
|
public function testIndex(): void
|
|
{
|
|
// Act
|
|
$this->get('/{{ROUTE_PATH}}');
|
|
|
|
// Assert
|
|
$this->assertResponseOk();
|
|
$this->assertResponseContains('{{EXPECTED_TEXT}}');
|
|
}
|
|
|
|
/**
|
|
* Test view method with valid ID
|
|
*/
|
|
public function testViewValidId(): void
|
|
{
|
|
// Act
|
|
$this->get('/{{ROUTE_PATH}}/view/1');
|
|
|
|
// Assert
|
|
$this->assertResponseOk();
|
|
}
|
|
|
|
/**
|
|
* Test add method GET renders form
|
|
*/
|
|
public function testAddGet(): void
|
|
{
|
|
// Act
|
|
$this->get('/{{ROUTE_PATH}}/add');
|
|
|
|
// Assert
|
|
$this->assertResponseOk();
|
|
}
|
|
|
|
/**
|
|
* Test add method POST with valid data
|
|
*/
|
|
public function testAddPostSuccess(): void
|
|
{
|
|
// Arrange
|
|
$this->enableCsrfToken();
|
|
$this->enableSecurityToken();
|
|
|
|
$data = [
|
|
'name' => 'New Item',
|
|
'status' => 'active',
|
|
];
|
|
|
|
// Act
|
|
$this->post('/{{ROUTE_PATH}}/add', $data);
|
|
|
|
// Assert
|
|
$this->assertResponseSuccess();
|
|
$this->assertRedirect(['action' => 'index']);
|
|
$this->assertFlashMessage('The {{ENTITY_LOWER}} has been saved.');
|
|
}
|
|
|
|
/**
|
|
* Test add method POST with validation errors
|
|
*/
|
|
public function testAddPostValidationFailure(): void
|
|
{
|
|
// Arrange
|
|
$this->enableCsrfToken();
|
|
$this->enableSecurityToken();
|
|
|
|
$data = []; // Empty or invalid data
|
|
|
|
// Act
|
|
$this->post('/{{ROUTE_PATH}}/add', $data);
|
|
|
|
// Assert
|
|
$this->assertResponseOk(); // Renders form view with errors
|
|
}
|
|
}
|