2016-11-09 9 views
0

私のテストに問題があります。なぜ私の機能が定義されていないのかわかりません。私は使用statetmentを追加、phpstormはこのクラスを参照してください。しかし、未定義のテストエラーを実行するとき。symfony test undefined function

namespace tests\AppBundle\Parser; 

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; 
use AppBundle\Parser\CommissionDataParser; 

class CommissionDataParserTest extends WebTestCase 
{ 

    public function testGroupOrdersByWeek() 
    { 

     $orders = [ 
      0 => [ 
       'date' => '2016-01-10', 
       'client_id'  => '2', 
       'client_type'=> 'natural', 
       'operation_type' => 'cash_in', 
       'operation_sum'  => '200.00', 
       'operation_currency'  => 'EUR', 
      ], 

      1 => [ 
       'date' => '2016-01-05', 
       'client_id'  => '1', 
       'client_type'=> 'legal', 
       'operation_type' => 'cash_out', 
       'operation_sum'  => '300.00', 
       'operation_currency'  => 'EUR', 
      ], 

      2 => [ 

       'date' => '2016-01-11', 
       'client_id'  => '1', 
       'client_type'=> 'natural', 
       'operation_type' => 'cash_out', 
       'operation_sum'  => '30000', 
       'operation_currency'  => 'JPY' 
      ] 
     ]; 


     $expected = [ 
      0 => [ 
       'date' => '2016-01-05', 
       'client_id'  => '2', 
       'client_type'=> 'natural', 
       'operation_type' => 'cash_in', 
       'operation_sum'  => '200.00', 
       'operation_currency'  => 'EUR', 
      ], 

      1 => [ 
       'date' => '2016-01-10', 
       'client_id'  => '1', 
       'client_type'=> 'legal', 
       'operation_type' => 'cash_out', 
       'operation_sum'  => '300.00', 
       'operation_currency'  => 'EUR', 
      ], 

      2 => [ 
       'date' => '2016-01-11', 
       'client_id'  => '1', 
       'client_type'=> 'natural', 
       'operation_type' => 'cash_out', 
       'operation_sum'  => '30000', 
       'operation_currency'  => 'JPY' 
      ] 
     ]; 

     $um = new CommissionDataParser(); 
     $result = $um->groupOrdersByWeek($orders); 


     $this->assertEquals($expected, $result, '**** -->>>>> result array wrong'); 

    } 

私がテストしたい機能があります:私はこのクラスの小さな部分を置くが、たとえば最初に

namespace AppBundle\Parser; 


class CommissionDataParser 
{ 
    public function getData($file) 
    { 
     $orders = $this->extractOrders($file); 

     if (is_array($orders)) { 
      $orders = $this->groupOrdersByWeek($orders); 
     } 

     // ... 
    } 


    public function extractOrders($file) 
    { 
     $orders = []; 
     $data = []; 
     //$lines = explode(PHP_EOL, file_get_contents($file)); 

     if (($handle = fopen($file, "r")) !== FALSE) { 
      while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) { 

       $num = count($row); 

       if ($num !== 6) { 
        return 'Badly structured file'; 

       } else if ($num == 0) { 
        return 'file is empty'; 
       } 

       $data[] = $row; 
      } 
      fclose($handle); 
     } 

     foreach ($data as $row) 
     { 
      $orders[] = [ 
       'date' => $row[0], 
       'client_id' => $row[1], 
       'client_type' => $row[2], 
       'operation_type' => $row[3], 
       'operation_sum' => $row[4], 
       'operation_currency' => $row[5] 
      ]; 
     } 

     return $orders; 
    } 
+0

uはここCommissionDataParserのUコードを貼り付けることができますか? –

答えて

1

のために、あなたはPHPUnitのブートストラップとしてapp/autoload.phpを使用していることを確認する必要があります。プロジェクトのルートでごphpunit.xml.distファイルを開き、次の行を見つける:uはあなたのファイルに次の行bootstrap="app/autoload.php"が表示された場合

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd" 
    backupGlobals="false" 
    colors="true" 
    bootstrap="app/autoload.php" 
> 

を、すべての権利。

次に、ファイルCommissionDataParser.phpが物理的にこのディレクトリにあることを確認してください。AppBundle\Parser。このファイルへのフルパスはYOUR_PROJECT_ROOT\src\AppBundle\Parser\CommissionDataParser.php

でなければなりません。少なくとも私はあなたのコードを実行することができました。

+0

私はapp/autoload.phpを追加すると、このパスで実行するとbootstrap = "autoload.php"でした。未定義の関数でエラーが発生しました。 "/ var/www/symfony/app/app/autoload.php " –

+0

CommerceDataParser.phpへのパスが正しく –

+0

です。最後に、 'CommissionDataParser'クラスに' groupOrdersByWeek'メソッドがありますか?))))) –

0

はい本当に私が例えば写真を撮る:)があります)

enter image description here

+0

すべてが動作しています。どのように私のテストからオブジェクトを作成する私のパーサーオブジェクトエンティティマネージャを置く?それはクラスのために必要なので? –

関連する問題