public function testBuildSchedule() { $schedule = [['rule' => 'foo', 'start' => 1, 'end' => 2, 'seconds' => 10, 'exists' => true], ['rule' => 'bar', 'start' => 2, 'end' => 5, 'seconds' => 100, 'exists' => false], ['rule' => 'baz', 'start' => 5, 'end' => 10, 'seconds' => 500, 'exists' => true]]; $rules = []; $i = 0; foreach ($schedule as $key => $options) { if ($options['exists']) { /* @var $rule \PHPUnit_Framework_MockObject_MockObject|RuleInterface */ $rule = $this->getMock('AnimeDb\\SmartSleep\\Rule\\RuleInterface'); $this->buildRule($rule, $options['start'], $options['end'], $options['seconds']); $this->collection->expects($this->at($i++))->method('has')->with($options['rule'])->will($this->returnValue(true)); $this->collection->expects($this->at($i++))->method('get')->with($options['rule'])->will($this->returnValue($rule)); $rules[] = $rule; } else { $this->collection->expects($this->at($i++))->method('has')->with($options['rule'])->will($this->returnValue(false)); } unset($schedule[$key]['exists']); } $schedule_obj = $this->builder->buildSchedule($schedule); $this->assertInstanceOf('AnimeDb\\SmartSleep\\Schedule', $schedule_obj); $this->assertEquals($rules, $schedule_obj->toArray()); }