Skip to content

Commit d6b5723

Browse files
committed
Fixing event test that only occurred when all tests were ran in sequence.
1 parent 78a09a1 commit d6b5723

3 files changed

Lines changed: 15 additions & 16 deletions

File tree

system/Events/Events.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,11 @@ class Events
8787

8888
/**
8989
* Ensures that we have a events file ready.
90-
*
91-
* @param string|null $file
9290
*/
93-
public static function initialize(string $file = null)
91+
public static function initialize()
9492
{
9593
// Don't overwrite anything....
96-
if (self::$initialized)
94+
if (static::$initialized)
9795
{
9896
return;
9997
}
@@ -120,7 +118,7 @@ public static function initialize(string $file = null)
120118
include $file;
121119
}
122120

123-
self::$initialized = true;
121+
static::$initialized = true;
124122
}
125123

126124
//--------------------------------------------------------------------

tests/_support/Events/MockEvents.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,8 @@ public function getSimulate()
5959
return self::$simulate;
6060
}
6161

62+
public function unInitialize()
63+
{
64+
static::$initialized = false;
65+
}
6266
}

tests/system/Events/EventsTest.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,29 @@ public function setUp()
1616

1717
$this->manager = new MockEvents();
1818

19+
$config = config('Modules');
20+
$config->activeExplorers = [];
21+
Config::injectMock('Modules', $config);
22+
1923
Events::removeAllListeners();
2024
}
2125

2226
//--------------------------------------------------------------------
2327

2428
public function testInitialize()
2529
{
26-
$config = config('Modules');
27-
$config->activeExplorers = [];
28-
Config::injectMock('Modules', $config);
29-
3030
// it should start out empty
3131
$default = [APPPATH . 'Config/Events.php'];
32-
Events::setFiles([]);
32+
$this->manager->setFiles([]);
3333
$this->assertEmpty($this->manager->getFiles());
3434

3535
// make sure we have a default events file
36-
Events::initialize();
37-
$this->assertEquals($default, $this->manager->getFiles());
38-
39-
// and we should not be able to change it normally
40-
Events::initialize('abracadabra');
36+
$this->manager->unInitialize();
37+
$this->manager::initialize();
4138
$this->assertEquals($default, $this->manager->getFiles());
4239

4340
// but we should be able to change it through the backdoor
44-
Events::setFiles(['/peanuts']);
41+
$this->manager::setFiles(['/peanuts']);
4542
$this->assertEquals(['/peanuts'], $this->manager->getFiles());
4643
}
4744

0 commit comments

Comments
 (0)