-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathNetworkTest.php
More file actions
119 lines (95 loc) · 3.21 KB
/
NetworkTest.php
File metadata and controls
119 lines (95 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace OpenStack\Test\Networking\v2\Models;
use GuzzleHttp\Psr7\Response;
use OpenStack\Networking\v2\Api;
use OpenStack\Networking\v2\Models\Network;
use OpenCloud\Test\TestCase;
class NetworkTest extends TestCase
{
/** @var Network */
private $network;
public function setUp()
{
parent::setUp();
$this->rootFixturesDir = dirname(__DIR__);
$this->network = new Network($this->client->reveal(), new Api());
$this->network->id = 'networkId';
}
public function test_it_creates()
{
$opts = [
'name' => 'foo',
'shared' => false,
'adminStateUp' => true
];
$expectedJson = ['network' => [
'name' => $opts['name'],
'shared' => $opts['shared'],
'admin_state_up' => $opts['adminStateUp'],
]];
$this->setupMock('POST', 'v2.0/networks', $expectedJson, [], 'network-post');
$this->assertInstanceOf(Network::class, $this->network->create($opts));
}
public function test_it_bulk_creates()
{
$opts = [
[
'name' => 'foo',
'shared' => false,
'adminStateUp' => true
],
[
'name' => 'bar',
'shared' => true,
'adminStateUp' => false
],
];
$expectedJson = [
'networks' => [
[
'name' => $opts[0]['name'],
'shared' => $opts[0]['shared'],
'admin_state_up' => $opts[0]['adminStateUp']
],
[
'name' => $opts[1]['name'],
'shared' => $opts[1]['shared'],
'admin_state_up' => $opts[1]['adminStateUp']
],
],
];
$this->setupMock('POST', 'v2.0/networks', $expectedJson, [], 'networks-post');
$networks = $this->network->bulkCreate($opts);
$this->assertInternalType('array', $networks);
$this->assertCount(2, $networks);
}
public function test_it_updates()
{
// Updatable attributes
$this->network->name = 'foo';
$this->network->shared = true;
$this->network->adminStateUp = false;
$expectedJson = ['network' => [
'name' => 'foo',
'shared' => true,
'admin_state_up' => false,
]];
$this->setupMock('PUT', 'v2.0/networks/networkId', $expectedJson, [], 'network-put');
$this->network->update();
}
public function test_it_retrieves()
{
$this->setupMock('GET', 'v2.0/networks/networkId', null, [], 'network-get');
$this->network->retrieve();
$this->assertEquals('networkId', $this->network->id);
$this->assertEquals('fakenetwork', $this->network->name);
$this->assertEquals('ACTIVE', $this->network->status);
$this->assertEquals(true, $this->network->routerExternal);
$this->assertEquals(false, $this->network->adminStateUp);
}
public function test_it_deletes()
{
$this->setupMock('DELETE', 'v2.0/networks/networkId', null, [], new Response(204));
$this->network->delete();
}
}