mailerlite / laravel-elasticsearch

An easy way to use the official Elastic Search client in your Laravel applications.
MIT License
909 stars 187 forks source link

Class 'Elasticsearch' not found from test classes #91

Closed wellbornman closed 3 years ago

wellbornman commented 3 years ago

I used "Elasticsearch" with static method "search", (Elasticsearch::search()) in my model and used my model's methods many times in my controller, and everything works fine, Model\Example.php

use Elasticsearch;
class Example {
     public static function example(){
            $params = ...;
            $result = Elasticsearch::search($params);
            ...
     }
}

Controller\ExampleController.php

use Model\Example;
class ExampleController extends Controller {
     public function example(){
            $result = Example::example();
            ...
     }
}

but when I use same code I wrote in my controller in my test classes, I encounter this error: Error: Class 'Elasticsearch' not found,

use Model\Example;
class ExampleTest extends TestCase
{
    public function testBasicTest()
    {
        $response = Example::example();
        ...
    }
}

whats is the problem?

nsaliu commented 3 years ago

Hi @wellbornman , which class are you extending in your test class?

I see TestCase, but in which namespace this class are?

cviebrock commented 3 years ago

Closing due to no response. Feel free to re-open or comment if you are still having issues.

wellbornman commented 3 years ago
namespace Tests;
use App\User;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase{
.....
}
nsaliu commented 3 years ago

@wellbornman can you try to extend Cviebrock\LaravelElasticsearch\Tests\TestCase in your test class instead Illuminate\Foundation\Testing\TestCase as BaseTestCase