1- <?php namespace CodeIgniter \Events ;
1+ <?php
2+ namespace CodeIgniter \Events ;
23
34use CodeIgniter \Config \Config ;
45use Tests \Support \Events \MockEvents ;
56
67class EventsTest extends \CIUnitTestCase
78{
9+
810 /**
911 * Accessible event manager instance
1012 */
@@ -16,17 +18,21 @@ protected function setUp()
1618
1719 $ this ->manager = new MockEvents ();
1820
19- $ config = config ('Modules ' );
20- $ config ->activeExplorers = [];
21- Config::injectMock ('Modules ' , $ config );
22-
2321 Events::removeAllListeners ();
2422 }
2523
2624 //--------------------------------------------------------------------
2725
26+ /**
27+ * @runInSeparateProcess
28+ * @preserveGlobalState disabled
29+ */
2830 public function testInitialize ()
2931 {
32+ $ config = config ('Modules ' );
33+ $ config ->activeExplorers = [];
34+ Config::injectMock ('Modules ' , $ config );
35+
3036 // it should start out empty
3137 $ default = [APPPATH . 'Config/Events.php ' ];
3238 $ this ->manager ->setFiles ([]);
@@ -40,19 +46,26 @@ public function testInitialize()
4046 // but we should be able to change it through the backdoor
4147 $ this ->manager ::setFiles (['/peanuts ' ]);
4248 $ this ->assertEquals (['/peanuts ' ], $ this ->manager ->getFiles ());
49+
50+ // re-initializing should have no effect
51+ Events::initialize ();
52+ $ this ->assertEquals (['/peanuts ' ], $ this ->manager ->getFiles ());
4353 }
4454
4555 //--------------------------------------------------------------------
4656
47- // Not working currently - might want to revisit at some point.
48- // public function testPerformance()
49- // {
50- // $logged = Events::getPerformanceLogs();
51- // // there should be a few event activities logged
52- // $this->assertGreaterThan(0,count($logged));
53- //
54- // // might want additional tests after some activity, or to inspect what has happened so far
55- // }
57+ public function testPerformance ()
58+ {
59+ $ result = null ;
60+ Events::on ('foo ' , function ($ arg ) use (&$ result ) {
61+ $ result = $ arg ;
62+ });
63+ Events::trigger ('foo ' , 'bar ' );
64+
65+ $ logged = Events::getPerformanceLogs ();
66+ // there should be some event activity logged
67+ $ this ->assertGreaterThan (0 , count ($ logged ));
68+ }
5669
5770 //--------------------------------------------------------------------
5871
0 commit comments