Omda's avatar
Level 1

my testing taking too much time to pass

its working fine but its take a wile to run once function... take about 1.23 minuts.

this phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>

        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="BCRYPT_ROUNDS" value="4"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="MAIL_DRIVER" value="array"/>
        <env name="QUEUE_CONNECTION" value="sync"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="DB_CONNECTION" value="A_testing"/>
        <env name="DB_DATABASE" value=":memory:"/>
    </php>
</phpunit>

this .env

APP_NAME=Ali
APP_ENV=testing
APP_KEY=base64:4pMDQn44sFpSQW64I4TswIv5mV4l9Ck0UM0Om4aRQm0=
APP_DEBUG=false
APP_LOG_LEVEL=debug
APP_URL=http://localhost
# DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306


DB_CONNECTION=sqlite
DB_DATABASE=database.sqlite
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

this database connection

 'connections' => [

        'atroha_testing' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', storage_path("database.sqlite")),
            'prefix' => '',
        ],

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],

        'A_testing' => [
            'driver' => 'mysql',
            'host' => env('DB_TEST_HOST', 'localhost'),
            'port' => env('DB_TEST_PORT', '3306'),
            'database' => env('DB_TEST_DATABASE', 'database.sqlite'),
            'username' => env('DB_TEST_USERNAME', 'root'),
            'password' => env('DB_TEST_PASSWORD', ''),
            'unix_socket' => env('DB_TEST_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],
]
0 likes
4 replies
martinbean's avatar

@omda Which test? Look into what the test is testing and find the bottleneck.

Omda's avatar
Level 1

i update my question @martinbean

'A_testing' => [
            'driver' => 'mysql',
            'host' => env('DB_TEST_HOST', 'localhost'),
            'port' => env('DB_TEST_PORT', '3306'),
            'database' => env('DB_TEST_DATABASE', 'database.sqlite'),
            'username' => env('DB_TEST_USERNAME', 'root'),
            'password' => env('DB_TEST_PASSWORD', ''),
            'unix_socket' => env('DB_TEST_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],
martinbean's avatar

@omda Again, look at what your test case is doing and try and find any bottlenecks there. We can't really tell much from your phpunit.xml file.

flightsimmer668's avatar

@omda try running your test files one by one and see which file or files is taking the longest to run, like so

vendor/bin/phpunit tests/Unit/testFilename.php

Once you've figured that out, then next you can drill down to the specific test in that file to try and find the culprit that is running slowly. You can use the --filter argument for that, like so:

vendor/bin/phpunit --filter write_the_test_method_name_here

Please or to participate in this conversation.