Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6540925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:02:26+00:00 2026-05-25T11:02:26+00:00

How do I make my stub act like an ArrayIterator, for example? I mean,

  • 0

How do I make my stub act like an ArrayIterator, for example? I mean, I want to iterate over this stub. It’s an exercise from Practical PHP Testing.

7.2
Write a EvenIterator which takes a FibonacciIterator an iterates only
on the even-indexed values (returning 0, 1, 3, 8, 21...).
7.3
Write tests for the EvenIterator class, stubbing out the
FibonacciIterator using an ArrayIterator in substitution, which is provided
by the Spl (otherwise it will never terminate!)

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:02:27+00:00Added an answer on May 25, 2026 at 11:02 am

    If I understand correctly the task here is to test EvenIterator by using ArrayIterator as a stub for FibonacciIterator.
    So for example load ArrayIterator with array of even values, pass it to EvenIterator and you should get same values. Then do the same with array of odd values, and you should get empty resultset.


    class EvenIteratorTest extends \PHPUnit_Framework_TestCase {
    
      public function testDoesNotRemoveEvens() {
    
        $data = array(2,4,6,8);
        $arrayIterator = new \ArrayIterator($data);
        $object = new EvenIterator($arrayIterator);
    
        $expected = $data;
        $actual = array();
        foreach($object as $v) {
          $actual[] = $v;
        }
        $this->assertEquals($expected,$actual);
      }
    
      public function testFiltersOutOdds() {
    
        $data = array(1,3,5,7);
        $arrayIterator = new \ArrayIterator($data);
        $object = new EvenIterator($arrayIterator);
    
        $actual = array();
        foreach($object as $v) {
          $actual[] = $v;
        }
        $this->assertEmpty($actual);
      }
    
    }
    

    As you can see, there’s a lot of duplicated code, so some refactoring would be in place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this may seem quite basic to geeks. But I want to make
To make it short: hibernate doesn't support projections and query by example? I found
To make a JavaScript class with a public method I'd do something like: function
I make a lot of web applications and from time to time I need
I make a user control and then want to include it on a page
I am developing a PHP script that has to make some calls to a
I have a thread in java/Android like this: Handler handler = new Handler() {
I want to make an android application which has two tap in one view
I want to make my own keyboard. I have the following code When I
Make a new AS3 Document in Flash, paste in the following code and run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.