2016-06-30 15 views
0

私はサービスを呼び出す必要がある単体テストを持っています。Symfony、PHPでのコールサービスユニット

私はそれをそのようにやった:

<?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); 
    } 
} 

をしかし、私はこのエラーを持っている:

There was 1 error:

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

+0

サービスにエラーがあるようです...どこに接続しようとしていますか? –

+1

テスト環境のサービスパラメータ設定を確認する – Matteo

答えて

0

私はあなたがあなたのアプリケーションでのRedisを使うと思います。

しかし、私はなぜこのようなテストを実装したいのですか?

このテストでは文字通り固定データが使用され、依存関係(redis)を使用する外部サービスから結果を取得しようとします。

私は、PriceServiceの単体テストと、「fm.price.get」として登録されたserivceのもう1つのテストと、redisを使用する3番目のテストが必要だとしますが、この場合はキャッシュをいくつかのサンプルデータ。

関連する問題