简体   繁体   English

找不到Symfony / PHPUnitClass'PHPUnit_Framework_TestCase'

[英]Symfony/PHPUnitClass 'PHPUnit_Framework_TestCase' not found

I created a very simple basic api with the api-platform framework. 我使用api平台框架创建了一个非常简单的基本api。 Now I am trying to write a simple unit test with PHP unit but when I try to run the test I keep getting this error: 现在,我试图用PHP单元编写一个简单的单元测试,但是当我尝试运行测试时,却不断出现此错误:

Class 'PHPUnit_Framework_TestCase' not found

It is complaining about this line: 它在抱怨这一行:

class JobControllerTest extends \\PHPUnit_Framework_TestCase

It says undefined class 它说undefined class

I installed phpunit with composer I have no idea what I'm doing wrong. 我用作曲家安装了phpunit我不知道我在做什么错。

Here is my full test: 这是我的完整测试:

<?php
namespace tests\AppBundle;

class JobControllerTest extends \PHPUnit_Framework_TestCase
{
    public function testPOST()
    {
        $client = new Client('http://localhost:8000', array(
            'request.options' => array(
                'exceptions' => false,
            )
        ));

        $data = array(
            'bar' => "hello",
        );

        $request = $client->post('/foos', null, json_encode($data));
        $response = $request->send();

        $this->assertEquals(201, $response->getStatusCode());
        $this->assertTrue($response->hasHeader('Location'));
        $data = json_decode($response->getBody(true), true);
        $this->assertArrayHasKey('bar', $data);
    }
}

If anyone could help me any bit that would be pretty cool :) 如果有人可以帮助我,那将非常酷:)

Many thanks in advance! 提前谢谢了!

This is because on phpunit6 has been deprecated, use the following: 这是因为phpunit6已被弃用,请使用以下命令:

use PHPUnit\Framework\TestCase;

class UserControllerTest extends TestCase

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM