0

I created a very simple basic api with the api-platform framework. 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:

Class 'PHPUnit_Framework_TestCase' not found

It is complaining about this line:

class JobControllerTest extends \PHPUnit_Framework_TestCase

It says undefined class

I installed phpunit with composer I have no idea what I'm doing wrong.

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!

5
  • It is because you have phpunit v6 installed. Install v5 or v4 and you should be good to go. There is actually quite a bit of discussion on this. Commented Feb 21, 2017 at 19:56
  • @Cerad I saw it on GitHub :) Thanks for letting me know though! Commented Feb 21, 2017 at 20:02
  • @Cerad Do you perhaps know why the $client = new Client( doesn't work? I did a composer require guzzlehttp/guzzle but doesn't seem to be working :p Commented Feb 21, 2017 at 20:03
  • Have you looked at the chapter on testing? Client is a HttpFoundation class, not the guzzle class. Commented Feb 21, 2017 at 22:44
  • You can try to use the approach from the stackoverflow.com/questions/42811164/… answer to be prepared for PHPUnit 6 as well as for earlier versions. Commented Jun 15, 2017 at 16:23

1 Answer 1

0

This is because on phpunit6 has been deprecated, use the following:

use PHPUnit\Framework\TestCase;

class UserControllerTest extends TestCase
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.