From df91f41967e5519b8c61daab43c41b1c7f972ce6 Mon Sep 17 00:00:00 2001 From: Pavel Lishin Date: Thu, 30 May 2019 17:20:30 -0400 Subject: [PATCH 01/10] #408: Read host and port information from solr instance, not Pantheon env variables --- includes/class-solrpower-api.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/includes/class-solrpower-api.php b/includes/class-solrpower-api.php index ba4522bb..ebfc6080 100644 --- a/includes/class-solrpower-api.php +++ b/includes/class-solrpower-api.php @@ -573,13 +573,22 @@ function check_for_schema() { * @return array Array of server connection information. */ public function get_server_info() { + $solr = get_solr(); + if ( ! $solr ) { + $host = null; + $port = null; + } else { + $config = $solr->getOption('endpoint'); + $host = isset( $config['localhost']['host'] ) ? $config['localhost']['host'] : null; + $port = isset( $config['localhost']['port'] ) ? $config['localhost']['port'] : null; + } $ping = $this->ping_server(); return array( 'ping_status' => $ping, - 'ip_address' => getenv( 'PANTHEON_INDEX_HOST' ), - 'port' => getenv( 'PANTHEON_INDEX_PORT' ), + 'ip_address' => $host, + 'port' => $port, 'path' => $this->compute_path(), ); From 11845b2b3b3fd432804ecea1a71e6bc2373032d8 Mon Sep 17 00:00:00 2001 From: Pavel Lishin Date: Thu, 30 May 2019 17:55:29 -0400 Subject: [PATCH 02/10] #408: hm, at least one test (test_wp_query_failed_ping) seems to rely on get_solr not being called inside get_server_info? --- includes/class-solrpower-api.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/includes/class-solrpower-api.php b/includes/class-solrpower-api.php index ebfc6080..6c52d5f3 100644 --- a/includes/class-solrpower-api.php +++ b/includes/class-solrpower-api.php @@ -573,12 +573,11 @@ function check_for_schema() { * @return array Array of server connection information. */ public function get_server_info() { - $solr = get_solr(); - if ( ! $solr ) { + if ( ! $this->solr ) { $host = null; $port = null; } else { - $config = $solr->getOption('endpoint'); + $config = $this->solr->getOption('endpoint'); $host = isset( $config['localhost']['host'] ) ? $config['localhost']['host'] : null; $port = isset( $config['localhost']['port'] ) ? $config['localhost']['port'] : null; } From e1d020c0c1445cf1c9786f2d63b7d9e770034be4 Mon Sep 17 00:00:00 2001 From: Pavel Lishin Date: Thu, 30 May 2019 18:00:29 -0400 Subject: [PATCH 03/10] #408: formatting fixes --- includes/class-solrpower-api.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class-solrpower-api.php b/includes/class-solrpower-api.php index 6c52d5f3..90784d22 100644 --- a/includes/class-solrpower-api.php +++ b/includes/class-solrpower-api.php @@ -577,9 +577,9 @@ public function get_server_info() { $host = null; $port = null; } else { - $config = $this->solr->getOption('endpoint'); - $host = isset( $config['localhost']['host'] ) ? $config['localhost']['host'] : null; - $port = isset( $config['localhost']['port'] ) ? $config['localhost']['port'] : null; + $config = $this->solr->getOption( 'endpoint' ); + $host = isset( $config['localhost']['host'] ) ? $config['localhost']['host'] : null; + $port = isset( $config['localhost']['port'] ) ? $config['localhost']['port'] : null; } $ping = $this->ping_server(); From 917a58fcc0981033a4a6d5c829377043623d389b Mon Sep 17 00:00:00 2001 From: Pavel Lishin Date: Thu, 30 May 2019 18:13:53 -0400 Subject: [PATCH 04/10] #408: Adding test --- tests/phpunit/test-solrpower-api.php | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/phpunit/test-solrpower-api.php diff --git a/tests/phpunit/test-solrpower-api.php b/tests/phpunit/test-solrpower-api.php new file mode 100644 index 00000000..04be38e9 --- /dev/null +++ b/tests/phpunit/test-solrpower-api.php @@ -0,0 +1,40 @@ + array( + 'localhost' => array( + 'host' => $override_host, + 'port' => $override_port, + 'path' => '', + ) + ), + ); + }; + add_filter( 's4wp_connection_options', $override_connection ); + + $server_info = SolrPower_Api::get_instance()->get_server_info(); + + $this->assertEquals( $override_host, $server_info['ip_address'] ); + $this->assertEquals( $override_port, $server_info['port'] ); + + remove_filter( 's4wp_connection_options', $override_connection ); + } +} \ No newline at end of file From 6b971a4aa55fc23bdfc4bc455011ef3735402a82 Mon Sep 17 00:00:00 2001 From: Pavel Lishin Date: Fri, 31 May 2019 14:17:33 -0400 Subject: [PATCH 05/10] #408: Whoops, $_ENV not $ENV --- tests/phpunit/test-solrpower-api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/test-solrpower-api.php b/tests/phpunit/test-solrpower-api.php index 04be38e9..58ec6d9c 100644 --- a/tests/phpunit/test-solrpower-api.php +++ b/tests/phpunit/test-solrpower-api.php @@ -12,8 +12,8 @@ function tearDown() { function test_server_info_uses_actual_config() { - $env_host = $ENV['PANTHEON_INDEX_HOST']; - $env_port = $ENV['PANTHEON_INDEX_HOST']; + $env_host = $_ENV['PANTHEON_INDEX_HOST']; + $env_port = $_ENV['PANTHEON_INDEX_HOST']; $override_host = $env_host . 'OVERRIDE'; $override_port = $env_host . 'OVERRIDE'; From 5fb59ca2d948d6b6fbbaf075a5bfdf2a5db54b3b Mon Sep 17 00:00:00 2001 From: Pavel Lishin Date: Fri, 31 May 2019 15:35:54 -0400 Subject: [PATCH 06/10] #408: Check for env --- tests/phpunit/test-solrpower-api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/test-solrpower-api.php b/tests/phpunit/test-solrpower-api.php index 58ec6d9c..76b5eb6b 100644 --- a/tests/phpunit/test-solrpower-api.php +++ b/tests/phpunit/test-solrpower-api.php @@ -12,8 +12,8 @@ function tearDown() { function test_server_info_uses_actual_config() { - $env_host = $_ENV['PANTHEON_INDEX_HOST']; - $env_port = $_ENV['PANTHEON_INDEX_HOST']; + $env_host = isset($_ENV['PANTHEON_INDEX_HOST']) ? $_ENV['PANTHEON_INDEX_HOST'] : ''; + $env_port = isset($_ENV['PANTHEON_INDEX_PORT']) ? $_ENV['PANTHEON_INDEX_PORT'] : ''; $override_host = $env_host . 'OVERRIDE'; $override_port = $env_host . 'OVERRIDE'; From 539d07d2508cfd5828bc70eef611453e159ff87d Mon Sep 17 00:00:00 2001 From: Pavel Lishin Date: Mon, 3 Jun 2019 11:38:42 -0400 Subject: [PATCH 07/10] #408: Check for env with array_key_exists (why _doesn't_ it exist?) --- tests/phpunit/test-solrpower-api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/test-solrpower-api.php b/tests/phpunit/test-solrpower-api.php index 76b5eb6b..a122b4f0 100644 --- a/tests/phpunit/test-solrpower-api.php +++ b/tests/phpunit/test-solrpower-api.php @@ -12,8 +12,8 @@ function tearDown() { function test_server_info_uses_actual_config() { - $env_host = isset($_ENV['PANTHEON_INDEX_HOST']) ? $_ENV['PANTHEON_INDEX_HOST'] : ''; - $env_port = isset($_ENV['PANTHEON_INDEX_PORT']) ? $_ENV['PANTHEON_INDEX_PORT'] : ''; + $env_host = array_key_exists('PANTHEON_INDEX_HOST', $_ENV) ? $_ENV['PANTHEON_INDEX_HOST'] : ''; + $env_port = array_key_exists('PANTHEON_INDEX_PORT', $_ENV) ? $_ENV['PANTHEON_INDEX_PORT'] : ''; $override_host = $env_host . 'OVERRIDE'; $override_port = $env_host . 'OVERRIDE'; From 51e868b13844ce3d538fc5df7e2d9ccc11f3b185 Mon Sep 17 00:00:00 2001 From: Pavel Lishin Date: Mon, 3 Jun 2019 12:00:43 -0400 Subject: [PATCH 08/10] #408: use getenv --- tests/phpunit/test-solrpower-api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/test-solrpower-api.php b/tests/phpunit/test-solrpower-api.php index a122b4f0..463f0efa 100644 --- a/tests/phpunit/test-solrpower-api.php +++ b/tests/phpunit/test-solrpower-api.php @@ -12,8 +12,8 @@ function tearDown() { function test_server_info_uses_actual_config() { - $env_host = array_key_exists('PANTHEON_INDEX_HOST', $_ENV) ? $_ENV['PANTHEON_INDEX_HOST'] : ''; - $env_port = array_key_exists('PANTHEON_INDEX_PORT', $_ENV) ? $_ENV['PANTHEON_INDEX_PORT'] : ''; + $env_host = getenv('PANTHEON_INDEX_HOST'); + $env_port = getenv('PANTHEON_INDEX_PORT'); $override_host = $env_host . 'OVERRIDE'; $override_port = $env_host . 'OVERRIDE'; From 4c7b53e8df8311cc979d8ff7ec92465318213a64 Mon Sep 17 00:00:00 2001 From: Pavel Lishin Date: Mon, 17 Jun 2019 11:24:43 -0400 Subject: [PATCH 09/10] #408: making variables available in the override function --- tests/phpunit/test-solrpower-api.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/phpunit/test-solrpower-api.php b/tests/phpunit/test-solrpower-api.php index 463f0efa..636e2eba 100644 --- a/tests/phpunit/test-solrpower-api.php +++ b/tests/phpunit/test-solrpower-api.php @@ -18,6 +18,8 @@ function test_server_info_uses_actual_config() { $override_port = $env_host . 'OVERRIDE'; $override_connection = function() { + global $override_host, $override_port; + return array( 'endpoint' => array( 'localhost' => array( From cffa748c10c57dbd5aa95383725d6502b16646cd Mon Sep 17 00:00:00 2001 From: Pavel Lishin Date: Tue, 18 Jun 2019 11:32:57 -0400 Subject: [PATCH 10/10] #408: hm, is this empty string evaluating as falsy? --- tests/phpunit/test-solrpower-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/test-solrpower-api.php b/tests/phpunit/test-solrpower-api.php index 636e2eba..c7795fae 100644 --- a/tests/phpunit/test-solrpower-api.php +++ b/tests/phpunit/test-solrpower-api.php @@ -25,7 +25,7 @@ function test_server_info_uses_actual_config() { 'localhost' => array( 'host' => $override_host, 'port' => $override_port, - 'path' => '', + 'path' => '/some/path', ) ), );