You are here

protected function PHPUnit_Framework_Constraint_Count::getCountOf in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Framework/Constraint/Count.php \PHPUnit_Framework_Constraint_Count::getCountOf()

Parameters

mixed $other:

Return value

bool

3 calls to PHPUnit_Framework_Constraint_Count::getCountOf()
PHPUnit_Framework_Constraint_Count::failureDescription in vendor/phpunit/phpunit/src/Framework/Constraint/Count.php
Returns the description of the failure
PHPUnit_Framework_Constraint_Count::matches in vendor/phpunit/phpunit/src/Framework/Constraint/Count.php
Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise.
PHPUnit_Framework_Constraint_SameSize::__construct in vendor/phpunit/phpunit/src/Framework/Constraint/SameSize.php

File

vendor/phpunit/phpunit/src/Framework/Constraint/Count.php, line 46

Class

PHPUnit_Framework_Constraint_Count
@since Class available since Release 3.6.0

Code

protected function getCountOf($other) {
  if ($other instanceof Countable || is_array($other)) {
    return count($other);
  }
  elseif ($other instanceof Traversable) {
    if ($other instanceof IteratorAggregate) {
      $iterator = $other
        ->getIterator();
    }
    else {
      $iterator = $other;
    }
    $key = $iterator
      ->key();
    $count = iterator_count($iterator);

    // manually rewind $iterator to previous key, since iterator_count
    // moves pointer
    if ($key !== null) {
      $iterator
        ->rewind();
      while ($iterator
        ->valid() && $key !== $iterator
        ->key()) {
        $iterator
          ->next();
      }
    }
    return $count;
  }
}