Tuesday, May 23, 2017

Memory exhaused in Laravel unit tests

I wrote unit tests for my controller. My class is

class ApiControllerTest extends TestCase

and it contains test methods like this

public function testAgeDistribution()
    {
        $response = $this->action(...,
            ['datasetName'=>'AgeDistribution',
              'min_longitude'=>-80.60, 'max_longitude'=>-78.60,
                'min_latitude'=>43.20, 'max_latitude'=>44,
                'zoom'=>12
                ]);



        $this->assertResponseOk();

        $json = json_decode($response->content());

        $this->checkMainThings($json, 'AgeDistribution', 'Population', 7, 100, 7);
    }

All methods are similar but with different parameters and checks.

In the beginning of handler function I have a row

$start_memory = memory_get_usage();

And I see (in debugger) that each new test it has more and more memory used.

In other words, memory is not freed between tests.

How to free memory in PHP or what potential error I have in tested methods?



via Dims

Advertisement