<?php

namespace Tests;

use App\Newsletter\CampaignMonitor;
use App\Newsletter\MailChimp;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Facades\Event;
use Stancl\Tenancy\Events\TenantCreated;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;
    use DispatchesJobs;

    #[\Override]
    protected function setUp(): void
    {
        parent::setUp();

        $this->app->bind(MailChimp::class, fn () => new MailChimp(new FakeMailchimp('test-api-key')));

        $this->app->bind(
            CampaignMonitor::class,
            fn () => new CampaignMonitor(new FakeCampaignMonitor('list-id', ['api_key' => 'test-api-key']))
        );

        // Fake further events for tenant created to avoid building database for tenants
        Event::fake([TenantCreated::class]);
    }
}
