コード例 #1
0
 /**
  * Test show()
  *
  * @covers ::get
  * @covers ::show
  * @test
  *
  * @return void
  */
 public function testShowCallsGetUrlWithParameters()
 {
     // Test values
     $getResponse = 'API Response';
     $allParameters = array('not-used');
     // Create the used mock objects
     $client = $this->getMockBuilder('Redmine\\Client')->disableOriginalConstructor()->getMock();
     $client->expects($this->once())->method('get')->with($this->logicalAnd($this->stringStartsWith('/issues/5.json'), $this->stringContains('not-used')))->willReturn($getResponse);
     // Create the object under test
     $api = new Issue($client);
     // Perform the tests
     $this->assertSame($getResponse, $api->show(5, $allParameters));
 }
コード例 #2
0
ファイル: SyncCommand.php プロジェクト: savaslabs/sumac
 /**
  * Get redmine issue matching this harvest entry and in the right project.
  *
  * @param \Harvest\Model\DayEntry $entry
  *
  * @return array|bool
  *                    Array of redmine issue information or FALSE if no match found
  */
 protected function getRedmineIssue(DayEntry $entry)
 {
     // Load the Redmine issue and check if the Harvest time entry ID is there, if so, skip.
     $redmine_issue_numbers = [];
     preg_match('/#([0-9]+)/', $entry->get('notes'), $redmine_issue_numbers);
     // Strip the leading '#', and take the first entry.
     $redmine_issue_number = reset($redmine_issue_numbers);
     $redmine_issue_number = str_replace('#', '', $redmine_issue_number);
     if (!$redmine_issue_number) {
         // The resulting value is not a number.
         $this->userTimeEntryErrors[$entry->get('user-id')]['no-number'][] = ['entry' => $entry];
         $this->output->writeln('<comment>Skipping entry, it does not look like there is an issue number here.');
         return false;
     }
     $this->setRedmineClient();
     $issue_api = new Redmine\Api\Issue($this->redmineClient);
     $redmine_issue = $issue_api->show($redmine_issue_number);
     if (!$redmine_issue || !isset($redmine_issue['issue']['project']['id'])) {
         // Issue doesn't exist in Redmine; this is probably a GitHub issue reference.
         $this->userTimeEntryErrors[$entry->get('user-id')]['missing-issue'][] = ['entry' => $entry];
         $this->output->writeln(sprintf('<error>- Could not find Redmine issue %d!</error>', $redmine_issue_number));
         $this->errors = true;
         return false;
     }
     // Validate that issue ID exists in project.
     if (isset($this->projectMap[$entry->get('project-id')])) {
         $project_names = [];
         $found = false;
         foreach ($this->projectMap[$entry->get('project-id')] as $project) {
             $project_names[] = current($project);
             if (isset($project[$redmine_issue['issue']['project']['id']])) {
                 $found = true;
             }
         }
         if (!$found) {
             // The issue number doesn't belong to the Harvest project we are looking at
             // time entries for, so continue. It's probably a GitHub issue ref.
             $this->userTimeEntryErrors[$entry->get('user-id')]['issue-not-in-project'][] = ['entry' => $entry];
             $this->output->writeln(sprintf('<error>- Issue %d does not exist in the Redmine project(s) %s. Time entry: \'%s\'</error>', $redmine_issue_number, implode(',', $project_names), $entry->toXML()));
             $this->errors = true;
             return false;
         }
     }
     return $redmine_issue;
 }
コード例 #3
0
ファイル: IssueTest.php プロジェクト: ntvis/php-redmine-api
 /**
  * Test show().
  *
  * @covers ::show
  * @test
  */
 public function testShowImplodesIncludeParametersCorrectly()
 {
     // Test values
     $parameters = array('include' => array('parameter1', 'parameter2'));
     $getResponse = array('API Response');
     // Create the used mock objects
     $client = $this->getMockBuilder('Redmine\\Client')->disableOriginalConstructor()->getMock();
     $client->expects($this->once())->method('get')->with($this->logicalAnd($this->stringStartsWith('/issues/5.json'), $this->stringContains(urlencode('parameter1,parameter2'))))->willReturn($getResponse);
     // Create the object under test
     $api = new Issue($client);
     // Perform the tests
     $this->assertSame($getResponse, $api->show(5, $parameters));
 }