CustomerTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Test\Unit;
  3. require_once dirname(__DIR__) . '/Setup.php';
  4. use Test\Setup;
  5. use Braintree;
  6. class CustomerTest extends Setup
  7. {
  8. public function testGet_givesErrorIfInvalidProperty()
  9. {
  10. $this->setExpectedException('PHPUnit_Framework_Error', 'Undefined property on Braintree\Customer: foo');
  11. $c = Braintree\Customer::factory([]);
  12. $c->foo;
  13. }
  14. public function testUpdateSignature_doesNotAlterOptionsInCreditCardUpdateSignature()
  15. {
  16. Braintree\CustomerGateway::updateSignature();
  17. foreach (Braintree\CreditCardGateway::updateSignature() as $key => $value) {
  18. if(is_array($value) and array_key_exists('options', $value)) {
  19. $this->assertEquals([
  20. 'makeDefault',
  21. 'verificationMerchantAccountId',
  22. 'verifyCard',
  23. 'verificationAmount',
  24. 'venmoSdkSession',
  25. 'failOnDuplicatePaymentMethod',
  26. ], $value['options']);
  27. }
  28. }
  29. }
  30. public function testCreateSignature_doesNotIncludeCustomerIdOnCreditCard()
  31. {
  32. $signature = Braintree\CustomerGateway::createSignature();
  33. $creditCardSignatures = array_filter($signature, 'Test\Unit\CustomerTest::findCreditCardArray');
  34. $creditCardSignature = array_shift($creditCardSignatures)['creditCard'];
  35. $this->assertNotContains('customerId', $creditCardSignature);
  36. }
  37. public function findCreditCardArray($el)
  38. {
  39. return is_array($el) && array_key_exists('creditCard', $el);
  40. }
  41. public function testFindErrorsOnBlankId()
  42. {
  43. $this->setExpectedException('InvalidArgumentException');
  44. Braintree\Customer::find('');
  45. }
  46. public function testFindErrorsOnWhitespaceId()
  47. {
  48. $this->setExpectedException('InvalidArgumentException');
  49. Braintree\Customer::find('\t');
  50. }
  51. }