Refactored the ContextualUnitTest unit test class to use a data provider. Also ran phpcs across the class and fixed a couple of small issues. Closes #3185183