Skip to content

Commit faa7c1b

Browse files
committed
Add test for invalid XML_Response, simplify code
1 parent 36e7dde commit faa7c1b

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

tests/include/bundledLibsTest.php

+21-25
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77

88
use PHPUnit\Framework\Attributes\Test;
99

10-
class bundledLibsTest extends PHPUnit\Framework\TestCase
11-
{
12-
#[Test]
13-
public function test_serendipity_xml_rpc_message()
14-
{
10+
class bundledLibsTest extends PHPUnit\Framework\TestCase {
11+
var $message = null;
12+
13+
protected function setUp(): void {
1514
$args = array(
1615
new XML_RPC_Value(
1716
'testA',
@@ -22,12 +21,16 @@ public function test_serendipity_xml_rpc_message()
2221
'string'
2322
)
2423
);
25-
$message = new XML_RPC_Message(
24+
$this->$message = new XML_RPC_Message(
2625
'weblogUpdates.ping',
2726
$args
2827
);
29-
$message->createPayload();
30-
28+
$this->$message->createPayload();
29+
}
30+
31+
#[Test]
32+
public function test_serendipity_xml_rpc_message()
33+
{
3134
$expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r
3235
<methodCall>\r
3336
<methodName>weblogUpdates.ping</methodName>\r
@@ -41,27 +44,12 @@ public function test_serendipity_xml_rpc_message()
4144
</params>\r
4245
</methodCall>\r
4346
";
44-
$this->assertEquals($expected, $message->payload);
47+
$this->assertEquals($expected, $this->$message->payload);
4548
}
4649

4750
#[Test]
4851
public function test_serendipity_xml_rpc_response_valid()
4952
{
50-
$args = array(
51-
new XML_RPC_Value(
52-
'testA',
53-
'string'
54-
),
55-
new XML_RPC_Value(
56-
'testB',
57-
'string'
58-
)
59-
);
60-
$message = new XML_RPC_Message(
61-
'weblogUpdates.ping',
62-
$args
63-
);
64-
$message->createPayload();
6553
$example_response = "<methodResponse>
6654
<params>
6755
<param>
@@ -70,8 +58,16 @@ public function test_serendipity_xml_rpc_response_valid()
7058
</params>
7159
</methodResponse>";
7260

73-
$xmlrpc_result = $message->parseResponse($example_response);
61+
$xmlrpc_result = $this->$message->parseResponse($example_response);
7462
$this->assertEquals($example_response, $xmlrpc_result->serialize());
7563
}
64+
#[Test]
65+
public function test_serendipity_xml_rpc_response_invalid()
66+
{
67+
$example_response = "some non-xml response";
68+
69+
$xmlrpc_result = $this->$message->parseResponse($example_response);
70+
$this->assertEquals(2, $xmlrpc_result->faultCode());
71+
}
7672

7773
}

tests/include/functionsTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

33
$serendipity['dbType'] = 'pdo-sqlite';
4-
define('IN_serendipity', true);
5-
define('S9Y_INCLUDE_PATH', dirname(__FILE__) . '/../../');
4+
@define('IN_serendipity', true);
5+
@define('S9Y_INCLUDE_PATH', dirname(__FILE__) . '/../../');
66
require_once dirname(__FILE__) . '/../../include/functions.inc.php';
77

88
use PHPUnit\Framework\Attributes\DataProvider;

0 commit comments

Comments
 (0)