From 71711d40632b871ea31f47c5aca03fe15256703d Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Mon, 5 Feb 2018 08:23:39 -0500
Subject: [PATCH] Modernize search specs reader service. - Use fully qualified
 class name as service name. - Eliminate static factory.

---
 module/VuFind/config/module.config.php             |  3 ++-
 .../Search/Factory/AbstractSolrBackendFactory.php  |  2 +-
 module/VuFind/src/VuFind/Service/Factory.php       | 14 --------------
 module/VuFind/src/VuFindTest/Unit/TestCase.php     |  3 ++-
 .../VuFindTest/Config/SearchSpecsReaderTest.php    |  4 ++--
 5 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php
index a161bb26b1f..1f7a48b44e6 100644
--- a/module/VuFind/config/module.config.php
+++ b/module/VuFind/config/module.config.php
@@ -290,6 +290,7 @@ $config = [
             'VuFind\ChannelProvider\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
             'VuFind\Config\AccountCapabilities' => 'VuFind\Config\AccountCapabilitiesFactory',
             'VuFind\Config\PluginManager' => 'VuFind\Config\PluginManagerFactory',
+            'VuFind\Config\SearchSpecsReader' => 'VuFind\Config\YamlReaderFactory',
             'VuFind\Config\YamlReader' => 'VuFind\Config\YamlReaderFactory',
             'VuFind\Content\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
             'VuFind\Content\AuthorNotes\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
@@ -337,7 +338,6 @@ $config = [
             'VuFind\Search\Results\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
             'VuFind\Search\Solr\HierarchicalFacetHelper' => 'Zend\ServiceManager\Factory\InvokableFactory',
             'VuFind\Search\SearchRunner' => 'VuFind\Search\SearchRunnerFactory',
-            'VuFind\SearchSpecsReader' => 'VuFind\Service\Factory::getSearchSpecsReader',
             'VuFind\SearchTabsHelper' => 'VuFind\Service\Factory::getSearchTabsHelper',
             'VuFind\Service\ReCaptcha' => 'VuFind\Service\ReCaptchaFactory',
             'VuFind\Session\Settings' => 'Zend\ServiceManager\Factory\InvokableFactory',
@@ -409,6 +409,7 @@ $config = [
             'VuFind\SearchParamsPluginManager' => 'VuFind\Search\Params\PluginManager',
             'VuFind\SearchResultsPluginManager' => 'VuFind\Search\Results\PluginManager',
             'VuFind\SearchRunner' => 'VuFind\Search\SearchRunner',
+            'VuFind\SearchSpecsReader' => 'VuFind\Config\SearchSpecsReader',
             'VuFind\YamlReader' => 'VuFind\Config\YamlReader',
         ],
     ],
diff --git a/module/VuFind/src/VuFind/Search/Factory/AbstractSolrBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/AbstractSolrBackendFactory.php
index e505a67ddc1..cfd22c3835a 100644
--- a/module/VuFind/src/VuFind/Search/Factory/AbstractSolrBackendFactory.php
+++ b/module/VuFind/src/VuFind/Search/Factory/AbstractSolrBackendFactory.php
@@ -399,7 +399,7 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface
      */
     protected function loadSpecs()
     {
-        return $this->serviceLocator->get('VuFind\SearchSpecsReader')
+        return $this->serviceLocator->get('VuFind\Config\SearchSpecsReader')
             ->get($this->searchYaml);
     }
 
diff --git a/module/VuFind/src/VuFind/Service/Factory.php b/module/VuFind/src/VuFind/Service/Factory.php
index c8903c701de..d7e2e345c0b 100644
--- a/module/VuFind/src/VuFind/Service/Factory.php
+++ b/module/VuFind/src/VuFind/Service/Factory.php
@@ -130,20 +130,6 @@ class Factory
         );
     }
 
-    /**
-     * Construct the search specs reader.
-     *
-     * @param ServiceManager $sm Service manager.
-     *
-     * @return \VuFind\Config\SearchSpecsReader
-     */
-    public static function getSearchSpecsReader(ServiceManager $sm)
-    {
-        return new \VuFind\Config\SearchSpecsReader(
-            $sm->get('VuFind\Cache\Manager')
-        );
-    }
-
     /**
      * Construct the SearchTabs helper.
      *
diff --git a/module/VuFind/src/VuFindTest/Unit/TestCase.php b/module/VuFind/src/VuFindTest/Unit/TestCase.php
index 1099e3cce19..439dac727b7 100644
--- a/module/VuFind/src/VuFindTest/Unit/TestCase.php
+++ b/module/VuFind/src/VuFindTest/Unit/TestCase.php
@@ -182,7 +182,8 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
                 'VuFind\RecordDriver\PluginManager', $recordDriverFactory
             );
             $this->serviceManager->setService(
-                'VuFind\SearchSpecsReader', new \VuFind\Config\SearchSpecsReader()
+                'VuFind\Config\SearchSpecsReader',
+                new \VuFind\Config\SearchSpecsReader()
             );
             $this->serviceManager->setService(
                 'VuFind\Log\Logger', $this->createMock('VuFind\Log\Logger')
diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Config/SearchSpecsReaderTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Config/SearchSpecsReaderTest.php
index a4b5162fc3b..3f9bf92c819 100644
--- a/module/VuFind/tests/unit-tests/src/VuFindTest/Config/SearchSpecsReaderTest.php
+++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Config/SearchSpecsReaderTest.php
@@ -94,7 +94,7 @@ class SearchSpecsReaderTest extends \VuFindTest\Unit\TestCase
     {
         // The searchspecs.yaml file should define author dismax fields (among many
         // other things).
-        $reader = $this->getServiceManager()->get('VuFind\SearchSpecsReader');
+        $reader = $this->getServiceManager()->get('VuFind\Config\SearchSpecsReader');
         $specs = $reader->get('searchspecs.yaml');
         $this->assertTrue(
             isset($specs['Author']['DismaxFields'])
@@ -109,7 +109,7 @@ class SearchSpecsReaderTest extends \VuFindTest\Unit\TestCase
      */
     public function testMissingFileRead()
     {
-        $reader = $this->getServiceManager()->get('VuFind\SearchSpecsReader');
+        $reader = $this->getServiceManager()->get('VuFind\Config\SearchSpecsReader');
         $specs = $reader->get('notreallyasearchspecs.yaml');
         $this->assertEquals([], $specs);
     }
-- 
GitLab