PHPUnit测试中Container的Symfony内存问题

时间:2019-07-12 12:45:59

标签: php phpunit php-7.2 symfony-4.3

我有以下测试。这导致PHP Fatal error: Out of memory (allocated 704905216) (tried to allocate 139802474386369 bytes)错误

这里$this->client->getContainer()可能是引起此问题的原因。但是我不怎么写其他方式。如何解决此内存问题?

public function testIndexWithCreateUser()
    {
        $printMock = $this->createMock(InternPrintApi::class);
        $printMock->expects($this->once())
            ->method('createUser')
            ->willReturn(json_decode('{"user":{"account":{"email":"test.user@example.com"}}}'));

        $this->client->getContainer()->set(InternPrintApi::class, $printMock);

        $this->client->request('POST', '/registration', [
            'registration' => [
                'email' => 'test.user@example.com',
                'password' => 'password'
            ]
        ]);

        $this->assertEquals(302, $this->client->getResponse()->getStatusCode());
    }

0 个答案:

没有答案