You are here

function Braintree_TransactionAdvancedSearchTest::test_rangeNode_settledAt in Commerce Braintree 7

File

braintree_php/tests/integration/TransactionAdvancedSearchTest.php, line 1030

Class

Braintree_TransactionAdvancedSearchTest

Code

function test_rangeNode_settledAt() {
  $transaction = Braintree_Transaction::saleNoValidate(array(
    'amount' => '1000.00',
    'creditCard' => array(
      'number' => '4111111111111111',
      'expirationDate' => '05/12',
    ),
    'options' => array(
      'submitForSettlement' => true,
    ),
  ));
  Braintree_Http::put('/transactions/' . $transaction->id . '/settle');
  $transaction = Braintree_Transaction::find($transaction->id);
  $twenty_min_ago = date_create("now -20 minutes", new DateTimeZone("UTC"));
  $ten_min_ago = date_create("now -10 minutes", new DateTimeZone("UTC"));
  $ten_min_from_now = date_create("now +10 minutes", new DateTimeZone("UTC"));
  $collection = Braintree_Transaction::search(array(
    Braintree_TransactionSearch::id()
      ->is($transaction->id),
    Braintree_TransactionSearch::settledAt()
      ->between($twenty_min_ago, $ten_min_ago),
  ));
  $this
    ->assertEquals(0, $collection
    ->maximumCount());
  $collection = Braintree_Transaction::search(array(
    Braintree_TransactionSearch::id()
      ->is($transaction->id),
    Braintree_TransactionSearch::settledAt()
      ->between($ten_min_ago, $ten_min_from_now),
  ));
  $this
    ->assertEquals(1, $collection
    ->maximumCount());
  $this
    ->assertEquals($transaction->id, $collection
    ->firstItem()->id);
}