1616use Cake \TestSuite \TestCase ;
1717use InvalidArgumentException ;
1818use Muffin \Trash \Model \Behavior \TrashBehavior ;
19+ use PHPUnit \Framework \Attributes \DataProvider ;
1920
2021class TrashBehaviorTest extends TestCase
2122{
@@ -58,7 +59,7 @@ public function setUp(): void
5859
5960 $ this ->CompositeArticlesUsers = $ this ->getTableLocator ()->get (
6061 'Muffin/Trash.CompositeArticlesUsers ' ,
61- ['table ' => 'trash_composite_articles_users ' ]
62+ ['table ' => 'trash_composite_articles_users ' ],
6263 );
6364 $ this ->CompositeArticlesUsers ->addBehavior ('Muffin/Trash.Trash ' );
6465
@@ -129,7 +130,7 @@ public function testBeforeFindWithTrashFieldInComparison()
129130 $ query = $ this ->Articles ->find ('all ' );
130131
131132 $ result = $ query ->where (
132- [$ this ->Articles ->aliasField ('trashed ' ) . ' >= ' => new DateTime ('-1 day ' )]
133+ [$ this ->Articles ->aliasField ('trashed ' ) . ' >= ' => new DateTime ('-1 day ' )],
133134 )->toArray ();
134135 $ this ->assertCount (2 , $ result );
135136 }
@@ -179,7 +180,7 @@ function (Event $event, EntityInterface $entity, ArrayObject $options) {
179180 $ entity ->setError ('id ' , 'Save aborted ' );
180181 $ event ->setResult (false );
181182 $ event ->stopPropagation ();
182- }
183+ },
183184 );
184185
185186 $ result = $ this ->Articles ->delete ($ article );
@@ -223,15 +224,15 @@ function (Event $event, EntityInterface $entity, ArrayObject $options) use (&$ha
223224 if (isset ($ options ['deleteOptions ' ])) {
224225 $ hasDeleteOptionsBefore = true ;
225226 }
226- }
227+ },
227228 );
228229 $ this ->Comments ->getEventManager ()->on (
229230 'Model.afterDelete ' ,
230231 function (Event $ event , EntityInterface $ entity , ArrayObject $ options ) use (&$ hasDeleteOptionsAfter ) {
231232 if (isset ($ options ['deleteOptions ' ])) {
232233 $ hasDeleteOptionsAfter = true ;
233234 }
234- }
235+ },
235236 );
236237
237238 $ article = $ this ->Articles ->get (1 );
@@ -265,24 +266,24 @@ function (Event $event, EntityInterface $entity, ArrayObject $options) use (&$ma
265266 if (isset ($ options ['deleteOptions ' ])) {
266267 $ mainHasDeleteOptions = true ;
267268 }
268- }
269+ },
269270 );
270271 $ this ->Comments ->getEventManager ()->on (
271272 'Model.beforeSave ' ,
272273 function (
273274 Event $ event ,
274275 EntityInterface $ entity ,
275- ArrayObject $ options
276+ ArrayObject $ options,
276277 ) use (
277278 &$ dependentHasDeleteOptions ,
278- &$ dependentIsNotPrimary
279+ &$ dependentIsNotPrimary,
279280 ) {
280281 if (isset ($ options ['deleteOptions ' ])) {
281282 $ dependentHasDeleteOptions = true ;
282283 }
283284
284285 $ dependentIsNotPrimary = $ options ['_primary ' ] === false ;
285- }
286+ },
286287 );
287288
288289 $ article = $ this ->Articles ->get (1 );
@@ -329,7 +330,7 @@ public function testTrash()
329330 $ this ->getTableLocator ()
330331 ->get ('ArticlesUsers ' , ['table ' => 'trash_articles_users ' ])
331332 ->find ()
332- ->count ()
333+ ->count (),
333334 );
334335 }
335336
@@ -595,24 +596,24 @@ function (Event $event, EntityInterface $entity, ArrayObject $options) use (&$ma
595596 if (isset ($ options ['restoreOptions ' ])) {
596597 $ mainHasRestoreOptions = true ;
597598 }
598- }
599+ },
599600 );
600601 $ this ->Comments ->getEventManager ()->on (
601602 'Model.beforeSave ' ,
602603 function (
603604 Event $ event ,
604605 EntityInterface $ entity ,
605- ArrayObject $ options
606+ ArrayObject $ options,
606607 ) use (
607608 &$ dependentHasRestoreOptions ,
608- &$ dependentIsNotPrimary
609+ &$ dependentIsNotPrimary,
609610 ) {
610611 if (isset ($ options ['restoreOptions ' ])) {
611612 $ dependentHasRestoreOptions = true ;
612613 }
613614
614615 $ dependentIsNotPrimary = $ options ['_primary ' ] === false ;
615- }
616+ },
616617 );
617618
618619 $ result = $ this ->Articles ->getBehavior ('Trash ' )->cascadingRestoreTrash ($ article , [
@@ -690,7 +691,7 @@ public function testCascadingUntrashEntity()
690691
691692 $ this ->assertInstanceOf (
692693 EntityInterface::class,
693- $ this ->Articles ->getBehavior ('Trash ' )->cascadingRestoreTrash ($ article )
694+ $ this ->Articles ->getBehavior ('Trash ' )->cascadingRestoreTrash ($ article ),
694695 );
695696
696697 $ article = $ this ->Articles
@@ -766,7 +767,7 @@ public function testCascadingUntrashAll()
766767 $ this ->assertNotEmpty ($ article ->composite_articles_users [0 ]->trashed );
767768 $ this ->assertInstanceOf (DateTime::class, $ article ->composite_articles_users [0 ]->trashed );
768769
769- $ this ->assertEquals (8 , $ this ->Articles ->getBehavior ('Trash ' )->cascadingRestoreTrash ());
770+ $ this ->assertEquals (3 , $ this ->Articles ->getBehavior ('Trash ' )->cascadingRestoreTrash ());
770771
771772 $ article = $ this ->Articles
772773 ->find ()
@@ -903,7 +904,7 @@ public function testGetTrashFieldSchemaIntrospection()
903904 {
904905 $ this ->assertEquals (
905906 'Articles.trashed ' ,
906- $ this ->Articles ->behaviors ()->get ('Trash ' )->getTrashField ()
907+ $ this ->Articles ->behaviors ()->get ('Trash ' )->getTrashField (),
907908 );
908909 }
909910
@@ -923,11 +924,11 @@ public function testImpEInvalidArgumentException()
923924 /**
924925 * Test the implementedEvents method.
925926 *
926- * @dataProvider provideConfigsForImplementedEventsTest
927927 * @param array $config Initial behavior config.
928928 * @param array $implementedEvents Expected implementedEvents.
929929 * @return void
930930 */
931+ #[DataProvider('provideConfigsForImplementedEventsTest ' )]
931932 public function testImplementedEvents (array $ config , array $ implementedEvents )
932933 {
933934 $ trash = new TrashBehavior ($ this ->Users , $ config );
@@ -942,6 +943,9 @@ public function testImplementedEvents(array $config, array $implementedEvents)
942943 */
943944 public static function provideConfigsForImplementedEventsTest ()
944945 {
946+ $ callable = function () {
947+ };
948+
945949 return [
946950 'No event config inherits default events ' => [
947951 [],
@@ -1001,8 +1005,7 @@ public static function provideConfigsForImplementedEventsTest()
10011005 [
10021006 'events ' => [
10031007 'Model.beforeDelete ' => [
1004- 'callable ' => function () {
1005- },
1008+ 'callable ' => $ callable ,
10061009 ],
10071010 'Model.beforeFind ' => [
10081011 'callable ' => ['' , 'beforeDelete ' ],
@@ -1012,8 +1015,7 @@ public static function provideConfigsForImplementedEventsTest()
10121015 ],
10131016 [
10141017 'Model.beforeDelete ' => [
1015- 'callable ' => function () {
1016- },
1018+ 'callable ' => $ callable ,
10171019 ],
10181020 'Model.beforeFind ' => [
10191021 'callable ' => ['' , 'beforeDelete ' ],
0 commit comments