1
|
|
|
<?php // phpcs:ignore Squiz.Commenting.FileComment.Missing |
2
|
|
|
|
3
|
|
|
namespace Automattic\Jetpack; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Test A8c_Mc_Stats class |
9
|
|
|
*/ |
10
|
|
|
class StatsTest extends TestCase { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Test add and get_current_status methods |
14
|
|
|
*/ |
15
|
|
|
public function test_add_get() { |
16
|
|
|
|
17
|
|
|
$stats = new A8c_Mc_Stats(); |
18
|
|
|
|
19
|
|
|
$stats->add( 'group', 'test' ); |
20
|
|
|
|
21
|
|
|
$check = $stats->get_current_stats(); |
22
|
|
|
|
23
|
|
|
$this->assertCount( 1, $check ); |
24
|
|
|
$this->assertArrayHasKey( 'group', $check ); |
25
|
|
|
$this->assertContains( 'test', $check['group'] ); |
26
|
|
|
$this->assertCount( 1, $check['group'] ); |
27
|
|
|
|
28
|
|
|
$stats->add( 'group', 'test2' ); |
29
|
|
|
|
30
|
|
|
$check = $stats->get_current_stats(); |
31
|
|
|
|
32
|
|
|
$this->assertCount( 1, $check ); |
33
|
|
|
$this->assertArrayHasKey( 'group', $check ); |
34
|
|
|
$this->assertContains( 'test', $check['group'] ); |
35
|
|
|
$this->assertContains( 'test2', $check['group'] ); |
36
|
|
|
$this->assertCount( 2, $check['group'] ); |
37
|
|
|
|
38
|
|
|
$stats->add( 'group2', 'test3' ); |
39
|
|
|
|
40
|
|
|
$check = $stats->get_current_stats(); |
41
|
|
|
|
42
|
|
|
$this->assertCount( 2, $check ); |
43
|
|
|
$this->assertArrayHasKey( 'group', $check ); |
44
|
|
|
$this->assertArrayHasKey( 'group2', $check ); |
45
|
|
|
$this->assertContains( 'test', $check['group'] ); |
46
|
|
|
$this->assertContains( 'test2', $check['group'] ); |
47
|
|
|
$this->assertContains( 'test3', $check['group2'] ); |
48
|
|
|
$this->assertCount( 2, $check['group'] ); |
49
|
|
|
$this->assertCount( 1, $check['group2'] ); |
50
|
|
|
|
51
|
|
|
// test errors. |
52
|
|
|
|
53
|
|
|
$this->assertFalse( $stats->add( 'group2', 'test3' ) ); |
54
|
|
|
$this->assertFalse( $stats->add( true, 'test3' ) ); |
|
|
|
|
55
|
|
|
$this->assertFalse( $stats->add( array( 123 ), 'test3' ) ); |
|
|
|
|
56
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Test get group query args |
61
|
|
|
*/ |
62
|
|
|
public function test_get_group_query_args() { |
63
|
|
|
|
64
|
|
|
$stats = new A8c_Mc_Stats(); |
65
|
|
|
$stats->add( 'group', 'test' ); |
66
|
|
|
$stats->add( 'group', 'test2' ); |
67
|
|
|
|
68
|
|
|
$this->assertEmpty( $stats->get_group_query_args( 'group2' ) ); |
69
|
|
|
|
70
|
|
|
$check = $stats->get_group_query_args( 'group' ); |
71
|
|
|
|
72
|
|
|
$this->assertCount( 1, $check ); |
73
|
|
|
$this->assertArrayHasKey( 'x_jetpack-group', $check ); |
74
|
|
|
$this->assertEquals( 'test,test2', $check['x_jetpack-group'] ); |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: