outofcontrol,
@outofcontrol@phpc.social avatar

TIL that although it’s been around for at least 5 versions of , we can do this:

if (App::runningUnitTests()) {  
 // Code to include in only tests  
}

if (!App::runningUnitTests()) {  
 // Code to exclude in tests  
}

when running tests. Works in as well, of course.

thomastospace,
@thomastospace@phpc.social avatar

@outofcontrol We need a tag or something for these things.

If you exclude certain code from tests, you're not testing anymore. I'm shocked this is even in a framework.

outofcontrol,
@outofcontrol@phpc.social avatar

@thomastospace Our use case is fairly valid, unless I am missing something super obvious. We have MySQL full text search via Scout, which has a migration for the full text table. Tests using sqlite choke on this. If I am not mistaken, there is little need to be testing a package from someone else, as in theory, the package maintainer has already done testing before releasing.

thomastospace,
@thomastospace@phpc.social avatar

@outofcontrol I expect it to work like this:

You have a service that uses something provided by Laravel Scout that can do the full-text search. You inject this in the constructor.

In your test, instead of injecting this service, make a mock of this service. Your class still thinks it's interacting with the class from Laravel Scout, but it's a fake object.

You then verify that your class sends the correct data to the mock service, and your mock service sends back a response to your class.

outofcontrol,
@outofcontrol@phpc.social avatar

@thomastospace Not sure I understand how this bypasses the full-text table migration generated by something like this https://github.com/ivanomatteo/laravel-scout-fulltext-engine

thomastospace,
@thomastospace@phpc.social avatar

@outofcontrol Could you show the code where you use the methods? Or is it private code?

outofcontrol,
@outofcontrol@phpc.social avatar

@thomastospace Strictly using it in the migration to ignore out the full text table generation.

thomastospace,
@thomastospace@phpc.social avatar

@outofcontrol Hmm, interesting. I don't use any unit testing on migrations. Guess that's what is causing the difference.

outofcontrol,
@outofcontrol@phpc.social avatar

@thomastospace When you run tests you don’t use the db at all?

thomastospace,
@thomastospace@phpc.social avatar

@outofcontrol For unittests, I don't. Those only test a single class.

Besides that, we have Application Tests, which cover the whole request flow, so those do touch the database.

Integration tests we currently don't have.

https://symfony.com/doc/current/testing.html#types-of-tests

outofcontrol,
@outofcontrol@phpc.social avatar

@thomastospace Fair point, I get confused with terminology sometimes. Which only adds to all the normal complexities in life :) The link to types of tests in sympfony is really great, thank you. From Laravel’s viewpoint, Feature tests are basically Integration tests if I read this correctly. This symfony makes the understanding of tests much more clear than anything else I’ve read or watched. Clear definitions really help.

outofcontrol,
@outofcontrol@phpc.social avatar

@thomastospace and… AFAIK App::runningUnitTests works for all tests, not just Unit tests. Happy to be corrected on this as I am learning a lot from our conversation.

thomastospace,
@thomastospace@phpc.social avatar

@outofcontrol These conversations are always fun and educational!

Still afraid of seeing App::runningUnitTests in code ever though 😅

outofcontrol,
@outofcontrol@phpc.social avatar

@thomastospace I do agree with the fear. And given time I am certain I will find a much better way to manage the issue at hand. I find I spend a considerable amount of time going back and rewriting my code to make it better. Tests are responsible for that. :)

  • All
  • Subscribed
  • Moderated
  • Favorites
  • Laravel
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • megavids
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • provamag3
  • JUstTest
  • All magazines