/** * Test create() * * @covers ::create * @covers ::post * @test * * @return void */ public function testCreateCallsPost() { // Test values $getResponse = 'API Response'; $parameters = array('issue_id' => '15', 'project_id' => '25', 'hours' => '5.25'); // Create the used mock objects $client = $this->getMockBuilder('Redmine\\Client')->disableOriginalConstructor()->getMock(); $client->expects($this->once())->method('post')->with('/time_entries.xml', $this->logicalAnd($this->stringStartsWith('<?xml version="1.0"?>' . "\n" . '<time_entry>'), $this->stringEndsWith('</time_entry>' . "\n"), $this->stringContains('<issue_id>15</issue_id>'), $this->stringContains('<project_id>25</project_id>'), $this->stringContains('<hours>5.25</hours>')))->willReturn($getResponse); // Create the object under test $api = new TimeEntry($client); // Perform the tests $this->assertSame($getResponse, $api->create($parameters)); }
/** * Saves a harvest entry to Redmine, or updates an existing one if it exists. * * @param array $redmine_time_entry_params * @param array $existing_redmine_time_entries * * @return bool */ protected function saveHarvestTimeEntryToRedmine(array $redmine_time_entry_params, array $existing_redmine_time_entries) { $time_entry_api = new Redmine\Api\TimeEntry($this->redmineClient); if (count($existing_redmine_time_entries) === 0) { $time_entry_api->create($redmine_time_entry_params); } else { // Update existing entry. $time_entry_api->update($existing_redmine_time_entries[0]['id'], $redmine_time_entry_params); } return true; }
/** * Test create(). * * @covers ::create * @covers ::post * @test */ public function testCreateCallsPost() { // Test values $getResponse = 'API Response'; $parameters = array('issue_id' => '15', 'project_id' => '25', 'hours' => '5.25', 'custom_fields' => array(array('id' => 1, 'name' => 'Affected version', 'value' => '1.0.1'), array('id' => 2, 'name' => 'Resolution', 'value' => 'Fixed'))); // Create the used mock objects $client = $this->getMockBuilder('Redmine\\Client')->disableOriginalConstructor()->getMock(); $client->expects($this->once())->method('post')->with('/time_entries.xml', $this->logicalAnd($this->stringStartsWith('<?xml version="1.0"?>' . "\n" . '<time_entry>'), $this->stringEndsWith('</time_entry>' . "\n"), $this->stringContains('<issue_id>15</issue_id>'), $this->stringContains('<project_id>25</project_id>'), $this->stringContains('<hours>5.25</hours>'), $this->stringContains('<custom_fields type="array"><custom_field name="Affected version" id="1"><value>1.0.1</value></custom_field><custom_field name="Resolution" id="2"><value>Fixed</value></custom_field></custom_fields>')))->willReturn($getResponse); // Create the object under test $api = new TimeEntry($client); // Perform the tests $this->assertSame($getResponse, $api->create($parameters)); }