8
8
use Redmine \Api \Group ;
9
9
use Redmine \Exception \MissingParameterException ;
10
10
use Redmine \Http \HttpClient ;
11
- use Redmine \Http \Request ;
12
- use Redmine \Http \Response ;
11
+ use Redmine \Tests \Fixtures \AssertingHttpClient ;
13
12
use SimpleXMLElement ;
14
13
15
14
/**
@@ -19,23 +18,18 @@ class CreateTest extends TestCase
19
18
{
20
19
public function testCreateWithNameCreatesGroup ()
21
20
{
22
- $ client = $ this ->createMock (HttpClient::class);
23
- $ client ->expects ($ this ->exactly (1 ))
24
- ->method ('request ' )
25
- ->willReturnCallback (function (Request $ request ) {
26
- $ this ->assertSame ('POST ' , $ request ->getMethod ());
27
- $ this ->assertSame ('/groups.xml ' , $ request ->getPath ());
28
- $ this ->assertSame ('application/xml ' , $ request ->getContentType ());
29
- $ this ->assertXmlStringEqualsXmlString ('<?xml version="1.0"?><group><name>Group Name</name></group> ' , $ request ->getContent ());
30
-
31
- return $ this ->createConfiguredMock (
32
- Response::class,
33
- [
34
- 'getContentType ' => 'application/xml ' ,
35
- 'getContent ' => '<?xml version="1.0"?><group></group> ' ,
36
- ]
37
- );
38
- });
21
+ $ client = AssertingHttpClient::create (
22
+ $ this ,
23
+ [
24
+ 'POST ' ,
25
+ '/groups.xml ' ,
26
+ 'application/xml ' ,
27
+ '<?xml version="1.0"?><group><name>Group Name</name></group> ' ,
28
+ 200 ,
29
+ 'application/xml ' ,
30
+ '<?xml version="1.0"?><group></group> '
31
+ ]
32
+ );
39
33
40
34
// Create the object under test
41
35
$ api = new Group ($ client );
@@ -52,23 +46,18 @@ public function testCreateWithNameCreatesGroup()
52
46
53
47
public function testCreateWithNameAndUserIdsCreatesGroup ()
54
48
{
55
- $ client = $ this ->createMock (HttpClient::class);
56
- $ client ->expects ($ this ->exactly (1 ))
57
- ->method ('request ' )
58
- ->willReturnCallback (function (Request $ request ) {
59
- $ this ->assertSame ('POST ' , $ request ->getMethod ());
60
- $ this ->assertSame ('/groups.xml ' , $ request ->getPath ());
61
- $ this ->assertSame ('application/xml ' , $ request ->getContentType ());
62
- $ this ->assertXmlStringEqualsXmlString ('<?xml version="1.0"?><group><name>Group Name</name><user_ids type="array"><user_id>1</user_id><user_id>2</user_id><user_id>3</user_id></user_ids></group> ' , $ request ->getContent ());
63
-
64
- return $ this ->createConfiguredMock (
65
- Response::class,
66
- [
67
- 'getContentType ' => 'application/xml ' ,
68
- 'getContent ' => '<?xml version="1.0"?><group></group> ' ,
69
- ]
70
- );
71
- });
49
+ $ client = AssertingHttpClient::create (
50
+ $ this ,
51
+ [
52
+ 'POST ' ,
53
+ '/groups.xml ' ,
54
+ 'application/xml ' ,
55
+ '<?xml version="1.0"?><group><name>Group Name</name><user_ids type="array"><user_id>1</user_id><user_id>2</user_id><user_id>3</user_id></user_ids></group> ' ,
56
+ 200 ,
57
+ 'application/xml ' ,
58
+ '<?xml version="1.0"?><group></group> '
59
+ ]
60
+ );
72
61
73
62
// Create the object under test
74
63
$ api = new Group ($ client );
@@ -85,23 +74,18 @@ public function testCreateWithNameAndUserIdsCreatesGroup()
85
74
86
75
public function testCreateWithNameAndCustomFieldsCreatesGroup ()
87
76
{
88
- $ client = $ this ->createMock (HttpClient::class);
89
- $ client ->expects ($ this ->exactly (1 ))
90
- ->method ('request ' )
91
- ->willReturnCallback (function (Request $ request ) {
92
- $ this ->assertSame ('POST ' , $ request ->getMethod ());
93
- $ this ->assertSame ('/groups.xml ' , $ request ->getPath ());
94
- $ this ->assertSame ('application/xml ' , $ request ->getContentType ());
95
- $ this ->assertXmlStringEqualsXmlString ('<?xml version="1.0"?><group><name>Group Name</name><custom_fields type="array"><custom_field id="1"><value>5</value></custom_field></custom_fields></group> ' , $ request ->getContent ());
96
-
97
- return $ this ->createConfiguredMock (
98
- Response::class,
99
- [
100
- 'getContentType ' => 'application/xml ' ,
101
- 'getContent ' => '<?xml version="1.0"?><group></group> ' ,
102
- ]
103
- );
104
- });
77
+ $ client = AssertingHttpClient::create (
78
+ $ this ,
79
+ [
80
+ 'POST ' ,
81
+ '/groups.xml ' ,
82
+ 'application/xml ' ,
83
+ '<?xml version="1.0"?><group><name>Group Name</name><custom_fields type="array"><custom_field id="1"><value>5</value></custom_field></custom_fields></group> ' ,
84
+ 200 ,
85
+ 'application/xml ' ,
86
+ '<?xml version="1.0"?><group></group> '
87
+ ]
88
+ );
105
89
106
90
// Create the object under test
107
91
$ api = new Group ($ client );
0 commit comments