Skip to content

Commit 411c9a8

Browse files
rashidspmikeproeng37
authored andcommitted
refactors Assertions (#100)
1 parent f12484a commit 411c9a8

File tree

3 files changed

+42
-171
lines changed

3 files changed

+42
-171
lines changed

tests/DecisionServiceTests/DecisionServiceTest.php

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,7 @@ public function testGetVariationForFeatureExperimentGivenNullExperimentIds()
630630
->method('log')
631631
->with(Logger::DEBUG, "The feature flag 'empty_feature' is not used in any experiments.");
632632

633-
$this->assertSame(
634-
null,
635-
$this->decisionService->getVariationForFeatureExperiment($feature_flag, 'user1', [])
636-
);
633+
$this->assertNull($this->decisionService->getVariationForFeatureExperiment($feature_flag, 'user1', []));
637634
}
638635

639636
// should return nil and log a message when the experiment is not in the datafile
@@ -655,10 +652,7 @@ public function testGetVariationForFeatureExperimentGivenExperimentNotInDataFile
655652
"The user 'user1' is not bucketed into any of the experiments using the feature 'boolean_feature'."
656653
);
657654

658-
$this->assertSame(
659-
null,
660-
$this->decisionService->getVariationForFeatureExperiment($feature_flag, 'user1', [])
661-
);
655+
$this->assertNull($this->decisionService->getVariationForFeatureExperiment($feature_flag, 'user1', []));
662656
}
663657

664658
// should return nil and log when the user is not bucketed into the feature flag's experiments
@@ -679,10 +673,7 @@ public function testGetVariationForFeatureExperimentGivenNonMutexGroupAndUserNot
679673
"The user 'user1' is not bucketed into any of the experiments using the feature 'multi_variate_feature'."
680674
);
681675
$feature_flag = $this->config->getFeatureFlagFromKey('multi_variate_feature');
682-
$this->assertSame(
683-
null,
684-
$this->decisionServiceMock->getVariationForFeatureExperiment($feature_flag, 'user1', [])
685-
);
676+
$this->assertNull($this->decisionServiceMock->getVariationForFeatureExperiment($feature_flag, 'user1', []));
686677
}
687678

688679
// should return the variation when the user is bucketed into a variation for the experiment on the feature flag
@@ -755,10 +746,7 @@ public function testGetVariationForFeatureExperimentGivenMutexGroupAndUserNotBuc
755746
Logger::INFO,
756747
"The user 'user_1' is not bucketed into any of the experiments using the feature 'boolean_feature'."
757748
);
758-
$this->assertEquals(
759-
null,
760-
$this->decisionServiceMock->getVariationForFeatureExperiment($feature_flag, 'user_1', [])
761-
);
749+
$this->assertNull($this->decisionServiceMock->getVariationForFeatureExperiment($feature_flag, 'user_1', []));
762750
}
763751

764752
// should return the bucketed experiment and variation
@@ -855,10 +843,7 @@ public function testGetVariationForFeatureWhenTheUserIsNeitherBucketedIntoFeatur
855843
"User 'user_1' is not bucketed into rollout for feature flag 'string_single_variable_feature'."
856844
);
857845

858-
$this->assertEquals(
859-
null,
860-
$decisionServiceMock->getVariationForFeature($feature_flag, 'user_1', [])
861-
);
846+
$this->assertNull($decisionServiceMock->getVariationForFeature($feature_flag, 'user_1', []));
862847
}
863848

864849
// should return null
@@ -874,10 +859,7 @@ public function testGetVariationForFeatureRolloutWhenNoRolloutIsAssociatedToFeat
874859
"Feature flag 'boolean_feature' is not used in a rollout."
875860
);
876861

877-
$this->assertEquals(
878-
null,
879-
$this->decisionServiceMock->getVariationForFeatureRollout($feature_flag, 'user_1', [])
880-
);
862+
$this->assertNull($this->decisionServiceMock->getVariationForFeatureRollout($feature_flag, 'user_1', []));
881863
}
882864

883865
// should return null
@@ -895,10 +877,7 @@ public function testGetVariationForFeatureRolloutWhenRolloutIsNotInDataFile()
895877
'Rollout with ID "invalid_rollout_id" is not in the datafile.'
896878
);
897879

898-
$this->assertEquals(
899-
null,
900-
$this->decisionServiceMock->getVariationForFeatureRollout($feature_flag, 'user_1', [])
901-
);
880+
$this->assertNull($this->decisionServiceMock->getVariationForFeatureRollout($feature_flag, 'user_1', []));
902881
}
903882

904883
// should return null
@@ -922,10 +901,7 @@ public function testGetVariationForFeatureRolloutWhenRolloutDoesNotHaveExperimen
922901
->method('getRolloutFromId')
923902
->will($this->returnValue($experiment_less_rollout));
924903

925-
$this->assertEquals(
926-
null,
927-
$this->decisionService->getVariationForFeatureRollout($feature_flag, 'user_1', [])
928-
);
904+
$this->assertNull($this->decisionService->getVariationForFeatureRollout($feature_flag, 'user_1', []));
929905
}
930906

931907
// ============== when the user qualifies for targeting rule (audience match) ======================
@@ -1028,10 +1004,8 @@ public function testGetVariationForFeatureRolloutWhenUserIsNeitherBucketedInTheT
10281004
$this->loggerMock->expects($this->never())
10291005
->method('log');
10301006

1031-
$this->assertEquals(
1032-
null,
1033-
$this->decisionService->getVariationForFeatureRollout($feature_flag, 'user_1', $user_attributes)
1034-
);
1007+
$this->assertNull(
1008+
$this->decisionService->getVariationForFeatureRollout($feature_flag, 'user_1', $user_attributes));
10351009
}
10361010

10371011
// ============== END of tests - when the user qualifies for targeting rule (audience match) ======================

tests/NotificationTests/NotificationCenterTest.php

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,16 @@ public function testAddNotificationWithInvalidParams()
5858
->method('log')
5959
->with(Logger::ERROR, "Invalid notification type.");
6060

61-
$this->assertSame(
62-
null,
63-
$this->notificationCenterObj->addNotificationListener(
64-
$invalid_type,
65-
function () {
66-
}
67-
)
68-
);
61+
$this->assertNull($this->notificationCenterObj->addNotificationListener($invalid_type, function () {
62+
}));
6963

7064
// should log and return null if invalid callable given
7165
$invalid_callable = "HelloWorld";
7266
$this->loggerMock->expects($this->at(0))
7367
->method('log')
7468
->with(Logger::ERROR, "Invalid notification callback.");
7569

76-
$this->assertSame(
77-
null,
78-
$this->notificationCenterObj->addNotificationListener(NotificationType::ACTIVATE, $invalid_callable)
79-
);
70+
$this->assertNull($this->notificationCenterObj->addNotificationListener(NotificationType::ACTIVATE, $invalid_callable));
8071
}
8172

8273
public function testAddNotificationWithValidTypeAndCallback()
@@ -372,10 +363,7 @@ function () {
372363
$this->loggerMock->expects($this->at(0))
373364
->method('log')
374365
->with(Logger::DEBUG, sprintf("No Callback found with notification ID '%s'.", $invalid_id));
375-
$this->assertSame(
376-
false,
377-
$this->notificationCenterObj->removeNotificationListener($invalid_id)
378-
);
366+
$this->assertFalse($this->notificationCenterObj->removeNotificationListener($invalid_id));
379367

380368
/////////////////////////////////////////////////////////////////////
381369
// === Verify that callback is removed for a valid notification ID //
@@ -385,10 +373,7 @@ function () {
385373
$this->loggerMock->expects($this->at(0))
386374
->method('log')
387375
->with(Logger::INFO, sprintf("Callback with notification ID '%s' has been removed.", $valid_id));
388-
$this->assertSame(
389-
true,
390-
$this->notificationCenterObj->removeNotificationListener($valid_id)
391-
);
376+
$this->assertTrue($this->notificationCenterObj->removeNotificationListener($valid_id));
392377

393378
// verify that notifications length for NotificationType::ACTIVATE is now 1
394379
$this->assertSame(
@@ -409,10 +394,7 @@ function () {
409394
$this->loggerMock->expects($this->at(0))
410395
->method('log')
411396
->with(Logger::DEBUG, sprintf("No Callback found with notification ID '%s'.", $valid_id));
412-
$this->assertSame(
413-
false,
414-
$this->notificationCenterObj->removeNotificationListener($valid_id)
415-
);
397+
$this->assertFalse($this->notificationCenterObj->removeNotificationListener($valid_id));
416398

417399
//verify that notifications lengths for NotificationType::ACTIVATE and NotificationType::TRACK remain same
418400
$this->assertSame(
@@ -475,10 +457,7 @@ function () {
475457
->method('handleError')
476458
->with(new InvalidNotificationTypeException('Invalid notification type.'));
477459

478-
$this->assertSame(
479-
null,
480-
$this->notificationCenterObj->clearNotifications($invalid_type)
481-
);
460+
$this->assertNull($this->notificationCenterObj->clearNotifications($invalid_type));
482461

483462
// Verify that notifications length for NotificationType::ACTIVATE is still 2
484463
$this->assertSame(

0 commit comments

Comments
 (0)