This repository contains step by step source code demonstration for rewriting and refactoring code to make it loosely coupled and testable
# Install composer dependencies phpunit, mockery adn symfony/var-dumper
$ composer install
# Run tests
$ phpunit
Start by cloning the master branch that consists of untestable code and checkout to respective branches step-1, step-2 and so on.
- Refactor using Dependency Injection and SOLID principles properly and make it testable [step-1]
- Organize the namespaces and directory structure [step-2]
- Build concrete implementations of interfaces [TODO]
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)
Please go through these blog posts and videos to get a nice grasp of how to write testable code in PHP.
- https://laracasts.com/collections/solid-principles
- http://fabien.potencier.org/what-is-dependency-injection.html
- https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design
- http://code.tutsplus.com/tutorials/how-to-write-testable-and-maintainable-code-in-php--net-31726
- http://code.tutsplus.com/tutorials/dependency-injection-huh--net-26903
- https://laracasts.com/collections/testing-in-php
- http://www.martinfowler.com/articles/injection.html
- http://doctrine-orm.readthedocs.org/projects/doctrine-dbal/en/latest/reference/configuration.html