Skip to content

Commit aec2ca4

Browse files
committed
show an error message on the method usage page if no results found
1 parent c7cc885 commit aec2ca4

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
There are next changes:
66

7+
## 1.2.18
8+
9+
There are next changes:
10+
11+
- show an error message on the method usage page if no results found
12+
713
## 1.2.17
814

915
There are next changes:

src/Badoo/LiveProfilerUI/Pages/MethodUsagePage.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,34 @@ public function getTemplateData() : array
6262
$error = 'Enter method name';
6363
}
6464

65-
$methods = [];
65+
$method = [];
6666
if (!$error) {
6767
$this->data['method'] = ltrim($this->data['method'], '\\');
6868
$methods = $this->Method->findByName($this->data['method'], true);
6969

7070
if (empty($methods)) {
7171
$error = 'Method "' . $this->data['method'] . '" not found';
72+
} else {
73+
$method = current($methods);
7274
}
7375
}
7476

7577
$fields = $this->FieldList->getFields();
7678
$field_descriptions = $this->FieldList->getFieldDescriptions();
7779

7880
$results = [];
79-
if (!empty($methods)) {
81+
if (!empty($method)) {
8082
$start_snapshot_id = 0;
8183
if ($this->use_method_usage_optimisation) {
8284
$last_two_days = \Badoo\LiveProfilerUI\DateGenerator::getDatesArray(date('Y-m-d'), 2, 2);
83-
$start_snapshot_id = in_array(current($methods)['date'], $last_two_days, true)
85+
$start_snapshot_id = in_array($method['date'], $last_two_days, true)
8486
? $this->Snapshot->getMinSnapshotIdByDates($last_two_days)
8587
: 0;
8688
}
8789

8890
$method_data = $this->MethodData->getDataByMethodIdsAndSnapshotIds(
8991
[],
90-
array_keys($methods),
92+
[$method['id']],
9193
200,
9294
$start_snapshot_id
9395
);
@@ -113,10 +115,13 @@ public function getTemplateData() : array
113115
$result['fields']['calls_count'] = $snapshots[$Row->getSnapshotId()]['calls_count'];
114116
$results[] = $result;
115117
}
118+
119+
if (empty($results)) {
120+
$error = 'There is no result for ' . $this->data['method'] . '. Last time it was called on ' . $method['date'] . '.';
121+
}
116122
}
117123

118124
return [
119-
'methods' => $methods,
120125
'method' => $this->data['method'],
121126
'results' => $results,
122127
'field_descriptions' => $field_descriptions,

tests/unit/Badoo/LiveProfilerUI/Pages/MethodUsagePageTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public function providerGetTemplateData()
2424
'found_methods' => [],
2525
'methods_data' => [],
2626
'expected' => [
27-
'methods' => [],
2827
'method' => 'test',
2928
'results' => [],
3029
'field_descriptions' => [],
@@ -33,22 +32,20 @@ public function providerGetTemplateData()
3332
],
3433
'exists_method_no_snapshots' => [
3534
'method_name' => 'test',
36-
'found_methods' => [1 => ['name' => 'test']],
35+
'found_methods' => [1 => ['id' => 1, 'name' => 'test', 'date' => '2019-01-01']],
3736
'methods_data' => [],
3837
'expected' => [
39-
'methods' => [1 => ['name' => 'test']],
4038
'method' => 'test',
4139
'results' => [],
4240
'field_descriptions' => [],
43-
'error' => ''
41+
'error' => 'There is no result for test. Last time it was called on 2019-01-01.'
4442
]
4543
],
4644
'exists_method' => [
4745
'method_name' => 'test',
48-
'found_methods' => [1 => ['name' => 'test']],
46+
'found_methods' => [1 => ['id' => 1, 'name' => 'test', 'date' => '2019-01-01']],
4947
'methods_data' => [$MethodDataMock],
5048
'expected' => [
51-
'methods' => [1 => ['name' => 'test']],
5249
'method' => 'test',
5350
'results' => [
5451
[

0 commit comments

Comments
 (0)