Commit 97ec474d authored by Bas de Nooijer's avatar Bas de Nooijer

Added endpoint __toString support

parent 4b1017f6
...@@ -258,4 +258,26 @@ class Endpoint extends Configurable ...@@ -258,4 +258,26 @@ class Endpoint extends Configurable
'password' => $this->getOption('password'), 'password' => $this->getOption('password'),
); );
} }
/**
* Magic method enables a object to be transformed to a string
*
* Get a summary showing significant variables in the object
* note: uri resource is decoded for readability
*
* @return string
*/
public function __toString()
{
$output = __CLASS__ . '::__toString' . "\n"
. 'base uri: ' . $this->getBaseUri() . "\n"
. 'host: ' . $this->getHost() . "\n"
. 'port: ' . $this->getPort() ."\n"
. 'path: ' . $this->getPath() ."\n"
. 'core: ' . $this->getCore() . "\n"
. 'timeout: ' . $this->getTimeout() . "\n"
. 'authentication: ' . print_r($this->getAuthentication(), 1);
return $output;
}
} }
...@@ -127,4 +127,35 @@ class EndpointTest extends \PHPUnit_Framework_TestCase ...@@ -127,4 +127,35 @@ class EndpointTest extends \PHPUnit_Framework_TestCase
$this->endpoint->getAuthentication() $this->endpoint->getAuthentication()
); );
} }
public function testToString()
{
$options = array(
'host' => '192.168.0.1',
'port' => 123,
'path' => '/mysolr/',
'core' => 'mycore',
'timeout' => 3,
'username' => 'x',
'password' => 'y'
);
$this->endpoint->setOptions($options);
$this->assertEquals(
'Solarium\Core\Client\Endpoint::__toString
base uri: http://192.168.0.1:123/mysolr/mycore/
host: 192.168.0.1
port: 123
path: /mysolr
core: mycore
timeout: 3
authentication: Array
(
[username] => x
[password] => y
)
',
(string) $this->endpoint
);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment