@@ -731,6 +731,29 @@ public function testTrackInvalidEventTags()
731
731
$ optlyObject ->track ('purchase ' , 'test_user ' , [], [1 =>2 ]);
732
732
}
733
733
734
+ public function testTrackInvalidEventTagsWithDeprecatedRevenueValue ()
735
+ {
736
+ $ this ->loggerMock ->expects ($ this ->once ())
737
+ ->method ('log ' )
738
+ ->with (Logger::ERROR , 'Provided event tags are in an invalid format. ' );
739
+
740
+ $ errorHandlerMock = $ this ->getMockBuilder (NoOpErrorHandler::class)
741
+ ->setMethods (array ('handleError ' ))
742
+ ->getMock ();
743
+ $ errorHandlerMock ->expects ($ this ->once ())
744
+ ->method ('handleError ' )
745
+ ->with (new InvalidEventTagException ('Provided event tags are in an invalid format. ' ));
746
+
747
+ $ optlyObject = new Optimizely (
748
+ $ this ->datafile ,
749
+ null ,
750
+ $ this ->loggerMock ,
751
+ $ errorHandlerMock
752
+ );
753
+
754
+ $ optlyObject ->track ('purchase ' , 'test_user ' , [], 42 );
755
+ }
756
+
734
757
public function testTrackUnknownEventKey ()
735
758
{
736
759
$ this ->loggerMock ->expects ($ this ->at (0 ))
@@ -1199,141 +1222,6 @@ public function testTrackWithAttributesNoEventValue()
1199
1222
$ optlyObject ->track ('purchase ' , 'test_user ' , $ userAttributes );
1200
1223
}
1201
1224
1202
- public function testTrackNoAttributesWithDeprecatedEventValue ()
1203
- {
1204
- $ this ->eventBuilderMock ->expects ($ this ->once ())
1205
- ->method ('createConversionEvent ' )
1206
- ->with (
1207
- $ this ->projectConfig ,
1208
- 'purchase ' ,
1209
- ['7718750065 ' => '7725250007 ' ],
1210
- 'test_user ' ,
1211
- null ,
1212
- array ('revenue ' => 42 )
1213
- )
1214
- ->willReturn (new LogEvent ('logx.optimizely.com/track ' , ['param1 ' => 'val1 ' ], 'POST ' , []));
1215
-
1216
- $ callIndex = 0 ;
1217
- $ this ->loggerMock ->expects ($ this ->exactly (17 ))
1218
- ->method ('log ' );
1219
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1220
- ->method ('log ' )
1221
- ->with (
1222
- Logger::WARNING ,
1223
- 'Event value is deprecated in track call. Use event tags to pass in revenue value instead. '
1224
- );
1225
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1226
- ->method ('log ' )
1227
- ->with (Logger::DEBUG , 'User "test_user" is not in the forced variation map. ' );
1228
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1229
- ->method ('log ' )
1230
- ->with (Logger::INFO , 'User "test_user" does not meet conditions to be in experiment "test_experiment". ' );
1231
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1232
- ->method ('log ' )
1233
- ->with (
1234
- Logger::INFO ,
1235
- 'Not tracking user "test_user" for experiment "test_experiment". '
1236
- );
1237
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1238
- ->method ('log ' )
1239
- ->with (Logger::DEBUG , 'User "test_user" is not in the forced variation map. ' );
1240
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1241
- ->method ('log ' )
1242
- ->with (
1243
- Logger::DEBUG ,
1244
- 'Assigned bucket 4517 to user "test_user" with bucketing ID "test_user". '
1245
- );
1246
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1247
- ->method ('log ' )
1248
- ->with (
1249
- Logger::INFO ,
1250
- 'User "test_user" is not in experiment group_experiment_1 of group 7722400015. '
1251
- );
1252
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1253
- ->method ('log ' )
1254
- ->with (
1255
- Logger::INFO ,
1256
- 'Not tracking user "test_user" for experiment "group_experiment_1". '
1257
- );
1258
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1259
- ->method ('log ' )
1260
- ->with (Logger::DEBUG , 'User "test_user" is not in the forced variation map. ' );
1261
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1262
- ->method ('log ' )
1263
- ->with (
1264
- Logger::DEBUG ,
1265
- 'Assigned bucket 4517 to user "test_user" with bucketing ID "test_user". '
1266
- );
1267
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1268
- ->method ('log ' )
1269
- ->with (
1270
- Logger::INFO ,
1271
- 'User "test_user" is in experiment group_experiment_2 of group 7722400015. '
1272
- );
1273
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1274
- ->method ('log ' )
1275
- ->with (
1276
- Logger::DEBUG ,
1277
- 'Assigned bucket 9871 to user "test_user" with bucketing ID "test_user". '
1278
- );
1279
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1280
- ->method ('log ' )
1281
- ->with (
1282
- Logger::INFO ,
1283
- 'User "test_user" is in variation group_exp_2_var_2 of experiment group_experiment_2. '
1284
- );
1285
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1286
- ->method ('log ' )
1287
- ->with (
1288
- Logger::INFO ,
1289
- 'Experiment "paused_experiment" is not running. '
1290
- );
1291
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1292
- ->method ('log ' )
1293
- ->with (
1294
- Logger::INFO ,
1295
- 'Not tracking user "test_user" for experiment "paused_experiment". '
1296
- );
1297
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1298
- ->method ('log ' )
1299
- ->with (
1300
- Logger::INFO ,
1301
- 'Tracking event "purchase" for user "test_user". '
1302
- );
1303
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1304
- ->method ('log ' )
1305
- ->with (
1306
- Logger::DEBUG ,
1307
- 'Dispatching conversion event to URL logx.optimizely.com/track with params {"param1":"val1"}. '
1308
- );
1309
-
1310
- $ optlyObject = new Optimizely ($ this ->datafile , new ValidEventDispatcher (), $ this ->loggerMock );
1311
-
1312
- // Verify that sendNotifications is called with expected params
1313
- $ arrayParam = array (
1314
- 'purchase ' ,
1315
- 'test_user ' ,
1316
- null ,
1317
- array ('revenue ' => 42 ),
1318
- new LogEvent ('logx.optimizely.com/track ' , ['param1 ' => 'val1 ' ], 'POST ' , [])
1319
- );
1320
-
1321
- $ this ->notificationCenterMock ->expects ($ this ->once ())
1322
- ->method ('sendNotifications ' )
1323
- ->with (
1324
- NotificationType::TRACK ,
1325
- $ arrayParam
1326
- );
1327
- $ optlyObject ->notificationCenter = $ this ->notificationCenterMock ;
1328
-
1329
- $ eventBuilder = new \ReflectionProperty (Optimizely::class, '_eventBuilder ' );
1330
- $ eventBuilder ->setAccessible (true );
1331
- $ eventBuilder ->setValue ($ optlyObject , $ this ->eventBuilderMock );
1332
-
1333
- // Call track
1334
- $ optlyObject ->track ('purchase ' , 'test_user ' , null , 42 );
1335
- }
1336
-
1337
1225
public function testTrackNoAttributesWithEventValue ()
1338
1226
{
1339
1227
$ this ->eventBuilderMock ->expects ($ this ->once ())
@@ -1555,152 +1443,6 @@ public function testTrackNoAttributesWithInvalidEventValue()
1555
1443
$ optlyObject ->track ('purchase ' , 'test_user ' , null , array ('revenue ' => '4200 ' ));
1556
1444
}
1557
1445
1558
- public function testTrackWithAttributesWithDeprecatedEventValue ()
1559
- {
1560
- $ userAttributes = [
1561
- 'device_type ' => 'iPhone ' ,
1562
- 'company ' => 'Optimizely ' ,
1563
- 'location ' => 'San Francisco '
1564
- ];
1565
-
1566
- $ this ->eventBuilderMock ->expects ($ this ->once ())
1567
- ->method ('createConversionEvent ' )
1568
- ->with (
1569
- $ this ->projectConfig ,
1570
- 'purchase ' ,
1571
- [
1572
- '7716830082 ' => '7722370027 ' ,
1573
- '7718750065 ' => '7725250007 '
1574
- ],
1575
- 'test_user ' ,
1576
- $ userAttributes ,
1577
- array ('revenue ' => 42 )
1578
- )
1579
- ->willReturn (new LogEvent ('logx.optimizely.com/track ' , ['param1 ' => 'val1 ' ], 'POST ' , []));
1580
-
1581
- $ callIndex = 0 ;
1582
- $ this ->loggerMock ->expects ($ this ->exactly (17 ))
1583
- ->method ('log ' );
1584
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1585
- ->method ('log ' )
1586
- ->with (
1587
- Logger::WARNING ,
1588
- 'Event value is deprecated in track call. Use event tags to pass in revenue value instead. '
1589
- );
1590
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1591
- ->method ('log ' )
1592
- ->with (Logger::DEBUG , 'User "test_user" is not in the forced variation map. ' );
1593
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1594
- ->method ('log ' )
1595
- ->with (Logger::DEBUG , 'Assigned bucket 3037 to user "test_user" with bucketing ID "test_user". ' );
1596
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1597
- ->method ('log ' )
1598
- ->with (
1599
- Logger::INFO ,
1600
- 'User "test_user" is in variation control of experiment test_experiment. '
1601
- );
1602
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1603
- ->method ('log ' )
1604
- ->with (Logger::DEBUG , 'User "test_user" is not in the forced variation map. ' );
1605
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1606
- ->method ('log ' )
1607
- ->with (
1608
- Logger::DEBUG ,
1609
- 'Assigned bucket 4517 to user "test_user" with bucketing ID "test_user". '
1610
- );
1611
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1612
- ->method ('log ' )
1613
- ->with (
1614
- Logger::INFO ,
1615
- 'User "test_user" is not in experiment group_experiment_1 of group 7722400015. '
1616
- );
1617
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1618
- ->method ('log ' )
1619
- ->with (
1620
- Logger::INFO ,
1621
- 'Not tracking user "test_user" for experiment "group_experiment_1". '
1622
- );
1623
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1624
- ->method ('log ' )
1625
- ->with (Logger::DEBUG , 'User "test_user" is not in the forced variation map. ' );
1626
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1627
- ->method ('log ' )
1628
- ->with (
1629
- Logger::DEBUG ,
1630
- 'Assigned bucket 4517 to user "test_user" with bucketing ID "test_user". '
1631
- );
1632
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1633
- ->method ('log ' )
1634
- ->with (
1635
- Logger::INFO ,
1636
- 'User "test_user" is in experiment group_experiment_2 of group 7722400015. '
1637
- );
1638
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1639
- ->method ('log ' )
1640
- ->with (
1641
- Logger::DEBUG ,
1642
- 'Assigned bucket 9871 to user "test_user" with bucketing ID "test_user". '
1643
- );
1644
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1645
- ->method ('log ' )
1646
- ->with (
1647
- Logger::INFO ,
1648
- 'User "test_user" is in variation group_exp_2_var_2 of experiment group_experiment_2. '
1649
- );
1650
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1651
- ->method ('log ' )
1652
- ->with (
1653
- Logger::INFO ,
1654
- 'Experiment "paused_experiment" is not running. '
1655
- );
1656
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1657
- ->method ('log ' )
1658
- ->with (
1659
- Logger::INFO ,
1660
- 'Not tracking user "test_user" for experiment "paused_experiment". '
1661
- );
1662
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1663
- ->method ('log ' )
1664
- ->with (
1665
- Logger::INFO ,
1666
- 'Tracking event "purchase" for user "test_user". '
1667
- );
1668
- $ this ->loggerMock ->expects ($ this ->at ($ callIndex ++))
1669
- ->method ('log ' )
1670
- ->with (
1671
- Logger::DEBUG ,
1672
- 'Dispatching conversion event to URL logx.optimizely.com/track with params {"param1":"val1"}. '
1673
- );
1674
-
1675
-
1676
- $ optlyObject = new Optimizely ($ this ->datafile , new ValidEventDispatcher (), $ this ->loggerMock );
1677
-
1678
- // Verify that sendNotifications is called with expected params
1679
- $ arrayParam = array (
1680
- 'purchase ' ,
1681
- 'test_user ' ,
1682
- $ userAttributes ,
1683
- array ('revenue ' => 42 ),
1684
- new LogEvent ('logx.optimizely.com/track ' , ['param1 ' => 'val1 ' ], 'POST ' , [])
1685
- );
1686
-
1687
- $ this ->notificationCenterMock ->expects ($ this ->once ())
1688
- ->method ('sendNotifications ' )
1689
- ->with (
1690
- NotificationType::TRACK ,
1691
- $ arrayParam
1692
- );
1693
-
1694
- $ optlyObject ->notificationCenter = $ this ->notificationCenterMock ;
1695
-
1696
- $ eventBuilder = new \ReflectionProperty (Optimizely::class, '_eventBuilder ' );
1697
- $ eventBuilder ->setAccessible (true );
1698
- $ eventBuilder ->setValue ($ optlyObject , $ this ->eventBuilderMock );
1699
-
1700
- // Call track
1701
- $ optlyObject ->track ('purchase ' , 'test_user ' , $ userAttributes , 42 );
1702
- }
1703
-
1704
1446
public function testTrackWithAttributesWithEventValue ()
1705
1447
{
1706
1448
$ userAttributes = [
0 commit comments