@@ -437,6 +437,8 @@ public function testCreateCallsPost()
437437 * @covers ::getIssueCategoryApi
438438 * @covers ::getIssueStatusApi
439439 * @covers ::getProjectApi
440+ * @covers ::getTrackerApi
441+ * @covers ::getUserApi
440442 * @test
441443 */
442444 public function testCreateWithClientCleansParameters ()
@@ -467,7 +469,7 @@ public function testCreateWithClientCleansParameters()
467469 ->willReturn ('cleanedValue ' );
468470
469471 $ client = $ this ->createMock (Client::class);
470- $ client ->expects ($ this ->exactly (6 ))
472+ $ client ->expects ($ this ->exactly (5 ))
471473 ->method ('getApi ' )
472474 ->willReturnMap (
473475 [
@@ -722,6 +724,60 @@ public function testCreateWithHttpClientRetrievesTrackerId()
722724 );
723725 }
724726
727+ /**
728+ * @covers ::create
729+ * @covers ::cleanParams
730+ * @covers ::getUserApi
731+ * @test
732+ */
733+ public function testCreateWithHttpClientRetrievesUserId ()
734+ {
735+ $ client = $ this ->createMock (HttpClient::class);
736+ $ client ->expects ($ this ->exactly (2 ))
737+ ->method ('request ' )
738+ ->willReturnCallback (function (string $ method , string $ path , string $ body = '' ) {
739+ if ($ method === 'GET ' ) {
740+ $ this ->assertSame ('/users.json ' , $ path );
741+ $ this ->assertSame ('' , $ body );
742+
743+ return $ this ->createConfiguredMock (
744+ Response::class,
745+ [
746+ 'getContentType ' => 'application/json ' ,
747+ 'getBody ' => '{"users":[{"login":"Author Name","id":5},{"login":"Assigned to User Name","id":6}]} ' ,
748+ ]
749+ );
750+ }
751+
752+ if ($ method === 'POST ' ) {
753+ $ this ->assertSame ('/issues.xml ' , $ path );
754+ $ this ->assertXmlStringEqualsXmlString ('<?xml version="1.0"?><issue><assigned_to_id>6</assigned_to_id><author_id>5</author_id></issue> ' , $ body );
755+
756+ return $ this ->createConfiguredMock (
757+ Response::class,
758+ [
759+ 'getContentType ' => 'application/xml ' ,
760+ 'getBody ' => '<?xml version="1.0"?><issue></issue> ' ,
761+ ]
762+ );
763+ }
764+
765+ throw new \Exception ();
766+ });
767+
768+ // Create the object under test
769+ $ api = new Issue ($ client );
770+
771+ $ xmlElement = $ api ->create (['assigned_to ' => 'Assigned to User Name ' , 'author ' => 'Author Name ' ]);
772+
773+ // Perform the tests
774+ $ this ->assertInstanceOf (SimpleXMLElement::class, $ xmlElement );
775+ $ this ->assertXmlStringEqualsXmlString (
776+ '<?xml version="1.0"?><issue></issue> ' ,
777+ $ xmlElement ->asXml (),
778+ );
779+ }
780+
725781 /**
726782 * Test create() and buildXML().
727783 *
@@ -844,7 +900,7 @@ public function testUpdateCleansParameters()
844900 ->willReturn ('cleanedValue ' );
845901
846902 $ client = $ this ->createMock (Client::class);
847- $ client ->expects ($ this ->exactly (6 ))
903+ $ client ->expects ($ this ->exactly (5 ))
848904 ->method ('getApi ' )
849905 ->willReturnMap (
850906 [
0 commit comments