RFC: Adding A Global Autoloader For Testing

Unknown
edited May 2020 in Core Vanilla

I have a PR out for adding a global autoloader for the purposes of testing.

The idea is to make all classes available in unit tests, regardless of whether or not addons are enabled.

My reasoning for this is that I think it will make writing addon unit tests easier. You can write your tests and know that all of your classes are there. Ideally, we write more unit tests than other tests and usually those don't need an extra installation of Vanilla. I see some tests manually requiring files; this change would make that unnecessary.

On the downside, this could lead to scenarios where tests pass, but production fails because of specific autoloading issues. This is something we'll have to decide on whether or not the benefits outweigh the side effects.

Another thing I encountered when making this change is problems with duplicate classes. If you look at my PR, I specifically exclude some plugins that caused this problem. These issues stemmed from two places:

  1. Plugins that have their own composer.json that include a duplicate vendor directory. In this case, we have changes in the works to bring these composer dependencies into the main vendor directory. If/when we make that change then this problem will go away.
  2. Some plugins just define duplicate classes. To me, this is a bad practice that we should work to avoid. Having this global autoloader will help us avoid this issue in the future as tests will now fail if we define duplicate classes. As we move towards everything being in a namespace then this type of issue should go away.

Anyway, let me know if you have any specific questions or objections about this proposal. You can react to this post, comment below, or even review the PR.