cakephp/elastic-search

Call to undefined method Cake\Database\Connection::getIndex()

ddgreen opened this issue · 5 comments

version:2.0-RC1

I received this Exception message when I ran PHPUnit.

throw point:
$esIndex = $db->getIndex($this->getIndex()->getName());
TestFixture.php, line 129

what is class that this $db?
(I think Elastica\Index)

How is this problem solved?

  • Please use 2.0-RC2
  • Have you set up your connection correctly ? See here and confirmed that it is working?

Thank you.

I installed 2.0-RC2.
And, ElasticSearch correctly work except when I ran PHPUnit.

I think TestFixture class cause this problem.

My TestCase has app.articles and app.users fixture.

  • app.articles inherit Cake\ElasticSearch\TestSuite\TestFixture.
  • app.users inherit Cake\TestSuite\Fixture\TestFixture.

PHPUnit correctly work when I commented out app.articles.

Should I separete these TestFixture?

My app.php :

        'elastic' => [
            'className' => 'Cake\ElasticSearch\Datasource\Connection',
            'driver' => 'Cake\ElasticSearch\Datasource\Connection',
            'host' => '127.0.0.1',
            'port' => 9200,
        ],
        'test_elastic' => [
            'className' => 'Cake\ElasticSearch\Datasource\Connection',
            'driver' => 'Cake\ElasticSearch\Datasource\Connection',
            'host' => '127.0.0.1',
            'port' => 9200,
        ],

Have you defined the correct connection name in your articles fixture ?

class ArticlesFixture extends TestFixture
{
    /**
     * Table/Index name
     *
     * @var string
     */
    public $table = 'Articles';

    /*
     * Set the elastic connection
     *
     * @var string
     */
    public $connection = 'test_elastic';

public $connection = 'test_elastic';
PHPUnit correctly worked after I added this line!

Thank you, josbeir!