Skip to content

DeGraciaMathieu/interface-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to test an interface

It is difficult to test an interface directly because it contains signatures and not behaviors.

We could create as many test classes as there are implementations of an interface, but this would be time-consuming and potentially bug-inducing.

An effective solution is to separate the business logic of an interface from the implementation details.

image

  • AbstractUserRepository contains the test methods and various assertions, e.g. : "it_able_to_find_user_by_id"; they do not contain any implementation-specific logic.
  • UserRepositoryInMemoryTest and UserRepositoryInSessionTest contain only the instantiation logic of the implementations; they do not contain any test logic.

This separation enhances the reliability and relevance of the tests and allows behaviors to be assigned to interfaces.

About

How to test an interface with phpunit

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages