Skip to content

Commit a129ddf

Browse files
committed
Add requirement for doc snippets
1 parent e461e1e commit a129ddf

File tree

5 files changed

+55
-19
lines changed

5 files changed

+55
-19
lines changed

AGENTS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ Prefer adding focused tests around the exact operation being changed instead of
103103
- a corresponding sample test under `tests/sample/`
104104
- documentation in `doc/services/` if the feature is part of the supported public workflow
105105

106+
All code snippets used in the docs must live in `samples/` rather than being maintained only inline in `.rst` files, and they must be covered by the sample test suite.
107+
106108
Sample tests typically create a temporary PHP file from a template and `require_once` it, so keep samples self-contained and readable.
107109

108110
## Documentation
@@ -123,3 +125,4 @@ make -C doc html
123125
- Keep docblocks accurate for public APIs and option arrays.
124126
- Reuse existing fixtures, sample patterns, and helper methods before inventing new ones.
125127
- If `composer.json` changes, run `composer normalize` because CI auto-normalizes that file.
128+

doc/services/compute/v2/server-groups.rst

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,7 @@ Microversion 2.64+
3939
If the Compute service is created with microversion ``2.64`` or later, you can use the singular ``policy`` field and
4040
optional ``rules`` object instead:
4141

42-
.. code-block:: php
43-
44-
$compute = $openstack->computeV2([
45-
'microVersion' => '2.64',
46-
]);
47-
48-
$serverGroup = $compute->createServerGroup([
49-
'name' => 'db-group',
50-
'policy' => 'anti-affinity',
51-
'rules' => [
52-
'max_server_per_host' => 1,
53-
],
54-
]);
42+
.. sample:: Compute/v2/server_groups/create_2_64.php
5543

5644
When Nova responds with the newer singular ``policy`` field, the SDK also exposes that value as the first item in
5745
``policies`` for compatibility with the older response shape.

samples/Compute/v2/server_groups/create.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
'scope' => ['project' => ['id' => '{projectId}']],
1313
]);
1414

15-
$compute = $openstack->computeV2(['region' => '{region}', 'microVersion' => '2.64']);
15+
$compute = $openstack->computeV2(['region' => '{region}']);
1616

1717
$serverGroup = $compute->createServerGroup([
18-
'name' => '{serverGroupName}',
19-
'policy' => 'anti-affinity',
20-
'rules' => ['max_server_per_host' => 3],
18+
'name' => '{serverGroupName}',
19+
'policies' => ['affinity'],
2120
]);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
require 'vendor/autoload.php';
4+
5+
$openstack = new OpenStack\OpenStack([
6+
'authUrl' => '{authUrl}',
7+
'region' => '{region}',
8+
'user' => [
9+
'id' => '{userId}',
10+
'password' => '{password}',
11+
],
12+
'scope' => ['project' => ['id' => '{projectId}']],
13+
]);
14+
15+
$compute = $openstack->computeV2([
16+
'region' => '{region}',
17+
'microVersion' => '2.64',
18+
]);
19+
20+
$serverGroup = $compute->createServerGroup([
21+
'name' => '{serverGroupName}',
22+
'policy' => 'anti-affinity',
23+
'rules' => [
24+
'max_server_per_host' => 1,
25+
],
26+
]);

tests/sample/Compute/v2/ServerGroupTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@ private function assertPolicy(ServerGroup $serverGroup, string $expected): void
1313
$this->assertEquals($expected, $serverGroup->policy);
1414
}
1515

16+
public function testCreateWithMicroversion264()
17+
{
18+
$name = $this->randomStr();
19+
20+
/** @var ServerGroup $serverGroup */
21+
require_once $this->sampleFile('server_groups/create_2_64.php', ['{serverGroupName}' => $name]);
22+
23+
try {
24+
$this->assertInstanceOf(ServerGroup::class, $serverGroup);
25+
$this->assertEquals($name, $serverGroup->name);
26+
$this->assertPolicy($serverGroup, 'anti-affinity');
27+
$this->assertEquals(1, $serverGroup->rules['max_server_per_host']);
28+
} finally {
29+
$serverGroup->delete();
30+
}
31+
32+
$this->expectException(BadResponseError::class);
33+
$serverGroup->retrieve();
34+
}
35+
1636
public function testCreate(): ServerGroup
1737
{
1838
$name = $this->randomStr();
@@ -22,7 +42,7 @@ public function testCreate(): ServerGroup
2242

2343
$this->assertInstanceOf(ServerGroup::class, $serverGroup);
2444
$this->assertEquals($name, $serverGroup->name);
25-
$this->assertPolicy($serverGroup, 'anti-affinity');
45+
$this->assertPolicy($serverGroup, 'affinity');
2646

2747
return $serverGroup;
2848
}
@@ -60,7 +80,7 @@ public function testRead(ServerGroup $createdServerGroup)
6080
$this->assertInstanceOf(ServerGroup::class, $serverGroup);
6181
$this->assertEquals($createdServerGroup->id, $serverGroup->id);
6282
$this->assertEquals($createdServerGroup->name, $serverGroup->name);
63-
$this->assertPolicy($serverGroup, 'anti-affinity');
83+
$this->assertPolicy($serverGroup, 'affinity');
6484
}
6585

6686
/**

0 commit comments

Comments
 (0)