You are here

class Braintree_ResourceCollectionTest in Commerce Braintree 7

Hierarchy

Expanded class hierarchy of Braintree_ResourceCollectionTest

File

braintree_php/tests/unit/ResourceCollectionTest.php, line 17

View source
class Braintree_ResourceCollectionTest extends PHPUnit_Framework_TestCase {
  public static $values = array(
    "a",
    "b",
    "c",
    "d",
    "e",
  );
  function testIterateOverResults() {
    $response = array(
      'searchResults' => array(
        'pageSize' => 2,
        'ids' => array(
          '0',
          '1',
          '2',
          '3',
          '4',
        ),
      ),
    );
    $pager = array(
      'className' => 'Braintree_TestResource',
      'classMethod' => 'fetch',
      'methodArgs' => array(),
    );
    $collection = new Braintree_ResourceCollection($response, $pager);
    $count = 0;
    $index = 0;
    foreach ($collection as $value) {
      $this
        ->assertEquals(Braintree_ResourceCollectionTest::$values[$index], $value);
      $index += 1;
      $count += 1;
    }
    $this
      ->assertEquals(5, $count);
  }
  function testDoesntIterateWhenNoResults() {
    $response = array(
      'searchResults' => array(
        'pageSize' => 2,
        'ids' => array(),
      ),
    );
    $pager = array(
      'className' => 'Braintree_TestResource',
      'classMethod' => 'fetch',
      'methodArgs' => array(),
    );
    $collection = new Braintree_ResourceCollection($response, $pager);
    $count = 0;
    $index = 0;
    foreach ($collection as $value) {
      $index += 1;
      $count += 1;
      break;
    }
    $this
      ->assertEquals(0, $count);
    $this
      ->assertEquals(0, $index);
  }

}

Members