@@ -37,37 +37,99 @@ protected function setUp()
37
37
->getMock ();
38
38
}
39
39
40
- public function testGetRevenueValueInvalidArgs ()
40
+ public function testGetRevenueValueWithUndefinedTags ()
41
41
{
42
- $ this ->assertNull (EventTagUtils::getRevenueValue (null ));
43
- $ this ->assertNull (EventTagUtils::getRevenueValue (0.5 ));
44
- $ this ->assertNull (EventTagUtils::getRevenueValue (65536 ));
45
- $ this ->assertNull (EventTagUtils::getRevenueValue (9223372036854775807 ));
46
- $ this ->assertNull (EventTagUtils::getRevenueValue ('65536 ' ));
47
- $ this ->assertNull (EventTagUtils::getRevenueValue (true ));
48
- $ this ->assertNull (EventTagUtils::getRevenueValue (false ));
42
+ $ this ->loggerMock ->expects ($ this ->exactly (3 ))
43
+ ->method ('log ' )
44
+ ->with (Logger::DEBUG , 'Event tags is undefined. ' );
45
+
46
+ $ this ->assertNull (EventTagUtils::getRevenueValue (null , $ this ->loggerMock ));
47
+ $ this ->assertNull (EventTagUtils::getRevenueValue (array (), $ this ->loggerMock ));
48
+ $ this ->assertNull (EventTagUtils::getRevenueValue (false , $ this ->loggerMock ));
49
+ }
50
+
51
+ public function testGetRevenueValueWithNonDictionaryTags ()
52
+ {
53
+ $ this ->loggerMock ->expects ($ this ->exactly (5 ))
54
+ ->method ('log ' )
55
+ ->with (Logger::DEBUG , 'Event tags is not a dictionary. ' );
56
+
57
+ $ this ->assertNull (EventTagUtils::getRevenueValue (0.5 , $ this ->loggerMock ));
58
+ $ this ->assertNull (EventTagUtils::getRevenueValue (65536 , $ this ->loggerMock ));
59
+ $ this ->assertNull (EventTagUtils::getRevenueValue (9223372036854775807 , $ this ->loggerMock ));
60
+ $ this ->assertNull (EventTagUtils::getRevenueValue ('65536 ' , $ this ->loggerMock ));
61
+ $ this ->assertNull (EventTagUtils::getRevenueValue (true , $ this ->loggerMock ));
49
62
}
63
+
64
+
50
65
public function testGetRevenueValueNoRevenueTag ()
51
66
{
52
- $ this ->assertNull (EventTagUtils::getRevenueValue (array ()));
53
- $ this ->assertNull (EventTagUtils::getRevenueValue (array ('non-revenue ' => 42 )));
67
+ $ this ->loggerMock ->expects ($ this ->exactly (2 ))
68
+ ->method ('log ' )
69
+ ->with (Logger::DEBUG , "The revenue key is not defined in the event tags or is null. " );
70
+
71
+ $ this ->assertNull (EventTagUtils::getRevenueValue (array ('revenue ' => null ), $ this ->loggerMock ));
72
+ $ this ->assertNull (EventTagUtils::getRevenueValue (array ('non-revenue ' => 42 ), $ this ->loggerMock ));
73
+ }
74
+
75
+ public function testGetRevenueValueWithNonNumericRevenueTag ()
76
+ {
77
+ $ this ->loggerMock ->expects ($ this ->exactly (4 ))
78
+ ->method ('log ' )
79
+ ->with (Logger::DEBUG , "Revenue value is not an integer or float, or is not a numeric string. " );
80
+
81
+ $ this ->assertNull (EventTagUtils::getRevenueValue (array ('revenue ' => 'optimizely ' ), $ this ->loggerMock ));
82
+ $ this ->assertNull (EventTagUtils::getRevenueValue (array ('revenue ' => true ), $ this ->loggerMock ));
83
+ $ this ->assertNull (EventTagUtils::getRevenueValue (array ('revenue ' => false ), $ this ->loggerMock ));
84
+ $ this ->assertNull (EventTagUtils::getRevenueValue (array ('revenue ' => array (1 , 2 , 3 )), $ this ->loggerMock ));
54
85
}
55
86
56
- public function testGetRevenueValueWithInvalidRevenueTag ()
87
+ public function testGetRevenueValueWithNonParsableRevenueTag ()
57
88
{
58
- $ this ->assertNull (EventTagUtils:: getRevenueValue ( array ( ' revenue ' => null )));
59
- $ this -> assertNull (EventTagUtils:: getRevenueValue ( array ( ' revenue ' => 0.5 )));
60
- $ this -> assertNull (EventTagUtils:: getRevenueValue ( array ( ' revenue ' => ' 65536 ' )) );
61
- $ this -> assertNull (EventTagUtils:: getRevenueValue ( array ( ' revenue ' => true )));
62
- $ this ->assertNull (EventTagUtils::getRevenueValue (array ('revenue ' => false ) ));
63
- $ this ->assertNull (EventTagUtils::getRevenueValue (array ('revenue ' => array ( 1 , 2 , 3 )) ));
89
+ $ this ->loggerMock -> expects ( $ this -> exactly ( 2 ))
90
+ -> method ( ' log ' )
91
+ -> with (Logger:: DEBUG , " Revenue value couldn't be parsed as an integer. " );
92
+
93
+ $ this ->assertNull (EventTagUtils::getRevenueValue (array ('revenue ' => 0.5 ), $ this -> loggerMock ));
94
+ $ this ->assertNull (EventTagUtils::getRevenueValue (array ('revenue ' => " 42.5 " ), $ this -> loggerMock ));
64
95
}
65
96
66
- public function testGetRevenueValueWithRevenueTag ()
97
+ public function testGetRevenueValueWithValidRevenueTag ()
67
98
{
68
- $ this ->assertSame (65536 , EventTagUtils::getRevenueValue (array ('revenue ' => 65536 )));
69
- $ this ->assertSame (9223372036854775807 , EventTagUtils::getRevenueValue (array ('revenue ' => 9223372036854775807 )));
70
- $ this ->assertSame (0 , EventTagUtils::getRevenueValue (array ('revenue ' => 0 )));
99
+ $ this ->loggerMock ->expects ($ this ->at (0 ))
100
+ ->method ('log ' )
101
+ ->with (Logger::INFO , "The revenue value 65536 will be sent to results. " );
102
+ $ this ->assertSame (65536 , EventTagUtils::getRevenueValue (array ('revenue ' => 65536 ), $ this ->loggerMock ));
103
+
104
+ $ this ->loggerMock ->expects ($ this ->at (0 ))
105
+ ->method ('log ' )
106
+ ->with (Logger::INFO , "The revenue value 65536 will be sent to results. " );
107
+ $ this ->assertSame (65536 , EventTagUtils::getRevenueValue (array ('revenue ' => "65536 " ), $ this ->loggerMock ));
108
+
109
+ $ this ->loggerMock ->expects ($ this ->at (0 ))
110
+ ->method ('log ' )
111
+ ->with (Logger::INFO , "The revenue value 65536 will be sent to results. " );
112
+ $ this ->assertSame (65536 , EventTagUtils::getRevenueValue (array ('revenue ' => 65536.0 ), $ this ->loggerMock ));
113
+
114
+ $ this ->loggerMock ->expects ($ this ->at (0 ))
115
+ ->method ('log ' )
116
+ ->with (Logger::INFO , "The revenue value 65536 will be sent to results. " );
117
+ $ this ->assertSame (65536 , EventTagUtils::getRevenueValue (array ('revenue ' => "65536.0 " ), $ this ->loggerMock ));
118
+
119
+ $ this ->loggerMock ->expects ($ this ->at (0 ))
120
+ ->method ('log ' )
121
+ ->with (Logger::INFO , "The revenue value 9223372036854775807 will be sent to results. " );
122
+ $ this ->assertSame (9223372036854775807 , EventTagUtils::getRevenueValue (array ('revenue ' => 9223372036854775807 ), $ this ->loggerMock ));
123
+
124
+ $ this ->loggerMock ->expects ($ this ->at (0 ))
125
+ ->method ('log ' )
126
+ ->with (Logger::INFO , "The revenue value 0 will be sent to results. " );
127
+ $ this ->assertSame (0 , EventTagUtils::getRevenueValue (array ('revenue ' => 0 ), $ this ->loggerMock ));
128
+
129
+ $ this ->loggerMock ->expects ($ this ->at (0 ))
130
+ ->method ('log ' )
131
+ ->with (Logger::INFO , "The revenue value 0 will be sent to results. " );
132
+ $ this ->assertSame (0 , EventTagUtils::getRevenueValue (array ('revenue ' => 0.0 ), $ this ->loggerMock ));
71
133
}
72
134
73
135
public function testGetNumericValueWithUndefinedTags ()
0 commit comments