jeudi 28 juillet 2016

PHPSpec: how to call factory method multiple times on single test

I trying to get my hands dirty with PHPSpec.

Basically Im trying to make a TimeSpan as a practice. I want to make sure that all possible valid inputs are accepted.

function it_can_be_created_from_24_format()
    {
        $hours = 24;
        $minutes = 60;
        $seconds = 60;
        for ($h = 1; $h < $hours; $h++) {
            for ($m = 1; $m < $minutes; $m++) {
                for ($s = 1; $s < $seconds; $s++) {
                    $this->beConstructedThrough('fromString', [$this->buildTimeString($h, $m, $s)]);
                    $this->shouldNotThrow(\InvalidArgumentException::class)->duringInstantiation();
                    $this->getHours()->shouldBe($h);
                    $this->getMinutes()->shouldBe($m);
                    $this->getSeconds()->shouldBe($s);
                }
            }
        }
    }


private function buildTimeString($h, $m, $s)
    {
        $minutes = ($m < 9) ? '0'.$m : $m;
        $seconds = ($s < 9) ? '0'.$s : $s;
        return sprintf('%s:%s:%s', $h, $minutes, $seconds);
    }

But im receiving this error: enter image description here

Aucun commentaire:

Enregistrer un commentaire