Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

Functions::throttle() is buggy #27

Open
tortuetorche opened this issue Mar 13, 2014 · 2 comments
Open

Functions::throttle() is buggy #27

tortuetorche opened this issue Mar 13, 2014 · 2 comments

Comments

@tortuetorche
Copy link

If you update the Functions::throttle() test like this (replace sleep(1); by sleep(2);:

  public function testCanThrottleFunctions()
  {
    $number = 0;
    $function = Functions::throttle(function () use (&$number) {
      $number++;
    }, 1);

    $function();
    $function();
    sleep(2);
    $function();

    $this->assertEquals(2, $number);
  }

PHPUnit returns: Failed asserting that 3 matches expected 2.

Or if you update the test like this (add a $this->assertEquals(1, $number); assertion):

  public function testCanThrottleFunctions()
  {
    $number = 0;
    $function = Functions::throttle(function () use (&$number) {
      $number++;
    }, 1);

    $function();
    $function();
    $this->assertEquals(1, $number);
    sleep(1);
    $function();

    $this->assertEquals(2, $number);
  }

PHPUnit returns: Failed asserting that 2 matches expected 1.

@black-snow
Copy link

Also there's a typo on http://anahkiasen.github.io/underscore-php/#Arrays within the throttle code example. Should be "Functions::throttle" instead of "Functions::only".

@Anahkiasen
Copy link
Owner

PRs accepted if you want to push a fix quickly

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants