Skip to content

Commit 77595a8

Browse files
committed
Adding unit tests and fixing minor issues
1 parent 00f5ca7 commit 77595a8

42 files changed

Lines changed: 4032 additions & 5 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Annotations/AnnotationGenerator.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,14 @@ protected function getApplicableDemoExampleUrls(string $pluginName, string $meth
477477
'date' => 'today',
478478
];
479479

480+
// Don't build example URLs for anything that isn't the R in CRUD. E.g. No create, update, or delete.
481+
$notAllowedExampleUrlOperations = ['create', 'add', 'save', 'set', 'update', 'delete', 'remove', 'copy', 'duplicate'];
482+
foreach ($notAllowedExampleUrlOperations as $operation) {
483+
if (stripos($methodName, $operation) === 0) {
484+
return [];
485+
}
486+
}
487+
480488
$parametersToReplace = [];
481489
if (!empty($paramsData['custom'])) {
482490
foreach ($paramsData['custom'] as $customParam) {
@@ -908,7 +916,7 @@ protected function determineResponses(array $rules, string $plugin, string $meth
908916
* none of the base properties are small enough, we simply return an empty string.
909917
*
910918
* @param string $exampleValue The example response received from the demo or other server.
911-
* @param string $type The type of the parameter. E.g. string, integer, number, boolean, array, ...
919+
* @param string $type The type of the parameter. E.g. xml, json, or tsv
912920
*
913921
* @return string A new example string within a reasonable variation from the limit. If no row of the example fits
914922
* within the limit, the result is an empty string.
@@ -946,7 +954,7 @@ public function cutExampleCloseToCharLimit(string $exampleValue, string $type):
946954
$rows = $decodedRows['row'];
947955
}
948956
$newRows = [];
949-
foreach ($rows as $row) {
957+
foreach ($rows as $key => $row) {
950958
// Don't add the row if it would exceed the limit
951959
if (
952960
strlen(json_encode($row)) > self::EXAMPLE_CHAR_LIMIT
@@ -955,14 +963,21 @@ public function cutExampleCloseToCharLimit(string $exampleValue, string $type):
955963
continue;
956964
}
957965

966+
// If it's a named element, add it back by name
967+
if (is_string($key)) {
968+
$newRows[$key] = $row;
969+
continue;
970+
}
971+
972+
// Since it wasn't a named row, it must be an array can simply be added back
958973
$newRows[] = $row;
959974
}
960975

961976
if (empty($newRows)) {
962977
return '';
963978
}
964979

965-
if (!empty($decodedRows['row'])) {
980+
if (!empty($decodedRows['row']) && is_array($decodedRows['row'])) {
966981
$decodedRows['row'] = $newRows;
967982
} else {
968983
$decodedRows = $newRows;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"idalert": 1,
3+
"name": "Test Alert",
4+
"login": "someUserName",
5+
"period": "day",
6+
"report": "VisitsSummary_get",
7+
"report_condition": null,
8+
"report_matched": null,
9+
"report_mediums": [
10+
"email"
11+
],
12+
"metric": "nb_uniq_visitors",
13+
"metric_condition": "greater_than",
14+
"metric_matched": 500,
15+
"compared_to": 7,
16+
"email_me": 1,
17+
"additional_emails": [],
18+
"phone_numbers": [],
19+
"slack_channel_id": null,
20+
"id_sites": [
21+
1
22+
]
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<result>
3+
<idalert>1</idalert>
4+
<name>Test Alert</name>
5+
<login>someUserName</login>
6+
<period>day</period>
7+
<report>VisitsSummary_get</report>
8+
<report_condition />
9+
<report_matched />
10+
<report_mediums>
11+
<row>email</row>
12+
</report_mediums>
13+
<metric>nb_uniq_visitors</metric>
14+
<metric_condition>greater_than</metric_condition>
15+
<metric_matched>500</metric_matched>
16+
<compared_to>7</compared_to>
17+
<email_me>1</email_me>
18+
<additional_emails>
19+
</additional_emails>
20+
<phone_numbers>
21+
</phone_numbers>
22+
<slack_channel_id />
23+
<id_sites>
24+
<row>1</row>
25+
</id_sites>
26+
</result>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[
2+
{
3+
"idalert": 1,
4+
"name": "Test Alert",
5+
"login": "someUserName",
6+
"period": "day",
7+
"report": "VisitsSummary_get",
8+
"report_condition": null,
9+
"report_matched": null,
10+
"report_mediums": [
11+
"email"
12+
],
13+
"metric": "nb_uniq_visitors",
14+
"metric_condition": "greater_than",
15+
"metric_matched": 500,
16+
"compared_to": 7,
17+
"email_me": 1,
18+
"additional_emails": [],
19+
"phone_numbers": [],
20+
"slack_channel_id": null,
21+
"id_sites": [
22+
1
23+
]
24+
},
25+
{
26+
"idalert": 2,
27+
"name": "Test Visit Drop Previous Day",
28+
"login": "someUserName",
29+
"period": "day",
30+
"report": "VisitsSummary_get",
31+
"report_condition": null,
32+
"report_matched": null,
33+
"report_mediums": [
34+
"email"
35+
],
36+
"metric": "nb_uniq_visitors",
37+
"metric_condition": "percentage_decrease_more_than",
38+
"metric_matched": 20,
39+
"compared_to": 1,
40+
"email_me": 1,
41+
"additional_emails": [],
42+
"phone_numbers": [],
43+
"slack_channel_id": null,
44+
"id_sites": [
45+
1
46+
]
47+
}
48+
]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<result>
3+
<row>
4+
<idalert>1</idalert>
5+
<name>Test Alert</name>
6+
<login>someUserName</login>
7+
<period>day</period>
8+
<report>VisitsSummary_get</report>
9+
<report_condition />
10+
<report_matched />
11+
<report_mediums>
12+
<row>email</row>
13+
</report_mediums>
14+
<metric>nb_uniq_visitors</metric>
15+
<metric_condition>greater_than</metric_condition>
16+
<metric_matched>500</metric_matched>
17+
<compared_to>7</compared_to>
18+
<email_me>1</email_me>
19+
<additional_emails>
20+
</additional_emails>
21+
<phone_numbers>
22+
</phone_numbers>
23+
<slack_channel_id />
24+
<id_sites>
25+
<row>1</row>
26+
</id_sites>
27+
</row>
28+
<row>
29+
<idalert>2</idalert>
30+
<name>Test Visit Drop Previous Day</name>
31+
<login>someUserName</login>
32+
<period>day</period>
33+
<report>VisitsSummary_get</report>
34+
<report_condition />
35+
<report_matched />
36+
<report_mediums>
37+
<row>email</row>
38+
</report_mediums>
39+
<metric>nb_uniq_visitors</metric>
40+
<metric_condition>percentage_decrease_more_than</metric_condition>
41+
<metric_matched>20</metric_matched>
42+
<compared_to>1</compared_to>
43+
<email_me>1</email_me>
44+
<additional_emails>
45+
</additional_emails>
46+
<phone_numbers>
47+
</phone_numbers>
48+
<slack_channel_id />
49+
<id_sites>
50+
<row>1</row>
51+
</id_sites>
52+
</row>
53+
</result>

0 commit comments

Comments
 (0)