GithubHelp home page GithubHelp logo

tdd-ddd-php's Introduction

Test Driven PHP With PHPUnit

This is a simple PHP application that was built using TDD and the principles of Domain Driven Design.

Description of the application

This application is an exciting console app where a lone fisherman on a lone pond catches fish on every third cast.

The fish are persisted in the database. The fisherman plays for keeps, so everytime the fisherman catches a fish, it is deleted from the database. A domain service is in charge of stocking the pond with fish when the application starts.

Domain

The domain holds the fish entity, the fish repository interface, the service responsible for stocking the pond, and our lone fisherman and pond services.

Infrastructure

The infrastructure layer contains our fish repository implementation and a Vendors directory that contains the Doctrine2 library.

Test

The test directory is broken up into two groups: unit tests and integration tests.

The unit tests were used to drive the design for everything in the domain layer. These tests make heavy use of PHPUnit mock objects and assertions.

The integration tests test the implementation of the fish repository. These tests make use of the PHPUnit database extension to setup tables and actual rows to test against.

app.php

Rather than use a full blown presentation layer, this application has one presentation, and it is represented by the app.php file. This is the application that can be run using the command:

php app.php

Running the tests

You will need phpunit and the phpunit DB extension installed. This can be done with a couple easy pear commands:

pear config-set auto_discover 1

pear install pear.phpunit.de/PHPUnit

pear install phpunit/DbUnit

In order to run all the tests you will need mysql and phpunit installed. The tests assume a database called "letsgofishing", but you can name it something else if you update the appropriate config files.

If you plan on running the app before the tests, you will also need to create a table called "fish". If you run the tests first, the table will be created for you.

To run the tests you will need to invoke the test runner with the bootstrap file and the configuration file:

phpunit --bootstrap Test/bootstrap.php --configuration Test/phpunit.xml Test/

tdd-ddd-php's People

Contributors

brianium avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.