You are here

function Braintree_Error_ValidationErrorCollectionTest::test_deepAll_givesAllErrorsDeeply in Commerce Braintree 7

File

braintree_php/tests/integration/Error/ValidationErrorCollectionTest.php, line 41

Class

Braintree_Error_ValidationErrorCollectionTest

Code

function test_deepAll_givesAllErrorsDeeply() {
  $result = Braintree_Customer::create(array(
    'email' => 'invalid',
    'creditCard' => array(
      'number' => '1234123412341234',
      'expirationDate' => 'invalid',
      'billingAddress' => array(
        'countryName' => 'invalid',
      ),
    ),
  ));
  $expectedErrors = array(
    Braintree_Error_Codes::CUSTOMER_EMAIL_IS_INVALID,
    Braintree_Error_Codes::CREDIT_CARD_EXPIRATION_DATE_IS_INVALID,
    Braintree_Error_Codes::CREDIT_CARD_NUMBER_IS_INVALID,
    Braintree_Error_Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED,
  );
  $actualErrors = $result->errors
    ->deepAll();
  $this
    ->assertEquals($expectedErrors, self::mapValidationErrorsToCodes($actualErrors));
  $expectedErrors = array(
    Braintree_Error_Codes::CREDIT_CARD_EXPIRATION_DATE_IS_INVALID,
    Braintree_Error_Codes::CREDIT_CARD_NUMBER_IS_INVALID,
    Braintree_Error_Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED,
  );
  $actualErrors = $result->errors
    ->forKey('customer')
    ->forKey('creditCard')
    ->deepAll();
  $this
    ->assertEquals($expectedErrors, self::mapValidationErrorsToCodes($actualErrors));
}