Passed
Push — develop ( fcfb7f...7a8492 )
by Michael
01:17
created

test_handleWebhookPayload_initial_single()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\plugin\swarmzapierstructwebhook\test;
4
5
/**
6
 * General tests for the swarmzapierstructwebhook plugin
7
 *
8
 * @group plugin_swarmzapierstructwebhook
9
 * @group plugins
10
 */
11
class handlewebhookpayload_plugin_swarmzapierstructwebhook_test extends \DokuWikiTest
1 ignored issue
show
Bug introduced by
The type DokuWikiTest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
{
13
    /** @var array alway enable the needed plugins */
14
    protected $pluginsEnabled = ['swarmzapierstructwebhook', 'struct', 'sqlite'];
15
16
17
    /**
18
     * Do not refactor these with a DataProvider -> struct database state would depend on order of execution
19
     */
20
    public function test_handleWebhookPayload_initial_single()
21
    {
22
        $inputJSON = '{"createdAt": "1525849118", "like": "False", "isMayor": "True", "editableUntil": "1525935518000", "posts": {"count": "0", "textCount": "0"}, "comments": {"count": "0"}, "photos": {"count": "0", "items": ""}, "likes": {"count": "0", "groups": ""}, "venue": {"stats": {"tipCount": "2", "checkinsCount": "1552", "usersCount": "24"}, "name": "CosmoCode", "venueRatingBlacklisted": "True", "url": "http://www.cosmocode.de", "contact": {"twitter": "cosmocode"}, "location": {"city": "Berlin", "labeledLatLngs": "label: display\nlat: 52.5341728565\nlng: 13.4235969339", "cc": "DE", "country": "Germany", "postalCode": "10405", "state": "Berlin", "formattedAddress": "Prenzlauer Allee 36 (Marienburger Strasse),10405 Berlin", "crossStreet": "Marienburger Strasse", "address": "Prenzlauer Allee 36", "lat": "52.5341728565", "lng": "13.4235969339"}, "beenHere": {"lastCheckinExpiredAt": "0"}, "verified": "False", "id": "4b4ca6c8f964a520f8b826e3", "categories": "icon: {u\'prefix\': u\'https://ss3.4sqi.net/img/categories_v2/building/default_\', u\'suffix\': u\'.png\'}\nid: 4bf58dd8d48988d124941735\nname: Office\npluralName: Offices\nprimary: True\nshortName: Office"}, "type": "checkin", "id": "5af29c1e6fd626002c38730b", "timeZoneOffset": "120", "source": {"url": "https://www.swarmapp.com", "name": "Swarm for Android"}}';
23
        $webhook = new \dokuwiki\plugin\swarmzapierstructwebhook\test\mock\Webhook();
24
25
        $actualOK = $webhook->handleWebhookPayload($inputJSON);
26
27
        /** @var \remote_plugin_struct $remote */
28
        $remote = plugin_load('remote', 'struct');
1 ignored issue
show
Bug introduced by
The function plugin_load was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        $remote = /** @scrutinizer ignore-call */ plugin_load('remote', 'struct');
Loading history...
29
        $rows = $remote->getAggregationData(
30
            ['swarm'],
31
            ['*']
32
        );
33
34
        $expectedRows = [
35
            'swarm.date' => '2018-05-09',
36
            'swarm.json' => $inputJSON,
37
            'swarm.locname' => 'CosmoCode',
38
            'swarm.checkinid' => '5af29c1e6fd626002c38730b',
39
            'swarm.shout' => '',
40
            'swarm.time' => '2018-05-09 08:58',
41
        ];
42
43
        $this->assertTrue($actualOK, 'single event, initially creating the schema');
44
        $this->assertEquals($rows[0], $expectedRows);
45
    }
46
47
    /**
48
     * Do not refactor these with a DataProvider -> struct database state would depend on order of execution
49
     */
50
    public function test_handleWebhookPayload_initial_double()
51
    {
52
        $inputJSON = '{"createdAt": "1525849118", "like": "False", "isMayor": "True", "editableUntil": "1525935518000", "posts": {"count": "0", "textCount": "0"}, "comments": {"count": "0"}, "photos": {"count": "0", "items": ""}, "likes": {"count": "0", "groups": ""}, "venue": {"stats": {"tipCount": "2", "checkinsCount": "1552", "usersCount": "24"}, "name": "CosmoCode", "venueRatingBlacklisted": "True", "url": "http://www.cosmocode.de", "contact": {"twitter": "cosmocode"}, "location": {"city": "Berlin", "labeledLatLngs": "label: display\nlat: 52.5341728565\nlng: 13.4235969339", "cc": "DE", "country": "Germany", "postalCode": "10405", "state": "Berlin", "formattedAddress": "Prenzlauer Allee 36 (Marienburger Strasse),10405 Berlin", "crossStreet": "Marienburger Strasse", "address": "Prenzlauer Allee 36", "lat": "52.5341728565", "lng": "13.4235969339"}, "beenHere": {"lastCheckinExpiredAt": "0"}, "verified": "False", "id": "4b4ca6c8f964a520f8b826e3", "categories": "icon: {u\'prefix\': u\'https://ss3.4sqi.net/img/categories_v2/building/default_\', u\'suffix\': u\'.png\'}\nid: 4bf58dd8d48988d124941735\nname: Office\npluralName: Offices\nprimary: True\nshortName: Office"}, "type": "checkin", "id": "5af29c1e6fd626002c38730b", "timeZoneOffset": "120", "source": {"url": "https://www.swarmapp.com", "name": "Swarm for Android"}}';
53
        $webhook = new \dokuwiki\plugin\swarmzapierstructwebhook\test\mock\Webhook();
54
55
        $actualOK = $webhook->handleWebhookPayload($inputJSON);
56
        $actualOK = $actualOK && $webhook->handleWebhookPayload($inputJSON);
57
58
        /** @var \remote_plugin_struct $remote */
59
        $remote = plugin_load('remote', 'struct');
1 ignored issue
show
Bug introduced by
The function plugin_load was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        $remote = /** @scrutinizer ignore-call */ plugin_load('remote', 'struct');
Loading history...
60
        $rows = $remote->getAggregationData(
61
            ['swarm'],
62
            ['*']
63
        );
64
65
        $expectedRows = [
66
            'swarm.date' => '2018-05-09',
67
            'swarm.json' => $inputJSON,
68
            'swarm.locname' => 'CosmoCode',
69
            'swarm.checkinid' => '5af29c1e6fd626002c38730b',
70
            'swarm.shout' => '',
71
            'swarm.time' => '2018-05-09 08:58',
72
        ];
73
74
        $this->assertTrue($actualOK, 'single event, initially creating the schema');
75
        $this->assertCount(1, $rows, 'saving a payload twice should only create one row');
76
        $this->assertEquals($rows[0], $expectedRows);
77
    }
78
}