0

I am new to PHP and trying to write a basic test case that verifies a connection to a database. Clearly I'm missing something fundamental. I understand from reading the manual online that this involves extending the PHPUnit_Extensions_Database_TestCase and implementing a couple of functions (getConnection() and getDataSet()). Please see my code below of the simplest case I could come up with to still get the head-scratching issue I'm encountering:

<?php
abstract class DBTest extends PHPUnit_Extensions_Database_TestCase
{

    public function getConnection()
    {
        return true;
    }
    public function getDataSet()
    {

        return true;
    }
}
?>

As you can see, the tests do nothing but return true. However, when I do a "phpUnit DBTest" I get the following message back:

PHPUnit 4.2.6 by Sebastian Bergmann.

F

Time: 1 ms, Memory: 7.50Mb

There was 1 failure:

1) Warning
No tests found in class "DBTest".

FAILURES!
Tests: 1, Assertions: 0, Failures: 1.

What am I missing? Any advice would help. Thanks.

1
  • Not seeing any php code. Commented Sep 26, 2014 at 20:19

1 Answer 1

1

PHPUnit complains about not finding any test. You must add at least a test method:

<?php
abstract class DBTest extends PHPUnit_Extensions_Database_TestCase
{

    public function getConnection()
    {
        return true;
    }
    public function getDataSet()
    {
        return true;
    }

    public function testDummy()
    {
        $this->assertTrue(true);
    }
}
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Just to clarify, phpUnit will only recognize the test method as a test method if it is prefixed with the word "test" as shown by gontrollez's answer.

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.