Testing abstract classes without creating child object

testing abstract class
Share on facebook
Share on twitter
Share on linkedin

Abstract classes can contain concrete methods which should be tested. One way to do it would be to create child class of the abstract class and test that one.

Let’s imagine that we have abstract class Person

While we are testing this class, usually we would create for example class Doctor which extends Person

so test would look like:

However there’s more elegant way to test abstract class without creating unnecessary child object:

More info about mocking abstract classes and traits can be found here.

Subscribe to our newsletter

Be first to read new helpful post

Share this post with your friends

Share on linkedin
Share on xing
Share on twitter
Share on facebook
composer Blog Title Image

10 Tips for PHP Composer

  1. Add the composer.lock and the composer.json to Git.

Composer install will install all the packages you have defined in your composer.lock file.

Changing enum column in Laravel migration

Changing enum type columns is currently not supported in Laravel, and if you try to run something like:

You are about to get following

Leave a Reply

Notify of