getMockBuilder(MockStartEvent::class)->setMethods(['mockMethod'])->getMock(); $mock->expects($this->once())->method('mockMethod'); Events::addListener(array($mock, 'mockMethod'), 'coreStartEvent', Priority::NORMAL); $factory = new Factory; $factory->initFactory(); } } class MockStartEvent { public function mockMethod(): void {} }