@freekmurze First of all, there's a good practice of never calling anything further, than a method on your peer (Client as dependency in this case):
// wrong - what happens if indices() return value changes on the Client?
public function clearIndex()
{
$this->elasticsearch->indices()->delete(['index' => $this->indexName]);
}
// right - you don't care about indices return value anymore, jut use Client's API
public function clearIndex()
{
$this->elasticsearch->deleteIndices(['index' => $this->indexName]);
}
// example piece from the Client class
public function deleteIndices(array $indices)
{
// the same might be the case here, unless indices() is some internal method
$this->indices()->delete($indices);
}
Next, you are not testing anything there:
$elasticsearch->indices()->delete(['index' => $this->indexName]);
$this->clearIndex();
it's just calling the same methods. You likely want to test, that your method calls some other method available in the peer's (dependency) API:
protected $indexName = 'indexName'; // don't use __construct() for this, define it or use the setter
function it_can_clear_the_index(Client $elasticsearch)
{
// expectation - I want it to happen
$elasticsearch->deleteIndices(['index' => 'indexName'])->shouldBeCalled();
// action - when I'm doing this
$this->clearIndex();
}