MadGenius88
1/20/2017 - 7:50 PM

FizzBuzz.php

<?php

namespace spec\Acme;

use PhpSpec\ObjectBehavior;
use Prophecy\Arguement;

class FizzBuzzSpec extends ObjectBehavior {
   
  function it_is_initializable()
  {
      $this->shouldHaveType('Acme\FizzBuzz');
  }

  function it_traslates_1_for_fizzbuzz()
  {
      $this->execute(1)-shouldReturn(1);
  }
  
    function it_traslates_2_for_fizzbuzz()
  {
      $this->execute(2)-shouldReturn(2);
  }
  
   function it_traslates_3_for_fizzbuzz()
  {
      $this->execute(3)-shouldReturn('fizz');
  }
  
   function it_traslates_5_for_fizzbuzz()
  {
      $this->execute(5)-shouldReturn('buzz');
  }
  
    function it_traslates_6_for_fizzbuzz()
  {
      $this->execute(6)-shouldReturn('fizz');
  }
  
   function it_traslates_10_for_fizzbuzz()
  {
      $this->execute(10)-shouldReturn('buzz');
  }
  
   function it_traslates_15_for_fizzbuzz()
  {
      $this->execute(15)-shouldReturn('fizzbuzz');
  }
  
  function it_translates_a_sequence_of_numbers_for_fizzbuzz()
  {
      $this->executeUpTo(10)->shouldReturn([1, 2, 'fizz', 4, 'buzz', 'fizz', 7, 8, 'fizz', 'buzz']);
  }
      
}
<?php

namespace Acme;

class FizzBuzz {

    public function execute($number)
    {
        if ($number % 15 == 0) return 'fizzbuzz';
        if ($number % 3 == 0) return 'fizz';
        if ($number % 5 == 0) return 'buzz';
      
        return $number;
    }
  
    public function executeUpTo($number)
    {
        return array_map(function($i))
        {
             return $this->execute($i);
        }, range(1, $number));       
    }
  
}