public function testCreateWeek()
 {
     $server = $this->getMock('TZIntellitimeServer');
     $weekFactory = new TZIntellitimeWeekFactory($server, $this->account);
     $datetime = new DateTime('2011-02-07');
     $tzReports = array();
     $week = $weekFactory->createWeek($datetime, $tzReports);
     $this->assertInstanceOf('TZIntellitimeWeek', $week);
 }
 private function setupTestFixture($testDescriptions)
 {
     if (!is_array($testDescriptions)) {
         $testDescriptions = array($testDescriptions);
     }
     // Each key in $testDescription is the week date
     $index = 0;
     foreach ($testDescriptions as $test) {
         $date = new DateTime($test->date, $this->timezone);
         $this->syncPolicy->expects($this->at(2 * $index))->method('getNextWeekToSync')->will($this->returnValue($date));
         $expectedDateRange = tzintellitime_week_span($date);
         /*
          * storeTZJobs and storeTZReports get in between, which
          * increases the sequential call index by two.
          */
         $this->reportStorage->expects($this->at(3 * $index))->method('getTZReports')->with($expectedDateRange[0], $expectedDateRange[1])->will($this->returnValue($test->expectedReports));
         $expectedWeek = $this->getMockBuilder('TZIntellitimeWeek')->disableOriginalConstructor()->getMock();
         if (!isset($test->syncResult->intellitime_assignments)) {
             $test->syncResult->intellitime_assignments = array($this->createMockAssignment('Assignment Title', 'title'));
         }
         foreach ($test->syncResult->tzreports as $tzreport) {
             $tzreport->intellitime_jobid = $test->syncResult->intellitime_assignments[0]->id;
         }
         if (!isset($test->syncResult->unfinishedWeeks)) {
             $test->syncResult->unfinishedWeeks = array();
         }
         $expectedWeek->expects($this->at($index))->method('sync')->will($this->returnValue($test->syncResult));
         $this->weekFactory->expects($this->at($index))->method('createWeek')->with($date, $test->expectedReports)->will($this->returnValue($expectedWeek));
         $storedAssignments = array_map($this->clone_lambda, $test->syncResult->getTZJobs());
         foreach ($storedAssignments as $assignment_key => $assignment) {
             $assignment->nid = 2 + $assignment_key;
             $assignment->vid = 3 + $assignment_key;
             $assignment->parentid = 0;
         }
         $this->reportStorage->expects($this->at(1 + 3 * $index))->method('storeTZJobs')->with($test->syncResult->getTZJobs())->will($this->returnValue($storedAssignments));
         if (!isset($test->mappedReports)) {
             $test->mappedReports = array_map($this->clone_lambda, $test->syncResult->tzreports);
         }
         foreach ($test->mappedReports as $tzreport) {
             $tzreport->jobid = $storedAssignments[0]->nid;
             unset($tzreport->intellitime_jobid);
         }
         $this->reportStorage->expects($this->at(2 + 3 * $index))->method('storeTZReports')->with($test->mappedReports);
         $this->mappingPolicy->expects($this->at($index))->method('resolveMappings')->with($expectedDateRange[0], $expectedDateRange[1], $this->isType('array'));
         $index++;
     }
     $this->syncPolicy->expects($this->at(2 * $index))->method('getNextWeekToSync')->will($this->returnValue(NULL));
 }