Logging

Adapt can log various details as it prepares a database, including any errors encountered.

Enable Logging

  1. Add to your .env.testing file:
    • ADAPT_LOG_LARAVEL=true and
    • ADAPT_LOG_VERBOSITY=2
  2. View Laravel's log file when you run your tests:
    • tail -f storage/logs/laravel.log
⚙️ See configuration
# .env.testing

ADAPT_LOG_LARAVEL=true
ADAPT_LOG_VERBOSITY=2

or

<?php
// config/code_distortion.adapt.php

return ['log' => [
        'stdout' => env('ADAPT_LOG_STDOUT', false),
        'laravel' => env('ADAPT_LOG_LARAVEL', true), // or false
        'verbosity' => env('ADAPT_LOG_VERBOSITY', 2), // 0 - 2
    ],];







 
 



Logging to Stdout

Normally, logs are written using Laravel's normal logging mechanism (usually to storage/logs/laravel.log).

You can choose to show the output on the screen instead (this will probably look messy amongst the normal output).

⚙️ See configuration
# .env.testing

ADAPT_LOG_STDOUT=true

or

<?php
// config/code_distortion.adapt.php

return ['log' => [
        'stdout' => env('ADAPT_LOG_STDOUT', true), // or false
        'laravel' => env('ADAPT_LOG_LARAVEL', false),
        'verbosity' => env('ADAPT_LOG_VERBOSITY', 0),
    ],];






 





Log Examples

NOTE

The actual details logged will depend on the steps Adapt takes to build each particular database.

Adapt first checks for stale databases to remove. It does this once, before any tests run:

Looking for stale things to remove
Generated a build-source checksum based on file modified timestamps (0ms)
Retrieved database list (connection: "mysql", driver: "mysql") (14ms)
- Found database "db_461b27_a3f454e722ed" (usable) (8ms)
- Found database "db_461b27_e66c70f1ee6c" (usable) (4ms)
Retrieved snapshot list (0ms)
- Found snapshot "/var/www/html/database/adapt-test-storage/snapshots/snapshot.db.461b27-1af3f9b38205.sqlite" (usable) (0ms)
Nothing found to remove - total time taken (27ms)

Adapt then determines which database/s to prepare for your test, and how to build it based on your configuration.

The settings used and the outcome are logged:

┌── ADAPT (v0.12.0) ────────────────────────────────────────────────────────────────┐
│ Preparing a database for connection "mysql"                                       │
│ For test "Tests\Feature\UserTest::test_that_a_user_can_be_stored_in_the_database" │
└───────────────────────────────────────────────────────────────────────────────────┘
┌── Software ──────┐
│ OS:      Linux   │
│ PHP:     8.1.7   │
│ Laravel: 9.23.0  │
│ PHPUnit: 9.5.21  │
│ Pest:    v1.21.3 │
│ Adapt:   0.12.0  │
│ MySQL:   8.0.29  │
└──────────────────┘
┌── Build Sources ────────────────────┐
│ Initial imports:   None             │
│ Migrations:        Yes              │
│ Seeder:            "DatabaseSeeder" │
│ Snapshots enabled? No               │
└─────────────────────────────────────┘
┌── Build Settings ──────────────────────────────────────┐
│ Using scenarios?    Yes                                │
│ Re-use method:      Transaction                        │
│ Verify db after?    No                                 │
│ For a browser test? No                                 │
│ Parallel testing?   No                                 │
│ Is a Pest test?     No                                 │
│ Build-checksum:     "461b27a4ac021242f3eb6a798d0aac4e" │
│ Snapshot-checksum:  "1af3f9b38205367b22bbccd58f486c25" │
│ Scenario-checksum:  "fba25141c2178fce740d467068f0a994" │
└────────────────────────────────────────────────────────┘
┌── Resolved Database ─────────────────┐
│ Connection: "mysql"                  │
│ Driver:     "mysql"                  │
│ Host:       "mysql"                  │
│ Database:   "db_461b27_fba25141c217" │
└──────────────────────────────────────┘


































 

Adapt then proceeds to build the database. This is an example of it creating a new database for the first time (this particular database is quite big - particularly because of its seeders):

Changed the database for connection "mysql" to "db_461b27_fba25141c217"
Created a new database (4ms)
Set up the re-use meta-data (5ms)
Ran migrations (353ms)
Ran seeder "\Database\Seeders\DatabaseSeeder" (847ms)
Built database "db_461b27_fba25141c217" - total preparation time 🏗️  (1.25s)

Then the test runs:

Started the wrapper-transaction in "mysql" database "db_461b27_fba25141c217" (0ms)
The test will run now
Rolled back the wrapper-transaction in "mysql" database "db_461b27_fba25141c217" (1ms)

The next time this database is needed for a test, it can be reused. The preparation section will look different when this happens:

Changed the database for connection "mysql" to "db_461b27_fba25141c217"
The existing database "db_461b27_fba25141c217" can be reused (1ms)
Refreshed the re-use meta-data (0ms)
Reusing database "db_461b27_fba25141c217" - total preparation time 😎 (2ms)

When a database can't be reused, Adapt will re-build it:

Changed the database for connection "mysql" to "db_461b27_fba25141c217"  
Database "db_461b27_fba25141c217" cannot be reused (1ms)  
(Reason: the wrapper-transaction was committed or rolled-back)  
Dropped the existing database (17ms)  
Created a new database (1ms)  
Set up the re-use meta-data (5ms)  
Ran migrations (369ms)  
Ran seeder "\Database\Seeders\DatabaseSeeder" (868ms)  
Rebuilt database "db_461b27_fba25141c217" - total preparation time 🏗️  (1.28s)

NOTE

Adapt's logs will look muddled when tests are run in parallel. This is because the different processes try to log their details at the same time.

Exception Logs

To help give you an idea of what happened when something went wrong, exceptions are logged as well:

┌── An Exception Occurred - AdaptBuildException ──────────────────────────────────────────┐
│ Failed to create mysql database "db_461b27_fba25141c217"                                │
│                                                                                         │
│ Previous Exception - PDOException                                                       │
│ SQLSTATE[HY000] [1045] Access denied for user 'root'@'172.26.0.8' (using password: YES) │
└─────────────────────────────────────────────────────────────────────────────────────────┘