api4 - Fix container cache/reload behavior
authorTim Otten <totten@civicrm.org>
Sun, 15 Sep 2019 18:19:06 +0000 (14:19 -0400)
committerColeman Watts <coleman@civicrm.org>
Tue, 17 Sep 2019 03:11:24 +0000 (23:11 -0400)
In the extension's `tests/phpunit/bootstrap.php`, it forced the container to
*never* use caching. I suspect this was because of two problems:

1. APIv4 does a directory scan for services, but it didn't inform
   the container that this directory was important.

2. APIv4 registers additional services for a test environment, but the
   caching system didn't allow different caches for live-vs-test env's.

CRM/Api4/Services.php
CRM/Core/Config/Runtime.php

index a615f1a0e27c7f0863dcc006bbbd54a64a0185cd..31c8f082774377be3ef245c62fe66f815c9090e1 100644 (file)
@@ -62,6 +62,7 @@ class CRM_Api4_Services {
     );
     foreach ($locations as $location) {
       $path = \CRM_Utils_File::addTrailingSlash(dirname($location)) . str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
+      $container->addResource(new \Symfony\Component\Config\Resource\DirectoryResource($path, ';\.php$;'));
       foreach (glob("$path*.php") as $file) {
         $matches = [];
         preg_match('/(\w*).php/', $file, $matches);
index d64c5ce5f94319ca6f4e3080c5fc0017ed67414e..da2abcec7b759fb6adc68a4b1424de4dfec42f63 100644 (file)
@@ -163,6 +163,8 @@ class CRM_Core_Config_Runtime extends CRM_Core_Config_MagicMerge {
         \CRM_Utils_Array::value('HTTP_HOST', $_SERVER, ''),
         // e.g. port-based vhosts
         \CRM_Utils_Array::value('SERVER_PORT', $_SERVER, ''),
+        // e.g. unit testing
+        defined('CIVICRM_TEST') ? 1 : 0,
         // Depending on deployment arch, these signals *could* be redundant, but who cares?
       ]));
     }