Remove layers from canvas before they get deleted

I was running into an error message when running some of the tests: Object::disconnect: Unexpected null parameter

example:
#244 Generated layers are not added to the map registry. ... Object::disconnect: Unexpected null parameter

#245 Check that the post processor does not add spurious report rows. ... Object::disconnect: Unexpected null parameter


From my basic understanding this happens when the canvas tries to use some stored layer pointers but the layers have  already been deleted (in the test cases we load/delete a series of test layers)
Would it make sense to reset the canvas layer list when all layers are removed (which is the what we do in the tests)?  
The current patch seems to fix the "error", but I am not sure if it is the appropriate patch to do.