Fix headers sent error in tests