Backend Testing Integration

Integration tests, database testing.

valec3 Updated

File contents

Backend Testing Integration

When to use this skill

  • Testing with database
  • API endpoint testing
  • Feature testing
  • End-to-end flows

Workflow

  • Use test database
  • Seed data
  • Test full flows
  • Reset database
  • Test API responses

Instructions

Database Test

<?php

namespace Tests\Integration;

use CodeIgniter\Test\CIDatabaseTestCase;

class UserModelTest extends CIDatabaseTestCase
{
    protected $seed = 'TestSeeder';
    protected $basePath = 'tests/database';

    public function testFindUserByEmail()
    {
        $model = new UserModel();
        $user = $model->where('email', 'test@example.com')->first();

        $this->assertNotNull($user);
        $this->assertEquals('test@example.com', $user->email);
    }
}

Feature Test

<?php

$result = $this->withHeaders(['Authorization' => 'Bearer ' . $token])
    ->post('/api/users', ['name' => 'John'])
    ->json();

$this->assertEquals(201, $result->getStatusCode());

Resources

  • Use separate test database
  • Seed fixtures
  • Test full request/response

valec3/Agents.skills.md/tree/main/.agent/skills/backend-testing-integration commit acb68268d4

Frequently asked questions

npx skillmds@latest add valec3/backend-testing-integration