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

Class 'Elasticsearch' not found from test classes #91

Closed
wellbornman opened this issue Sep 21, 2020 · 4 comments
Closed

Class 'Elasticsearch' not found from test classes #91

wellbornman opened this issue Sep 21, 2020 · 4 comments

Comments

@wellbornman
Copy link

wellbornman commented Sep 21, 2020

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
Copy link
Contributor

nsaliu commented Sep 29, 2020

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

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

@cviebrock
Copy link
Contributor

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

@wellbornman
Copy link
Author

wellbornman commented Jan 5, 2021

namespace Tests;
use App\User;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase{
.....
}

@nsaliu
Copy link
Contributor

nsaliu commented Jan 6, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants