<?php

declare(strict_types=1);

namespace Tests\Support\Api;

use PHPUnit\Framework\TestCase;

class ApiTestCase extends TestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $skipReason = \api_test_runtime()->skipReason();
        if ($skipReason !== null) {
            if (getenv('API_TEST_FAIL_ON_SKIP') === '1') {
                throw new \RuntimeException($skipReason);
            }

            $this->markTestSkipped($skipReason);
        }

        \api_test_runtime()->beginTest();
    }

    protected function tearDown(): void
    {
        if (\api_tests_enabled()) {
            \api_test_runtime()->endTest();
        }

        parent::tearDown();
    }
}
