Skip to content

Commit 85e1023

Browse files
run phpcs on tests/ directory too
1 parent bfd8a29 commit 85e1023

27 files changed

+350
-264
lines changed

phpcs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<arg name="colors"/>
55
<file>code-snippets/</file>
66
<file>src/</file>
7+
<file>tests/</file>
78
<file>migrations/</file>
89
<file>koko-analytics.php</file>
910
<file>uninstall.php</file>

tests/AdminTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
2+
23
declare(strict_types=1);
34

5+
namespace KokoAnalytics\Tests;
6+
47
use KokoAnalytics\Admin;
58
use PHPUnit\Framework\TestCase;
69

710
final class AdminTest extends TestCase
811
{
9-
public function testCanInstantiate() : void
12+
public function testCanInstantiate(): void
1013
{
1114
$i = new Admin();
1215
self::assertTrue($i instanceof Admin);

tests/AggregatorTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
2+
23
declare(strict_types=1);
34

5+
namespace KokoAnalytics\Tests;
6+
47
use KokoAnalytics\Aggregator;
58
use PHPUnit\Framework\TestCase;
69

710
final class AggregatorTest extends TestCase
811
{
9-
public function testCanInstantiate() : void
12+
public function testCanInstantiate(): void
1013
{
1114
$i = new Aggregator();
1215
self::assertTrue($i instanceof Aggregator);

tests/DashboardTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?php
2+
23
declare(strict_types=1);
34

5+
namespace KokoAnalytics\Tests;
6+
47
use KokoAnalytics\Dashboard;
58
use PHPUnit\Framework\TestCase;
9+
use DateTimeImmutable;
610

711
final class DashboardTest extends TestCase
812
{
9-
public function testCanInstantiate() : void
13+
public function testCanInstantiate(): void
1014
{
1115
$i = new Dashboard();
1216
self::assertTrue($i instanceof Dashboard);

tests/DashboardWidgetTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
2+
23
declare(strict_types=1);
34

5+
namespace KokoAnalytics\Tests;
6+
47
use KokoAnalytics\Dashboard_Widget;
58
use PHPUnit\Framework\TestCase;
69

710
final class DashboardWidgetTest extends TestCase
811
{
9-
public function testCanInstantiate() : void
12+
public function testCanInstantiate(): void
1013
{
1114
$i = new Dashboard_Widget();
1215
self::assertTrue($i instanceof Dashboard_Widget);

tests/EndpointInstallerTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
2+
23
declare(strict_types=1);
34

5+
namespace KokoAnalytics\Tests;
6+
47
use KokoAnalytics\Endpoint_Installer;
58
use PHPUnit\Framework\TestCase;
69

710
final class EndpointInstallerTest extends TestCase
811
{
9-
public function testCanInstantiate() : void
12+
public function testCanInstantiate(): void
1013
{
1114
$i = new Endpoint_Installer();
1215
self::assertTrue($i instanceof Endpoint_Installer);

tests/FunctionsTest.php

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
declare(strict_types=1);
44

5+
namespace KokoAnalytics\Tests;
6+
57
use PHPUnit\Framework\TestCase;
68

79
use function KokoAnalytics\extract_pageview_data;
@@ -14,50 +16,50 @@ final class FunctionsTest extends TestCase
1416
public function testExtractPageviewData(): void
1517
{
1618
// incomplete params
17-
$this->assertEquals(extract_pageview_data([]), []);
18-
$this->assertEquals(extract_pageview_data(['p' => '1']), []);
19-
$this->assertEquals(extract_pageview_data(['nv' => '2']), []);
20-
$this->assertEquals(extract_pageview_data(['up' => '3']), []);
21-
$this->assertEquals(extract_pageview_data(['p' => '1', 'nv' => '2']), []);
22-
$this->assertEquals(extract_pageview_data(['p' => '1', 'up' => '3']), []);
23-
$this->assertEquals(extract_pageview_data(['nv' => '2', 'up' => '3']), []);
19+
$this->assertEquals(extract_pageview_data([]), []);
20+
$this->assertEquals(extract_pageview_data(['p' => '1']), []);
21+
$this->assertEquals(extract_pageview_data(['nv' => '2']), []);
22+
$this->assertEquals(extract_pageview_data(['up' => '3']), []);
23+
$this->assertEquals(extract_pageview_data(['p' => '1', 'nv' => '2']), []);
24+
$this->assertEquals(extract_pageview_data(['p' => '1', 'up' => '3']), []);
25+
$this->assertEquals(extract_pageview_data(['nv' => '2', 'up' => '3']), []);
2426

2527
// complete but invalid
26-
$this->assertEquals(extract_pageview_data(['p' => '', 'nv' => '', 'up' => '']), []);
27-
$this->assertEquals(extract_pageview_data(['p' => 'x', 'nv' => '2', 'up' => '3']), []);
28-
$this->assertEquals(extract_pageview_data(['p' => '1', 'nv' => 'x', 'up' => '3']), []);
29-
$this->assertEquals(extract_pageview_data(['p' => '1', 'nv' => '2', 'up' => 'x']), []);
30-
$this->assertEquals(extract_pageview_data(['p' => '1', 'nv' => '2', 'up' => '3', 'r' => 'not an url']), []);
28+
$this->assertEquals(extract_pageview_data(['p' => '', 'nv' => '', 'up' => '']), []);
29+
$this->assertEquals(extract_pageview_data(['p' => 'x', 'nv' => '2', 'up' => '3']), []);
30+
$this->assertEquals(extract_pageview_data(['p' => '1', 'nv' => 'x', 'up' => '3']), []);
31+
$this->assertEquals(extract_pageview_data(['p' => '1', 'nv' => '2', 'up' => 'x']), []);
32+
$this->assertEquals(extract_pageview_data(['p' => '1', 'nv' => '2', 'up' => '3', 'r' => 'not an url']), []);
3133

3234
// complete and valid
33-
$this->assertEquals(extract_pageview_data(['p' => '1', 'nv' => '2', 'up' => '3']), ['p', 1, 2, 3, '']);
34-
$this->assertEquals(extract_pageview_data(['p' => '1', 'nv' => '2', 'up' => '3', 'r' => '']), ['p', 1, 2, 3, '']);
35-
$this->assertEquals(extract_pageview_data(['p' => '1', 'nv' => '2', 'up' => '3', 'r' => 'https://www.kokoanalytics.com']), ['p', 1, 2, 3, 'https://www.kokoanalytics.com']);
35+
$this->assertEquals(extract_pageview_data(['p' => '1', 'nv' => '2', 'up' => '3']), ['p', 1, 2, 3, '']);
36+
$this->assertEquals(extract_pageview_data(['p' => '1', 'nv' => '2', 'up' => '3', 'r' => '']), ['p', 1, 2, 3, '']);
37+
$this->assertEquals(extract_pageview_data(['p' => '1', 'nv' => '2', 'up' => '3', 'r' => 'https://www.kokoanalytics.com']), ['p', 1, 2, 3, 'https://www.kokoanalytics.com']);
3638
}
3739

3840
public function testExtractEventData(): void
3941
{
4042
// incomplete
41-
$this->assertEquals(extract_event_data([]), []);
42-
$this->assertEquals(extract_event_data(['e' => 'Event']), []);
43-
$this->assertEquals(extract_event_data(['p' => 'Param']), []);
44-
$this->assertEquals(extract_event_data(['u' => '1']), []);
45-
$this->assertEquals(extract_event_data(['v' => '1']), []);
46-
$this->assertEquals(extract_event_data(['e' => 'Event', 'v' => '1']), []);
47-
$this->assertEquals(extract_event_data(['e' => 'Event', 'u' => '1']), []);
48-
$this->assertEquals(extract_event_data(['p' => 'Param', 'v' => '1']), []);
49-
$this->assertEquals(extract_event_data(['p' => 'Param', 'u' => '1']), []);
50-
$this->assertEquals(extract_event_data(['e' => 'Event', 'p' => 'Param', 'u' => '1']), []);
51-
$this->assertEquals(extract_event_data(['e' => 'Event', 'p' => 'Param', 'v' => '1']), []);
43+
$this->assertEquals(extract_event_data([]), []);
44+
$this->assertEquals(extract_event_data(['e' => 'Event']), []);
45+
$this->assertEquals(extract_event_data(['p' => 'Param']), []);
46+
$this->assertEquals(extract_event_data(['u' => '1']), []);
47+
$this->assertEquals(extract_event_data(['v' => '1']), []);
48+
$this->assertEquals(extract_event_data(['e' => 'Event', 'v' => '1']), []);
49+
$this->assertEquals(extract_event_data(['e' => 'Event', 'u' => '1']), []);
50+
$this->assertEquals(extract_event_data(['p' => 'Param', 'v' => '1']), []);
51+
$this->assertEquals(extract_event_data(['p' => 'Param', 'u' => '1']), []);
52+
$this->assertEquals(extract_event_data(['e' => 'Event', 'p' => 'Param', 'u' => '1']), []);
53+
$this->assertEquals(extract_event_data(['e' => 'Event', 'p' => 'Param', 'v' => '1']), []);
5254

5355
// complete but invalid
54-
$this->assertEquals(extract_event_data(['e' => 'Event', 'p' => 'Param', 'u' => '1', 'v' => 'nan']), []);
55-
$this->assertEquals(extract_event_data(['e' => 'Event', 'p' => 'Param', 'u' => 'nan', 'v' => '100']), []);
56-
$this->assertEquals(extract_event_data(['e' => 'Event', 'p' => 'Param', 'u' => 'nan', 'v' => 'nan']), []);
57-
$this->assertEquals(extract_event_data(['e' => '', 'p' => 'Param', 'u' => '1', 'v' => '100']), []);
56+
$this->assertEquals(extract_event_data(['e' => 'Event', 'p' => 'Param', 'u' => '1', 'v' => 'nan']), []);
57+
$this->assertEquals(extract_event_data(['e' => 'Event', 'p' => 'Param', 'u' => 'nan', 'v' => '100']), []);
58+
$this->assertEquals(extract_event_data(['e' => 'Event', 'p' => 'Param', 'u' => 'nan', 'v' => 'nan']), []);
59+
$this->assertEquals(extract_event_data(['e' => '', 'p' => 'Param', 'u' => '1', 'v' => '100']), []);
5860

5961
// complete and valid
60-
$this->assertEquals(extract_event_data(['e' => 'Event', 'p' => 'Param', 'u' => '1', 'v' => '100']), ['e', 'Event', 'Param', 1, 100]);
62+
$this->assertEquals(extract_event_data(['e' => 'Event', 'p' => 'Param', 'u' => '1', 'v' => '100']), ['e', 'Event', 'Param', 1, 100]);
6163
}
6264

6365
public function testGetClientIp(): void
@@ -85,6 +87,5 @@ public function testPercentFormatI18n(): void
8587
$this->assertEquals(percent_format_i18n(-1.00), '-100%');
8688
$this->assertEquals(percent_format_i18n(0.55), '+55%');
8789
$this->assertEquals(percent_format_i18n(-0.55), '-55%');
88-
8990
}
9091
}

tests/MigrationsTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<?php
2+
23
declare(strict_types=1);
34

5+
namespace KokoAnalytics\Tests;
6+
47
use KokoAnalytics\Migrations;
58
use PHPUnit\Framework\TestCase;
69

710
class MigrationsTest extends TestCase
811
{
912
private $dir = '/tmp/koko-analytics-tests/migrations';
1013

11-
public function setUp() : void
14+
public function setUp(): void
1215
{
1316
if (! file_exists($this->dir)) {
1417
mkdir($this->dir, 0700, true);
@@ -21,7 +24,7 @@ public function testCanInstantiate()
2124
$this->assertInstanceOf(Migrations::class, $instance);
2225
}
2326

24-
public function tearDown() : void
27+
public function tearDown(): void
2528
{
2629
array_map('unlink', glob($this->dir . '/*.php'));
2730
if (file_exists($this->dir)) {

tests/PageviewAggregatorTest.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
2+
23
declare(strict_types=1);
34

5+
namespace KokoAnalytics\Tests;
6+
47
use KokoAnalytics\Aggregator;
58
use PHPUnit\Framework\TestCase;
69

710
final class PageviewAggregatorTest extends TestCase
811
{
9-
public function test_clean_url() : void
12+
public function test_clean_url(): void
1013
{
1114
$a = new \KokoAnalytics\Pageview_Aggregator();
1215

@@ -32,7 +35,7 @@ public function test_clean_url() : void
3235
}
3336
}
3437

35-
public function test_normalize_url() : void
38+
public function test_normalize_url(): void
3639
{
3740
$a = new \KokoAnalytics\Pageview_Aggregator();
3841
$tests = [
@@ -97,21 +100,26 @@ public function test_normalize_url() : void
97100
}
98101
}
99102

100-
public function test_is_valid_url(): void {
103+
public function test_is_valid_url(): void
104+
{
101105
$a = new \KokoAnalytics\Pageview_Aggregator();
102106

103-
foreach ([
107+
foreach (
108+
[
104109
'https://www.kokoanalytics.com',
105110
'android-app://com.google.android.googlequicksearchbox',
106-
] as $url) {
111+
] as $url
112+
) {
107113
$this->assertTrue($a->is_valid_url($url));
108114
}
109115

110-
foreach ([
111-
'',
112-
'Hello world',
113-
'<script>alert(1)</script>',
114-
] as $url) {
116+
foreach (
117+
[
118+
'',
119+
'Hello world',
120+
'<script>alert(1)</script>',
121+
] as $url
122+
) {
115123
$this->assertFalse($a->is_valid_url($url));
116124
}
117125
}

tests/PluginTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
<?php
2+
23
declare(strict_types=1);
34

5+
namespace KokoAnalytics\Tests;
6+
47
use KokoAnalytics\Aggregator;
58
use KokoAnalytics\Plugin;
69
use PHPUnit\Framework\TestCase;
710

811
final class PluginTest extends TestCase
912
{
10-
public function testCanInstantiate() : void
13+
public function testCanInstantiate(): void
1114
{
12-
$i = new Plugin( new Aggregator() );
15+
$i = new Plugin(new Aggregator());
1316
self::assertTrue($i instanceof Plugin);
1417
}
1518
}

0 commit comments

Comments
 (0)