MCPcopy Create free account
hub / github.com/Rello/analytics / testValidate

Method testValidate

tests/Service/ThresholdServiceTest.php:21–67  ·  view source on GitHub ↗

* @dataProvider validationData */

(array $thresholds, array $dataset, $dimension1, $dimension2, $value, $expectedNotification)

Source from the content-addressed store, hash-verified

19 * @dataProvider validationData
20 */
21 public function testValidate(array $thresholds, array $dataset, $dimension1, $dimension2, $value, $expectedNotification)
22 {
23 $thresholdMapper = $this->createMock(ThresholdMapper::class);
24 $thresholdMapper->method('getSevOneThresholdsByReport')->willReturn($thresholds);
25
26 $reportMapper = $this->createMock(ReportMapper::class);
27 $reportMapper->method('read')->willReturn($dataset);
28
29 $notification = $this->createMock(NotificationManager::class);
30 if ($expectedNotification) {
31 $notification->expects($this->once())->method('triggerNotification');
32 } else {
33 $notification->expects($this->never())->method('triggerNotification');
34 }
35
36 $datasetMapper = $this->createMock(\OCA\Analytics\Db\DatasetMapper::class);
37 $dateFormatter = $this->createMock(IDateTimeFormatter::class);
38
39 $variableService = new VariableService(
40 new NullLogger(),
41 $datasetMapper,
42 $dateFormatter
43 );
44
45 $service = new ThresholdService(
46 new NullLogger(),
47 $thresholdMapper,
48 $notification,
49 $reportMapper,
50 $variableService,
51 new FakeL10N(),
52 $this->createMock(DatasetStorageResolver::class),
53 $this->createMock(FlexibleStorageMapper::class)
54 );
55
56 // Call read to trigger variable replacement logic
57 //$this->assertSame($thresholds, $service->read(1));
58
59 $result = $service->validate($dataset['id'], $dimension1, $dimension2, $value);
60
61 // Assert whatever return value or side effects you need
62 if ($expectedNotification) {
63 $this->assertSame('Threshold value met', $result);
64 } else {
65 $this->assertNull($result);
66 }
67 }
68
69 public function validationData()
70 {

Callers

nothing calls this directly

Calls 1

validateMethod · 0.45

Tested by

no test coverage detected