Skip to content

sanjayshiwakoti/Testable_Code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Writing Testable code in PHP

This repository contains step by step source code demonstration for rewriting and refactoring code to make it loosely coupled and testable

Instructions

# Install composer dependencies phpunit, mockery adn symfony/var-dumper
$ composer install

# Run tests
$ phpunit

Steps

Start by cloning the master branch that consists of untestable code and checkout to respective branches step-1, step-2 and so on.

  1. Refactor using Dependency Injection and SOLID principles properly and make it testable [step-1]
  2. Organize the namespaces and directory structure [step-2]
  3. Build concrete implementations of interfaces [TODO]

Things to consider

While coding ensure these principles are not violated in order to make code testable, maintainable and loosely coupled.

  • DRY (Don't Repeat Yourself)
  • SOLID principles
    • Single Responsibility Principle
    • Open/Closed Principle
    • Liskov substitution principle
    • Interface segregation principle
    • Dependency inversion principle
  • Dependency Injection
  • Separation of Concerns
  • Ioc Containers (Optional)

Useful Links and videos

Please go through these blog posts and videos to get a nice grasp of how to write testable code in PHP.

Testable_Code

About

Test for Testable Code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published