Hi Tim, I dont know the exact behaviour you're trying to test, so this may not be useful.
However, when it comes to behat, you should be testing the behaviour you're expecting your users to experience. In the event of an error, would it not be better to catch the exception and display a meaningful error message to the user (which you can then test for), rather than showing them an uncaught exception?
You can also test the options of your plugins using PHPUnit
1. where you expect an exception:
$this->expectExceptionMessage('Course or activity not accessible. (Not enrolled)');
function_that_throws_an_exception($course, $user, $module);
2. or providing wrong parameters:
$this->expectExceptionMessage('Invalid number of parameters');
Perhaps it will not pass a review of nice code, but it is possible to test code that is not encapsulated by a function:
global $CFG, $PAGE;
$course = $this->getDataGenerator()->create_course();
$_POST['id'] = 89;
include_once($CFG->dirroot . '/local/plugin/view.php');
However, in this case, I wouldn't. As Martin Fowler would say (I think that is the right attribution) there is only point writing test to catch mistakes you will actually make. Here, having a Behat test to catch the happy path is probably all you need, and probably all your Behat tests will cover that.