コード例 #1
0
 /**
  * throws exceptions if any of our requirements are not met
  *
  * @param  mixed $list
  *         the data to be examined by each requirement in turn
  * @param  string $fieldOrVarName
  *         what is the name of $list in the calling code?
  * @return void
  */
 public function toList($list, $fieldOrVarName = "value")
 {
     // we'll use this to traverse our list
     $callable = function ($value, $key, $name) {
         $this->to($value, $name);
     };
     // do we have an array, or an object?
     TraverseList::using($list, $fieldOrVarName, $callable);
 }
コード例 #2
0
/**
 * traverse a list held in an array or a traversable object
 *
 * @param  array|object $list
 *         the list to walk
 * @param  string $listName
 *         what is the name of $list in the calling code?
 * @param  callable $callable
 *         what are we calling
 * @return void
 */
function traverse_list($list, $listName, callable $callable)
{
    return TraverseList::using($list, $listName, $callable);
}
コード例 #3
0
 /**
  * @covers ::using
  * @dataProvider provideNonLists
  * @expectedException InvalidArgumentException
  */
 public function test_throws_InvalidArgumentException_when_list_is_not_an_arry_or_object($list)
 {
     // ----------------------------------------------------------------
     // setup your test
     // this will hold the list built by our callable
     $actualList = [];
     // the test uses a valid callable just to make sure this
     // is not triggering any exceptions of any kind
     $callable = function ($value, $key, $name) use(&$actualList) {
         $actualList[$name] = $value;
     };
     // ----------------------------------------------------------------
     // perform the change
     TraverseList::using($list, '$list', $callable);
     // ----------------------------------------------------------------
     // test the results
 }