Browse Source

introduce test bootstrapping

Tim MacDonald 5 years ago
parent
commit
56960ed2a0
2 changed files with 37 additions and 1 deletions
  1. 6 1
      phpunit.xml
  2. 31 0
      tests/bootstrap.php

+ 6 - 1
phpunit.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <phpunit backupGlobals="false"
          backupStaticAttributes="false"
-         bootstrap="vendor/autoload.php"
+         bootstrap="tests/bootstrap.php"
          colors="true"
          convertErrorsToExceptions="true"
          convertNoticesToExceptions="true"
@@ -29,5 +29,10 @@
         <server name="MAIL_DRIVER" value="array"/>
         <server name="QUEUE_CONNECTION" value="sync"/>
         <server name="SESSION_DRIVER" value="array"/>
+        <server name="APP_CONFIG_CACHE" value="bootstrap/cache/config.phpunit.php"/>
+        <server name="APP_SERVICES_CACHE" value="bootstrap/cache/services.phpunit.php"/>
+        <server name="APP_PACKAGES_CACHE" value="bootstrap/cache/packages.phpunit.php"/>
+        <server name="APP_ROUTES_CACHE" value="bootstrap/cache/routes.phpunit.php"/>
+        <server name="APP_EVENTS_CACHE" value="bootstrap/cache/events.phpunit.php"/>
     </php>
 </phpunit>

+ 31 - 0
tests/bootstrap.php

@@ -0,0 +1,31 @@
+<?php
+
+use Illuminate\Contracts\Console\Kernel;
+
+require_once __DIR__.'/../vendor/autoload.php';
+
+/*
+|--------------------------------------------------------------------------
+| Bootstrap the testing environment
+|--------------------------------------------------------------------------
+|
+| You have the option to specify console commands that will execute before your
+| test suite is run. Caching config, routes, & events may improve performance
+| and bring your testing environment closer to production.
+|
+*/
+
+$commands = [
+    'config:cache',
+    'event:cache',
+    // 'route:cache',
+];
+
+$app = require __DIR__.'/../bootstrap/app.php';
+
+$console = tap($app->make(Kernel::class))->bootstrap();
+
+foreach ($commands as $command) {
+    $console->call($command);
+}
+