Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kenprogrammer's avatar

PHP Unit testing

I want to ensure user's card has enough balance before proceeding with checkout. Below is the test class:

    declare(strict_types=1);
    use PHPUnit\Framework\TestCase;

    class PaymentTest extends TestCase
    {
        /**
         * @dataProvider cardBalance
         */
        public function testAccountHasBalance($amount)
        {
            $this->assertGreaterThan(0,$amount);
        }

        /**
         * @depends testAccountHasBalance
         */
        public function testCheckout()
        {
            $this->assertTrue(true);
        }

        public function cardBalance()
        {
            return 100;
        }
    }

The two tests are being skipped and marked as incomplete or risky. What am missing?

0 likes
7 replies
automica's avatar
automica
Best Answer
Level 54

@kenprogrammer this one is risky as you are checking true = true

    public function testCheckout()
        {
            $this->assertTrue(true);
        }

Also your cardBalance dataProvider needs to return an associative array

   public function cardBalance()
        {
            return [
		[100]
		];
        }

see https://tighten.co/blog/tidying-up-your-phpunit-tests-with-data-providers/

I also like to add a descriptive key so you can easily see what item in your data provider you are testing eg


public function cardBalance()
{
    return [
        'card balance is 100' => [100]
    ];
}
kenprogrammer's avatar

@automica I've tried

$this->assertTrue(false);
$this->assertFalse(true);
```	
Still the two tests are being skipped. Never mind my naivety,just started learning testing.
automica's avatar

@kenprogrammer good stuff. how to write tests is a bit of an art but its worth getting to grips with as it'll give you much more confidence with refactoring.

my favourite phrase for this is 'your future self will thank you' :)

1 like

Please or to participate in this conversation.