Coder Social home page Coder Social logo

Comments (18)

c5n8 avatar c5n8 commented on May 10, 2024 8

Try add this to your .env file just like what works in phpunit.xml file

SCOUT_DRIVER='"null"'

This way we don't have to 'hack' the scout config file

from scout.

pactode avatar pactode commented on May 10, 2024 4

@calebporzio You have to use double quotes on the SCOUT_DRIVER null value. Like this:
<env name="SCOUT_DRIVER" value='"null"'/>

from scout.

monsterdream avatar monsterdream commented on May 10, 2024 3

Hello, I found a solution. You need to setup it in reversed way. Instead in your .env file put

SCOUT_DRIVER=null 

and in config/Scout.php

'driver' => env('SCOUT_DRIVER', 'algolia')

Put in .env

SCOUT_DRIVER=algolia

and in config/Scout.php

'driver' => env('SCOUT_DRIVER', 'null')

Of course then you can just remove it from local environment and it will means that it will use null.

from scout.

mattstauffer avatar mattstauffer commented on May 10, 2024 3

This is no longer an issue; works fine after this:

#224

from scout.

harrygr avatar harrygr commented on May 10, 2024 1

How would one do that in a phpunit.xml file where the values are already between quotes?

<env name="SCOUT_DRIVER" value="null" />

Presumably I could use single quotes to wrap it but I haven't yet tested if it works:

<env name="SCOUT_DRIVER" value='"null"' />

from scout.

dwightwatson avatar dwightwatson commented on May 10, 2024 1

Using double quotes on the environment variable doesn't work. I've been trying to do this to disable Laravel Scout in my test environment. Dotenv must take the string "null" to become null as well.

SCOUT_DRIVER="null"
>>> env('SCOUT_DRIVER');
=> null

My solution in the meantime has been to set the default driver to "null" in the config/scout.php file and then set it to "algolia" through an environment variable in production, but clearly this isn't great.

I suspect this issue will also affect the "null" Broadcast driver.

from scout.

morloderex avatar morloderex commented on May 10, 2024

Use double qoutes on the enviroment variable.

from scout.

talvbansal avatar talvbansal commented on May 10, 2024

@dwightwatson I've managed to set my driver to null using your method as well as the <env name="SCOUT_DRIVER" value='"null"' /> method too.

However my unit tests are DIRE slow after this:

25seconds -> 7mins

Are slow unit tests something you're seeing too?

It may well be because I'm using the TntSearch driver however I wanted to see if this is a scout issue or their implementation issue. Although using their native implementation not the scout wrapper has no impact on testing speed.

from scout.

harrygr avatar harrygr commented on May 10, 2024

@dwightwatson that's an OK suggestion but there's a problem when, for development, you have it set to "algolia" in your .env phpunit will fall back on that value if no value is set in phpunit.xml. Basically it means that if you have your local driver set to algolia there's no easy way to override that for tests. Will be a fine solution for CI though where you can just omit the driver env variable completely.

from scout.

thebrubaker avatar thebrubaker commented on May 10, 2024

I agree,it would be good to change this "null" option to "none" or "disable" or some equivalent that won't confuse .env to typecasting null from a string to a null value.

from scout.

talvbansal avatar talvbansal commented on May 10, 2024

We've found a way around this that disables the auto indexing by default during unit tests, when we get around to writing the searching unit tests we can re enable it for those particular tests.

I think we can close this issue now?

from scout.

dwightwatson avatar dwightwatson commented on May 10, 2024

You've found a solution using the PHPUnit configuration file, but this is still an issue with Scout configuration in general. I don't think this issue should be closed, and I think another option name should be chosen (or, support literal null as being the "null" driver).

from scout.

talvbansal avatar talvbansal commented on May 10, 2024

Ahh totally sorry I thought I was responding to an issue on a different repo RE the scout implementation within that project sorry ignore my post above

from scout.

edcs avatar edcs commented on May 10, 2024

I've had the same problem in my projects too - 'null' is a silly name to use for anything that goes through .env since Laravel turns it into a null. My workaround to get it to work nicely with PHPUnit is this (will only work on PHP 7.0 and above though):

phpunit.xml

<env name="SCOUT_DRIVER" value="null"/>

config/scout.php

'driver' => env('SCOUT_DRIVER') ?? 'null',

I was considering doing a PR to fix this problem by renaming the 'null' driver to something else. Wondering if it's worth my time though as I don't want to spend a bunch of time on it for to be rejected.

from scout.

harrygr avatar harrygr commented on May 10, 2024

@edcs Your workaround is basically the same as the others suggest. Passing a 2nd argument into env() has the same effect.

This workaround fails however in the case where your local .env file has the driver set to something else (e.g. alogolia). Then, simply omitting SCOUT_DRIVER from phpunit.xml will not mean your tests will use the 'null' driver as laravel will fall back on the .env file and try to use algolia. This means that when you run your tests locally you'll be using the driver you set for development work.

It should be fine for CI though where you tend not to set the SCOUT_DRIVER at all.

from scout.

calebporzio avatar calebporzio commented on May 10, 2024

Any solution here? It seems crazy that this hasn't been resolved...

from scout.

calebporzio avatar calebporzio commented on May 10, 2024

Thanks I think I just removed the reference to it and it defaults to null. Still not happy with the proposed solutions, but Oh well - thanks for the tip!

from scout.

browner12 avatar browner12 commented on May 10, 2024

documentation for the lazy:

https://laravel.com/docs/5.6/configuration#environment-variable-types

from scout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.