01 - Preheat oven to 375°F (190°C). Lightly grease a 9x13-inch baking dish.
02 - Bring a large pot of salted water to a rolling boil. Add the pasta and cook until it reaches the al dente stage according to package directions. During the final 2 minutes of the pasta's cooking time, add the trimmed and cut green beans to the boiling water. Drain the pasta and green beans together and set aside.
03 - In a large skillet set over medium heat, melt the unsalted butter. Add the diced yellow onion and sauté for approximately 3 minutes, or until softened. Introduce the sliced mushrooms and continue to cook for an additional 5 minutes, until they have browned. Stir in the minced garlic and cook for 1 minute more.
04 - Evenly sprinkle the all-purpose flour over the vegetables in the skillet. Stir the flour into the vegetables to ensure they are coated. Gradually whisk in the whole milk and vegetable broth, stirring continuously to prevent any lumps from forming.
05 - Bring the sauce mixture to a gentle simmer and continue to cook for 4–5 minutes, stirring occasionally, until it has noticeably thickened. Incorporate the grated Parmesan cheese, dried thyme, ground black pepper, salt, and ground nutmeg. Taste the sauce and adjust the seasonings if necessary.
06 - Add the drained pasta and green beans to the skillet containing the sauce. Alternatively, if using a separate large bowl, transfer the sauce to it and add the pasta and green beans. Mix thoroughly to ensure all components are well combined.
07 - Pour the combined pasta, vegetable, and sauce mixture into the prepared baking dish. Distribute the crispy fried onions evenly over the top. If using, sprinkle the grated sharp cheddar cheese over the onions.
08 - Place the baking dish in the preheated oven and bake for 20–25 minutes. The casserole is ready when the topping is golden brown and the contents are bubbling.
09 - Remove the casserole from the oven and allow it to rest for 5 minutes before serving. This allows the sauce to set slightly.