Skip to content

Commit 63504c1

Browse files
committed
Add tests for deprecated retrieveAll method
1 parent dd97725 commit 63504c1

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

tests/Unit/Api/AbstractApiTest.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Redmine\Tests\Unit\Api;
44

5-
use DOMDocument;
65
use PHPUnit\Framework\TestCase;
76
use Redmine\Api\AbstractApi;
87
use Redmine\Client\Client;
@@ -180,16 +179,6 @@ public static function getJsonDecodingFromGetMethodData(): array
180179
*/
181180
public function testXmlDecodingFromRequestMethods($methodName, $response, $decode, $expected)
182181
{
183-
$xmlToString = function (SimpleXMLElement $xmlElement) {
184-
$dom = new DOMDocument('1.0');
185-
$dom->preserveWhiteSpace = false;
186-
$dom->formatOutput = false;
187-
$dom->loadXML($xmlElement->asXML());
188-
189-
// Remove line breaks
190-
return preg_replace("/\r|\n/", '', $dom->saveXML());
191-
};
192-
193182
$client = $this->createMock(Client::class);
194183
$client->method('getLastResponseBody')->willReturn($response);
195184
$client->method('getLastResponseContentType')->willReturn('application/xml');
@@ -204,7 +193,7 @@ public function testXmlDecodingFromRequestMethods($methodName, $response, $decod
204193
$return = $method->invoke($api, 'path', $decode);
205194

206195
$this->assertInstanceOf(SimpleXMLElement::class, $return);
207-
$this->assertSame($expected, $xmlToString($return));
196+
$this->assertXmlStringEqualsXmlString($expected, $return->asXML());
208197
} elseif ('delete' === $methodName) {
209198
$return = $method->invoke($api, 'path');
210199

@@ -213,7 +202,7 @@ public function testXmlDecodingFromRequestMethods($methodName, $response, $decod
213202
$return = $method->invoke($api, 'path', '');
214203

215204
$this->assertInstanceOf(SimpleXMLElement::class, $return);
216-
$this->assertSame($expected, $xmlToString($return));
205+
$this->assertXmlStringEqualsXmlString($expected, $return->asXML());
217206
}
218207
}
219208

@@ -228,4 +217,23 @@ public static function getXmlDecodingFromGetMethodData(): array
228217
['delete', '<?xml version="1.0"?><issue/>', null, '<?xml version="1.0"?><issue/>'],
229218
];
230219
}
220+
221+
/**
222+
* @covers \Redmine\Api\AbstractApi::retrieveAll
223+
*/
224+
public function testDeprecatedRetrieveAll()
225+
{
226+
$client = $this->createMock(Client::class);
227+
$client->method('requestGet')->willReturn(true);
228+
$client->method('getLastResponseBody')->willReturn('<?xml version="1.0"?><issue/>');
229+
$client->method('getLastResponseContentType')->willReturn('application/xml');
230+
231+
$api = $this->getMockForAbstractClass(AbstractApi::class, [$client]);
232+
233+
$method = new ReflectionMethod($api, 'retrieveAll');
234+
$method->setAccessible(true);
235+
236+
$this->assertSame([], $method->invoke($api, '/issues.xml'));
237+
238+
}
231239
}

0 commit comments

Comments
 (0)