2016-05-10 2 views
0

次の機能があり、オブジェクトの構造をテストしようとしています。PyStringNodeとjsonの文字列

@mynet 
    Scenario: Import mynet network Transactions 
    Given I Import transactions for network "mynet" from "2015-09-01" to "2015-09-01" 
    Then I should have 20 transactions imported 
    And The first element of the transaction should be 
    """ 
    { 
      "transaction_date": "2015-09-01 19:34:17", 
      "tenant_id": 1, 
      "network": "xxx", 
      "network_transaction_id": "xxxxa630514d", 
      "network_merchant_name": "xxxxx", 
      "currency": "EUR", 
      "amount": "287.40", 
      "commission": "4.31", 
      "subid": "xxxxxxxxxx", 
      "enquiry_id": 0, 
      "reference": "xxxx6a630514d", 
      "network_merchant_id": "4", 
      "status": "declined", 
      "network_status": "2", 
      "meta_data": "{"short_name":"mynet"}" 
    } 
    """ 

meta_dataに問題があります。 PyStringNodeフォーマットが正しく変換されていないと感じています。ここ は、私は単純な文字列でMETA_DATAを交換するとき、すべてが順調であるPyStringNode

public function theFirstElementOfTheTransactionShouldBe(PyStringNode $string) 
{ 
    $expectedFirstElement = json_decode($string->getRaw(), true); 
    $realfirstelement = $this->transactions[0]; 
    Assert::assertEquals($realfirstelement, $expectedFirstElement); 
} 

を処理するために、私のBehatコンテキストで一部で、behatテストを実行しているとき、私はエラーを取得する

null does not match expected type "array". 

..... jsonオブジェクトを持っているときに特別なケースはありますか?私のシナリオ/フィーチャーをどのように構造化するのですか?

+1

例については[こちら](http://www.inanzzz.com/index.php/home)で 'PyStringNode'を検索:ここで

は修正版(テストしていない)です。 – BentCoder

答えて

1

あなたのオブジェクトを囲む余分な引用符があります。それらを削除し、それは動作するはずです。

@mynet 
    Scenario: Import mynet network Transactions 
    Given I Import transactions for network "mynet" from "2015-09-01" to "2015-09-01" 
    Then I should have 20 transactions imported 
    And The first element of the transaction should be 
    """ 
    { 
     "transaction_date": "2015-09-01 19:34:17", 
     "tenant_id": 1, 
     "network": "xxx", 
     "network_transaction_id": "xxxxa630514d", 
     "network_merchant_name": "xxxxx", 
     "currency": "EUR", 
     "amount": "287.40", 
     "commission": "4.31", 
     "subid": "xxxxxxxxxx", 
     "enquiry_id": 0, 
     "reference": "xxxx6a630514d", 
     "network_merchant_id": "4", 
     "status": "declined", 
     "network_status": "2", 
     "meta_data": { 
      "short_name":"mynet" 
     } 
    } 
    """