Test environment setup for web project

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Test Environment Setup for Web Projects

A test environment is an isolated setup with its own database, configuration, and state. Without proper setup, tests become unstable, slow, and interfere with each other.

Test Environment Layers

Unit tests     → In-memory / mocks → no external dependencies
Integration    → Test database (SQLite or Docker PostgreSQL)
E2E / Browser  → Staging environment or local Docker Compose
Load tests     → Dedicated staging (isolated from main)

Docker Compose for Test Environment

# docker-compose.test.yml
services:
  app:
    build:
      context: .
      target: test
    environment:
      APP_ENV: testing
      DB_HOST: db
      DB_DATABASE: testdb
      REDIS_HOST: redis
      QUEUE_CONNECTION: sync    # queues sync in tests
      MAIL_MAILER: array        # intercept emails to array
      CACHE_DRIVER: array       # cache in memory
    depends_on:
      db: { condition: service_healthy }
      redis: { condition: service_healthy }

  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: testdb
      POSTGRES_USER: test
      POSTGRES_PASSWORD: test
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U test"]
      interval: 5s
      timeout: 3s
      retries: 5
    tmpfs:
      - /var/lib/postgresql/data   # DB in RAM — faster

  redis:
    image: redis:7-alpine
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s

Laravel Configuration for Tests

// phpunit.xml
<php>
    <env name="APP_ENV"          value="testing"/>
    <env name="DB_CONNECTION"    value="sqlite"/>
    <env name="DB_DATABASE"      value=":memory:"/>
    <env name="CACHE_DRIVER"     value="array"/>
    <env name="SESSION_DRIVER"   value="array"/>
    <env name="QUEUE_CONNECTION" value="sync"/>
    <env name="MAIL_MAILER"      value="array"/>
</php>
// Basic TestCase with transactions
abstract class TestCase extends BaseTestCase
{
    use RefreshDatabase;  // rollback DB after each test

    protected function setUp(): void
    {
        parent::setUp();
        $this->withoutVite();  // don't run Vite in tests
        $this->seed(TestDatabaseSeeder::class);
    }
}

Test Isolation

Transactions (fast, but not for HTTP-client tests):

// DatabaseTransactions trait — rollback after each test
use DatabaseTransactions;

Migrations (slower, but more reliable):

// RefreshDatabase trait — recreate DB before each test
use RefreshDatabase;

Mocking External Services:

// Don't make real HTTP requests in tests
Http::fake([
    'api.stripe.com/*'  => Http::response(['id' => 'pi_test_123'], 200),
    'api.sendgrid.com/*' => Http::response(['message_id' => 'test'], 202),
    '*'                 => Http::response(['error' => 'Unexpected request'], 500),
]);

// Intercept email
Mail::fake();
// Verify
Mail::assertSent(OrderConfirmationMail::class, fn($mail) =>
    $mail->hasTo('[email protected]')
);

Test Data Factories

// database/factories/UserFactory.php
class UserFactory extends Factory
{
    public function definition(): array
    {
        return [
            'name'              => $this->faker->name(),
            'email'             => $this->faker->unique()->safeEmail(),
            'email_verified_at' => now(),
            'password'          => Hash::make('password'),
        ];
    }

    public function admin(): static
    {
        return $this->afterCreating(fn(User $user) =>
            $user->assignRole('admin')
        );
    }

    public function unverified(): static
    {
        return $this->state(['email_verified_at' => null]);
    }
}

// Usage in tests
$user = User::factory()->admin()->create();
$users = User::factory()->count(10)->create();

CI/CD — GitHub Actions

name: Tests

on: [push, pull_request]

jobs:
  unit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with: { php-version: '8.3', extensions: 'sqlite3' }
      - run: composer install --no-interaction
      - run: php artisan test --parallel --testsuite=Unit

  integration:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:16
        env:
          POSTGRES_DB: testdb
          POSTGRES_PASSWORD: test
        ports: ['5432:5432']
        options: --health-cmd pg_isready --health-interval 5s
    env:
      DB_CONNECTION: pgsql
      DB_HOST: localhost
      DB_DATABASE: testdb
      DB_PASSWORD: test
    steps:
      - uses: actions/checkout@v4
      - run: composer install
      - run: php artisan test --testsuite=Feature

Test Database Seeder

class TestDatabaseSeeder extends Seeder
{
    public function run(): void
    {
        // Minimal data set for tests
        Role::create(['name' => 'admin']);
        Role::create(['name' => 'user']);

        Category::factory(5)->create();
        Product::factory(20)->create();
    }
}

Implementation Timeline

Setting up a test environment from scratch (Docker + CI + factories): 3–5 days.