mercredi 22 janvier 2020

Symfony 4 - PHPUnit - Difficults with the setUp() method

I'm following the Symfony Cast Stripe formation. They use Symfony 3 and I use Symfony 4.

I try to make some test like in the formation : https://symfonycasts.com/screencast/stripe-level2/testing-webhooks#play

But when I run the test, I've this error :

Fatal error: Cannot redeclare static Symfony\Bundle\FrameworkBundle\Test\WebTestCase::$container as non static App\Tests\Controller\WebhookControllerTest::$container in C:\Users\user\Desktop\StripeFormation2\tests\Controller\WebhookControllerTest.php on line 11

I made this :

<?php
namespace App\Tests\Controller;

use DateTime;
use App\Entity\User;
use App\Entity\Subscription;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;

class WebhookControllerTest extends WebTestCase
{
    /** @var EntityManagerInterface */
    private $em;
    private $container;

    public function setUp()
    {
        self::bootKernel();
        $this->container = self::$kernel->getContainer();
        $this->em = $this->container->get('doctrine')->getManager();
    }
    // ...

Can someone help me please ?

Aucun commentaire:

Enregistrer un commentaire