dimanche 29 septembre 2019

Sime test on twig render method with PHPUnit

I write a little test (dead simple) and it didn't work. I have no idea why ? Here is the test:

<?php

namespace App\Tests\Mailer;

use PHPUnit\Framework\TestCase;
use Twig\Environment;

class MailerTest extends TestCase
{
    public function testConfirmationEmail()
    {
        $twigMock = $this->getMockBuilder(Environment::class)
            ->disableOriginalConstructor()
            ->getMock()
        ;
        $twigMock->expects($this->once())->method('render');
    }
}

I mock the Twig\Environment class and I test if the method render run only once. Nothing really fancy here. Here is my result:

1) App\Tests\Mailer\MailerTest::testConfirmationEmail Expectation failed for method name is equal to 'render' when invoked 1 time(s). Method was expected to be called 1 times, actually called 0 times.

I don't understand why It didn't work. My test should run the render method only once, but it called 0 times. I tested it with PHPUnit 6.5.14 on Symfony 4.3.2.

Thanks everyone

Aucun commentaire:

Enregistrer un commentaire