コード例 #1
0
 /**
  * traverse a list held in an array
  *
  * @param  array $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
  */
 public static function using($list, $listName, callable $callable)
 {
     // robustness!
     if (!is_array($list) && !$list instanceof Traversable) {
         throw new InvalidArgumentException($listName . ' is not an array');
     }
     // if we get here, then we're okay to iterate over the list
     foreach ($list as $key => $data) {
         // make sure we quote the key correctly
         $name = $listName . '[' . quote_index($key) . ']';
         $callable($data, $key, $name);
     }
 }
コード例 #2
0
 /**
  * @covers ::quote_index
  */
 public function test_throws_InvalidArgumentException_for_resources()
 {
     // ----------------------------------------------------------------
     // setup your test
     $expectedName = STDIN;
     // ----------------------------------------------------------------
     // perform the change
     $actualName = quote_index($expectedName);
     // ----------------------------------------------------------------
     // test the results
     $this->assertEquals($expectedName, $actualName);
 }