Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read host and port information from solr instance, not Pantheon env variables #411

Closed
wants to merge 10 commits into from
12 changes: 10 additions & 2 deletions includes/class-solrpower-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,21 @@ function check_for_schema() {
* @return array Array of server connection information.
*/
public function get_server_info() {
if ( ! $this->solr ) {
$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;
}

$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(),
);

Expand Down
40 changes: 40 additions & 0 deletions tests/phpunit/test-solrpower-api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

class SolrPowerAPITest extends SolrTestBase {

function setUp() {
parent::setUp();
}

function tearDown() {
parent::tearDown();
}


function test_server_info_uses_actual_config() {
$env_host = getenv('PANTHEON_INDEX_HOST');
$env_port = getenv('PANTHEON_INDEX_PORT');
$override_host = $env_host . 'OVERRIDE';
$override_port = $env_host . 'OVERRIDE';

$override_connection = function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pavellishin I don't think $override_host is defined in the context of this function. Maybe pass it in as a parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, dangit. I forget how modern PHP works wrt scoping.

return array(
'endpoint' => 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 );
}
}