Switching to the test database connection only happens when
_drupal_bootstrap_database() runs before executing a first query.
To avoid complicating the boostrap with more fine grained level booting, just
boot the DrupalKernel after DRUPAL_BOOTSTRAP_CODE. Getting rid of those levels
is for a seperate issue.
Additionally mirror the changes in the testing files
core/modules/system/tests/http.php and https.php.