@@ -1268,6 +1268,96 @@ public function test_it_can_handles_float_scopes_correctly()
12681268 FloatScopeFeature::class => false ,
12691269 ], Feature::for (10.00 )->all ());
12701270 }
1271+
1272+ public function test_it_dispatches_events_when_activating_multiple_features_and_scopes ()
1273+ {
1274+ Event::fake ([FeatureUpdated::class]);
1275+
1276+ $ first = new User (['id ' => 1 ]);
1277+ $ second = new User (['id ' => 2 ]);
1278+
1279+ Feature::for ([$ first , $ second ])->activate (['foo ' , 'bar ' ]);
1280+
1281+ Event::assertDispatchedTimes (FeatureUpdated::class, 4 );
1282+
1283+ $ events = [];
1284+ Event::assertDispatched (function (FeatureUpdated $ event ) use (&$ events ) {
1285+ $ events [] = [
1286+ 'feature ' => $ event ->feature ,
1287+ 'scope ' => $ event ->scope ,
1288+ 'value ' => $ event ->value ,
1289+ ];
1290+
1291+ return true ;
1292+ });
1293+
1294+ $ this ->assertCount (4 , $ events );
1295+ $ this ->assertContains ([
1296+ 'feature ' => 'foo ' ,
1297+ 'scope ' => $ first ,
1298+ 'value ' => true ,
1299+ ], $ events );
1300+ $ this ->assertContains ([
1301+ 'feature ' => 'foo ' ,
1302+ 'scope ' => $ second ,
1303+ 'value ' => true ,
1304+ ], $ events );
1305+ $ this ->assertContains ([
1306+ 'feature ' => 'bar ' ,
1307+ 'scope ' => $ first ,
1308+ 'value ' => true ,
1309+ ], $ events );
1310+ $ this ->assertContains ([
1311+ 'feature ' => 'bar ' ,
1312+ 'scope ' => $ second ,
1313+ 'value ' => true ,
1314+ ], $ events );
1315+ }
1316+
1317+ public function test_it_dispatches_events_when_deactivating_multiple_features_and_scopes ()
1318+ {
1319+ Event::fake ([FeatureUpdated::class]);
1320+
1321+ $ first = new User (['id ' => 1 ]);
1322+ $ second = new User (['id ' => 2 ]);
1323+
1324+ Feature::for ([$ first , $ second ])->deactivate (['foo ' , 'bar ' ]);
1325+
1326+ Event::assertDispatchedTimes (FeatureUpdated::class, 4 );
1327+
1328+ $ events = [];
1329+ Event::assertDispatched (function (FeatureUpdated $ event ) use (&$ events ) {
1330+ $ events [] = [
1331+ 'feature ' => $ event ->feature ,
1332+ 'scope ' => $ event ->scope ,
1333+ 'value ' => $ event ->value ,
1334+ ];
1335+
1336+ return true ;
1337+ });
1338+
1339+ $ this ->assertCount (4 , $ events );
1340+ $ this ->assertContains ([
1341+ 'feature ' => 'foo ' ,
1342+ 'scope ' => $ first ,
1343+ 'value ' => false ,
1344+ ], $ events );
1345+ $ this ->assertContains ([
1346+ 'feature ' => 'foo ' ,
1347+ 'scope ' => $ second ,
1348+ 'value ' => false ,
1349+ ], $ events );
1350+ $ this ->assertContains ([
1351+ 'feature ' => 'bar ' ,
1352+ 'scope ' => $ first ,
1353+ 'value ' => false ,
1354+ ], $ events );
1355+ $ this ->assertContains ([
1356+ 'feature ' => 'bar ' ,
1357+ 'scope ' => $ second ,
1358+ 'value ' => false ,
1359+ ], $ events );
1360+ }
12711361}
12721362
12731363class MyFeature
0 commit comments