2016-05-10 11 views
0

Ich habe die folgende Funktion, und ich versuche, die Struktur eines Objekts zu testen.PyStringNode und JSON-String

@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"}" 
    } 
    """ 

es ist etwas falsch mit dem meta_data Stück. Ich habe das Gefühl, das PyStringNode-Format konvertiert es nicht richtig. Hier ist der Teil in meinem Behat Kontext für die Handhabung des PyStringNode

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

und beim Ausführen des Behat Tests, erhalte ich die Fehler

null does not match expected type "array". 

wenn ich meta_data mit einer einfachen Zeichenfolge zu ersetzen, ist alles gut ..... gibt es einen besonderen Fall wenn man JSON-Objekte hat? Wie strukturiere ich mein Szenario/Feature?

+1

Suche nach 'PyStringNode' in [hier] (http://www.inanzzz.com/index.php/home) für Beispiele . – BentCoder

Antwort

1

Sie haben zusätzliche Anführungszeichen in der Umgebung Ihres Objekts. Entferne sie, es sollte funktionieren. Hier

ist die korrigierte Version (nicht getestet):

@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" 
     } 
    } 
    """