<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
         bootstrap="tests/bootstrap.php"
         cacheResultFile="tests/.phpunit.result.cache"
         executionOrder="depends,defects"
         forceCoversAnnotation="true"
         beStrictAboutCoversAnnotation="true"
         beStrictAboutOutputDuringTests="true"
         beStrictAboutTodoAnnotatedTests="true"
         convertDeprecationsToExceptions="true"
         failOnRisky="true"
         failOnWarning="true"
         verbose="true"
         colors="true">

    <!-- Test Suites -->
    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">tests/unit</directory>
        </testsuite>
        <testsuite name="Integration">
            <directory suffix="Test.php">tests/integration</directory>
        </testsuite>
        <testsuite name="Feature">
            <directory suffix="Test.php">tests/feature</directory>
        </testsuite>
    </testsuites>

    <!-- Coverage Configuration -->
    <coverage cacheDirectory="tests/.phpunit.cache"
              processUncoveredFiles="true">
        <include>
            <directory suffix=".php">src</directory>
            <directory suffix=".php">libraries</directory>
            <directory suffix=".php">models</directory>
            <directory suffix=".php">controllers</directory>
            <directory suffix=".php">helpers</directory>
        </include>
        <exclude>
            <directory>vendor</directory>
            <directory>tests</directory>
            <file>config/autoload.php</file>
        </exclude>
        <report>
            <html outputDirectory="coverage-html"/>
            <text outputFile="coverage.txt"/>
            <xml outputDirectory="coverage-xml"/>
        </report>
    </coverage>

    <!-- Logging -->
    <logging>
        <junit outputFile="tests/logs/junit.xml"/>
        <teamcity outputFile="tests/logs/teamcity.txt"/>
        <testdoxHtml outputFile="tests/logs/testdox.html"/>
        <testdoxText outputFile="tests/logs/testdox.txt"/>
    </logging>

    <!-- PHP Configuration -->
    <php>
        <!-- Environment Variables -->
        <env name="APP_ENV" value="testing"/>
        <env name="APP_DEBUG" value="true"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
        
        <!-- Desk-Moloni Test Configuration -->
        <env name="DESK_MOLONI_API_BASE_URL" value="https://api.moloni.pt/v1/"/>
        <env name="DESK_MOLONI_OAUTH_BASE_URL" value="https://www.moloni.pt/v1/"/>
        <env name="DESK_MOLONI_TEST_MODE" value="true"/>
        <env name="DESK_MOLONI_DEBUG" value="true"/>
        
        <!-- Database Configuration -->
        <env name="DB_CONNECTION" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:"/>
        
        <!-- Redis Configuration for Testing -->
        <env name="REDIS_HOST" value="127.0.0.1"/>
        <env name="REDIS_PORT" value="6379"/>
        <env name="REDIS_PASSWORD" value=""/>
        <env name="REDIS_DATABASE" value="15"/>
        
        <!-- Test API Credentials (Mock) -->
        <env name="MOLONI_CLIENT_ID" value="test_client_id"/>
        <env name="MOLONI_CLIENT_SECRET" value="test_client_secret"/>
        <env name="MOLONI_USERNAME" value="test@example.com"/>
        <env name="MOLONI_PASSWORD" value="test_password"/>
        <env name="MOLONI_COMPANY_ID" value="123456"/>
        
        <!-- Performance Testing -->
        <env name="PERFORMANCE_TEST_ITERATIONS" value="100"/>
        <env name="PERFORMANCE_TEST_TIMEOUT" value="30"/>
        
        <!-- Constants -->
        <const name="PHPUNIT_TESTSUITE" value="true"/>
    </php>

    <!-- Extensions -->
    <extensions>
        <!-- Mock Server Extension for API Testing -->
        <extension class="PHPUnit\Extensions\MockWebServer\MockWebServerExtension"/>
    </extensions>

    <!-- Listeners -->
    <listeners>
        <!-- Performance Listener -->
        <listener class="DeskMoloni\Tests\Listeners\PerformanceListener"/>
        <!-- Memory Usage Listener -->
        <listener class="DeskMoloni\Tests\Listeners\MemoryUsageListener"/>
    </listeners>

    <!-- Groups -->
    <groups>
        <include>
            <group>unit</group>
            <group>integration</group>
            <group>feature</group>
        </include>
        <exclude>
            <group>slow</group>
            <group>network</group>
            <group>external</group>
        </exclude>
    </groups>
</phpunit>