jeudi 30 juin 2016

Symfony, Call service in PHP Unit

I have a unit test, where I need to call a service.

I did it that way:

<?php
namespace FM\PriceBundle\Tests\Service;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class PriceServiceTest extends KernelTestCase
{
    private $container;

    public function testFiulPrice()
    {
        self::bootKernel();
        $this->container = self::$kernel->getContainer();

        $productId = 1;
        $id = 1;
        $what = ['postal', 'departement', 'region', 'country', 'insee'];
        $date = new \DateTime('2016-06-23');

        $price = $this->container->get('fm.price.get')->fiulPrice($productId, $id, $what[0], $date);

        $this->assertNotEmpty($price);
    }
}

But I have this error:

There was 1 error:

1) FM\PriceBundle\Tests\Service\PriceServiceTest::testFiulPrice Predis\Connection\ConnectionException: Connection refused [tcp://localhost:6379]

Aucun commentaire:

Enregistrer un commentaire