降低Laravel的单元测试内存使用率

I have an application written in PHP using the Laravel framework.

And I have a test suite consisting of approximately 200 phpUnit test methods.

The problem I have is that this test suite is taking a painfully long time to run (~10 mins), and has also now started running out of memory on our test server.

I could adjust the max memory in php.ini to solve the latter issue, but that's not really the point: I shouldn't have to -- I don't want to have to allocate 500mb or a gig to a single PHP process. (because, you know, the server might need to do other stuff at the same time)

I've done some investigation, and it seems like the main reason that it's so slow and uses so much RAM is because it sets up a whole new Laravel environment for every test.

That's understandable, but I'm looking for ways to cut it down - either the memory usage or the time taken, or better yet both.

Can anyone suggest ways of streamlining my code or my tests that will help with this?

Thank you.

Are all of your tests functional, or some of them are unit? If you're unit testing your classes, you don't need to initialize Laravel environment at all, just get an instance of the class involved and set the dependencies.

Check the "Am I Writing Unit Or Functional Tests?" section of the tutorial on writing Laravel controller tests:

https://medium.com/laravel-4/laravel-4-controller-testing-48414f4782d0

So you can extend the Laravel test class when you need the Laravel services, but if you're testing libraries, you can use plain PHPUnit tests.