@@ -638,13 +638,10 @@ public function testTrackInvalidOptimizelyObject()
638638 {
639639 $ optlyObject = new Optimizely ('Random datafile ' );
640640
641- $ notificationCenter = new \ReflectionProperty (Optimizely::class, '_notificationCenter ' );
642- $ notificationCenter ->setAccessible (true );
643- $ notificationCenter ->setValue ($ optlyObject , $ this ->notificationCenterMock );
644-
645641 // Verify that sendNotifications isn't called
646642 $ this ->notificationCenterMock ->expects ($ this ->never ())
647643 ->method ('sendNotifications ' );
644+ $ optlyObject ->notificationCenter = $ this ->notificationCenterMock ;
648645
649646 $ optlyObject ->track ('some_event ' , 'some_user ' );
650647 $ this ->expectOutputRegex ('/Datafile has invalid format. Failing "track"./ ' );
@@ -667,13 +664,10 @@ public function testTrackInvalidAttributes()
667664 $ this ->datafile , new ValidEventDispatcher (), $ this ->loggerMock , $ errorHandlerMock
668665 );
669666
670- $ notificationCenter = new \ReflectionProperty (Optimizely::class, '_notificationCenter ' );
671- $ notificationCenter ->setAccessible (true );
672- $ notificationCenter ->setValue ($ optlyObject , $ this ->notificationCenterMock );
673-
674667 // Verify that sendNotifications isn't called
675668 $ this ->notificationCenterMock ->expects ($ this ->never ())
676669 ->method ('sendNotifications ' );
670+ $ optlyObject ->notificationCenter = $ this ->notificationCenterMock ;
677671
678672 // Call track
679673 $ this ->assertNull ($ optlyObject ->track ('purchase ' , 'test_user ' , 42 ));
@@ -839,10 +833,6 @@ public function testTrackNoAttributesNoEventValue()
839833
840834 $ optlyObject = new Optimizely ($ this ->datafile , new ValidEventDispatcher (), $ this ->loggerMock );
841835
842- $ notificationCenter = new \ReflectionProperty (Optimizely::class, '_notificationCenter ' );
843- $ notificationCenter ->setAccessible (true );
844- $ notificationCenter ->setValue ($ optlyObject , $ this ->notificationCenterMock );
845-
846836 // Verify that sendNotifications is called with expected params
847837 $ arrayParam = array (
848838 'purchase ' ,
@@ -858,6 +848,7 @@ public function testTrackNoAttributesNoEventValue()
858848 NotificationType::TRACK ,
859849 $ arrayParam
860850 );
851+ $ optlyObject ->notificationCenter = $ this ->notificationCenterMock ;
861852
862853 $ eventBuilder = new \ReflectionProperty (Optimizely::class, '_eventBuilder ' );
863854 $ eventBuilder ->setAccessible (true );
@@ -954,12 +945,8 @@ public function testTrackNoAttributesNoEventValueAfterSetForcedVariation()
954945 ->with (Logger::DEBUG ,
955946 'Dispatching conversion event to URL logx.optimizely.com/track with params param1=val1. ' );
956947
957- $ optlyObject = new Optimizely ($ this ->datafile , new ValidEventDispatcher (), $ this ->loggerMock );
958-
959- $ notificationCenter = new \ReflectionProperty (Optimizely::class, '_notificationCenter ' );
960- $ notificationCenter ->setAccessible (true );
961- $ notificationCenter ->setValue ($ optlyObject , $ this ->notificationCenterMock );
962-
948+ $ optlyObject = new Optimizely ($ this ->datafile , new ValidEventDispatcher (), $ this ->loggerMock );
949+
963950 // Verify that sendNotifications is called with expected params
964951 $ arrayParam = array (
965952 'purchase ' ,
@@ -975,6 +962,7 @@ public function testTrackNoAttributesNoEventValueAfterSetForcedVariation()
975962 NotificationType::TRACK ,
976963 $ arrayParam
977964 );
965+ $ optlyObject ->notificationCenter = $ this ->notificationCenterMock ;
978966
979967 $ this ->assertTrue ($ this ->optimizelyObject ->setForcedVariation ($ experimentKey , $ userId , $ variationKey ), 'Set variation for paused experiment should have failed. ' );
980968
@@ -1075,10 +1063,6 @@ public function testTrackWithAttributesNoEventValue()
10751063
10761064 $ optlyObject = new Optimizely ($ this ->datafile , new ValidEventDispatcher (), $ this ->loggerMock );
10771065
1078- $ notificationCenter = new \ReflectionProperty (Optimizely::class, '_notificationCenter ' );
1079- $ notificationCenter ->setAccessible (true );
1080- $ notificationCenter ->setValue ($ optlyObject , $ this ->notificationCenterMock );
1081-
10821066 // Verify that sendNotifications is called with expected params
10831067 $ arrayParam = array (
10841068 'purchase ' ,
@@ -1095,6 +1079,8 @@ public function testTrackWithAttributesNoEventValue()
10951079 $ arrayParam
10961080 );
10971081
1082+ $ optlyObject ->notificationCenter = $ this ->notificationCenterMock ;
1083+
10981084 $ eventBuilder = new \ReflectionProperty (Optimizely::class, '_eventBuilder ' );
10991085 $ eventBuilder ->setAccessible (true );
11001086 $ eventBuilder ->setValue ($ optlyObject , $ this ->eventBuilderMock );
@@ -1187,10 +1173,6 @@ public function testTrackNoAttributesWithDeprecatedEventValue()
11871173
11881174 $ optlyObject = new Optimizely ($ this ->datafile , new ValidEventDispatcher (), $ this ->loggerMock );
11891175
1190- $ notificationCenter = new \ReflectionProperty (Optimizely::class, '_notificationCenter ' );
1191- $ notificationCenter ->setAccessible (true );
1192- $ notificationCenter ->setValue ($ optlyObject , $ this ->notificationCenterMock );
1193-
11941176 // Verify that sendNotifications is called with expected params
11951177 $ arrayParam = array (
11961178 'purchase ' ,
@@ -1206,6 +1188,7 @@ public function testTrackNoAttributesWithDeprecatedEventValue()
12061188 NotificationType::TRACK ,
12071189 $ arrayParam
12081190 );
1191+ $ optlyObject ->notificationCenter = $ this ->notificationCenterMock ;
12091192
12101193 $ eventBuilder = new \ReflectionProperty (Optimizely::class, '_eventBuilder ' );
12111194 $ eventBuilder ->setAccessible (true );
@@ -1293,11 +1276,7 @@ public function testTrackNoAttributesWithEventValue()
12931276 'Dispatching conversion event to URL logx.optimizely.com/track with params param1=val1. ' );
12941277
12951278 $ optlyObject = new Optimizely ($ this ->datafile , new ValidEventDispatcher (), $ this ->loggerMock );
1296-
1297- $ notificationCenter = new \ReflectionProperty (Optimizely::class, '_notificationCenter ' );
1298- $ notificationCenter ->setAccessible (true );
1299- $ notificationCenter ->setValue ($ optlyObject , $ this ->notificationCenterMock );
1300-
1279+
13011280 // Verify that sendNotifications is called with expected params
13021281 $ arrayParam = array (
13031282 'purchase ' ,
@@ -1314,6 +1293,8 @@ public function testTrackNoAttributesWithEventValue()
13141293 $ arrayParam
13151294 );
13161295
1296+ $ optlyObject ->notificationCenter = $ this ->notificationCenterMock ;
1297+
13171298 $ eventBuilder = new \ReflectionProperty (Optimizely::class, '_eventBuilder ' );
13181299 $ eventBuilder ->setAccessible (true );
13191300 $ eventBuilder ->setValue ($ optlyObject , $ this ->eventBuilderMock );
@@ -1390,10 +1371,6 @@ public function testTrackNoAttributesWithInvalidEventValue()
13901371
13911372 $ optlyObject = new Optimizely ($ this ->datafile , new ValidEventDispatcher (), $ this ->loggerMock );
13921373
1393- $ notificationCenter = new \ReflectionProperty (Optimizely::class, '_notificationCenter ' );
1394- $ notificationCenter ->setAccessible (true );
1395- $ notificationCenter ->setValue ($ optlyObject , $ this ->notificationCenterMock );
1396-
13971374 // Verify that sendNotifications is called with expected params
13981375 $ arrayParam = array (
13991376 'purchase ' ,
@@ -1410,6 +1387,8 @@ public function testTrackNoAttributesWithInvalidEventValue()
14101387 $ arrayParam
14111388 );
14121389
1390+ $ optlyObject ->notificationCenter = $ this ->notificationCenterMock ;
1391+
14131392 $ eventBuilder = new \ReflectionProperty (Optimizely::class, '_eventBuilder ' );
14141393 $ eventBuilder ->setAccessible (true );
14151394 $ eventBuilder ->setValue ($ optlyObject , $ this ->eventBuilderMock );
@@ -1511,11 +1490,7 @@ public function testTrackWithAttributesWithDeprecatedEventValue()
15111490
15121491
15131492 $ optlyObject = new Optimizely ($ this ->datafile , new ValidEventDispatcher (), $ this ->loggerMock );
1514-
1515- $ notificationCenter = new \ReflectionProperty (Optimizely::class, '_notificationCenter ' );
1516- $ notificationCenter ->setAccessible (true );
1517- $ notificationCenter ->setValue ($ optlyObject , $ this ->notificationCenterMock );
1518-
1493+
15191494 // Verify that sendNotifications is called with expected params
15201495 $ arrayParam = array (
15211496 'purchase ' ,
@@ -1532,6 +1507,8 @@ public function testTrackWithAttributesWithDeprecatedEventValue()
15321507 $ arrayParam
15331508 );
15341509
1510+ $ optlyObject ->notificationCenter = $ this ->notificationCenterMock ;
1511+
15351512 $ eventBuilder = new \ReflectionProperty (Optimizely::class, '_eventBuilder ' );
15361513 $ eventBuilder ->setAccessible (true );
15371514 $ eventBuilder ->setValue ($ optlyObject , $ this ->eventBuilderMock );
@@ -1628,11 +1605,7 @@ public function testTrackWithAttributesWithEventValue()
16281605 'Dispatching conversion event to URL logx.optimizely.com/track with params param1=val1. ' );
16291606
16301607 $ optlyObject = new Optimizely ($ this ->datafile , new ValidEventDispatcher (), $ this ->loggerMock );
1631-
1632- $ notificationCenter = new \ReflectionProperty (Optimizely::class, '_notificationCenter ' );
1633- $ notificationCenter ->setAccessible (true );
1634- $ notificationCenter ->setValue ($ optlyObject , $ this ->notificationCenterMock );
1635-
1608+
16361609 // Verify that sendNotifications is called with expected params
16371610 $ arrayParam = array (
16381611 'purchase ' ,
@@ -1649,6 +1622,8 @@ public function testTrackWithAttributesWithEventValue()
16491622 $ arrayParam
16501623 );
16511624
1625+ $ optlyObject ->notificationCenter = $ this ->notificationCenterMock ;
1626+
16521627 $ eventBuilder = new \ReflectionProperty (Optimizely::class, '_eventBuilder ' );
16531628 $ eventBuilder ->setAccessible (true );
16541629 $ eventBuilder ->setValue ($ optlyObject , $ this ->eventBuilderMock );
@@ -2072,14 +2047,12 @@ public function testIsFeatureEnabledGivenFeatureFlagIsNotEnabledForUser()
20722047 $ optimizelyMock ->expects ($ this ->never ())
20732048 ->method ('sendImpressionEvent ' );
20742049
2075- $ notificationCenter = new \ReflectionProperty (Optimizely::class, '_notificationCenter ' );
2076- $ notificationCenter ->setAccessible (true );
2077- $ notificationCenter ->setValue ($ optimizelyMock , $ this ->notificationCenterMock );
2078-
20792050 // verify that sendNotifications isn't called
20802051 $ this ->notificationCenterMock ->expects ($ this ->never ())
20812052 ->method ('sendNotifications ' );
20822053
2054+ $ optimizelyMock ->notificationCenter = $ this ->notificationCenterMock ;
2055+
20832056 $ this ->loggerMock ->expects ($ this ->at (0 ))
20842057 ->method ('log ' )
20852058 ->with (Logger::INFO , "Feature Flag 'double_single_variable_feature' is not enabled for user 'user_id'. " );
@@ -2624,9 +2597,7 @@ public function testSendImpressionEventWithNoAttributes(){
26242597 $ eventBuilder ->setAccessible (true );
26252598 $ eventBuilder ->setValue ($ optlyObject , $ this ->eventBuilderMock );
26262599
2627- $ notificationCenter = new \ReflectionProperty (Optimizely::class, '_notificationCenter ' );
2628- $ notificationCenter ->setAccessible (true );
2629- $ notificationCenter ->setValue ($ optlyObject , $ this ->notificationCenterMock );
2600+ $ optlyObject ->notificationCenter = $ this ->notificationCenterMock ;
26302601
26312602 $ this ->loggerMock ->expects ($ this ->at (0 ))
26322603 ->method ('log ' )
@@ -2712,9 +2683,7 @@ public function testSendImpressionEventWithAttributes(){
27122683 $ eventBuilder ->setAccessible (true );
27132684 $ eventBuilder ->setValue ($ optlyObject , $ this ->eventBuilderMock );
27142685
2715- $ notificationCenter = new \ReflectionProperty (Optimizely::class, '_notificationCenter ' );
2716- $ notificationCenter ->setAccessible (true );
2717- $ notificationCenter ->setValue ($ optlyObject , $ this ->notificationCenterMock );
2686+ $ optlyObject ->notificationCenter = $ this ->notificationCenterMock ;
27182687
27192688 $ optlyObject ->sendImpressionEvent ('test_experiment ' , 'control ' , 'test_user ' , $ userAttributes );
27202689 }
0 commit comments