While developing an application I try to keep the code separated. I also love testing and one wonderful tool which helps me produce good quality code is phpspec. The issue is what by default it keeps all the tests in the root directory.
phpspec requires some configuration to keep the tests where they belong. You might notice that I'm using Symfony framework for my application. When you do DDD development the framework used isn't that important. My domain login is kept in
src/Domain directory & infrastructure code is kept as bundles in
The following configuration is required to make phpspec work correctly (finding specs, creating/updating specs, running specs):
suites: core_suite: namespace: Domain\Core psr4_prefix: Domain\Core spec_path: src/Domain/Core src_path: src/Domain/Core spec_prefix: Spec user_infrastructure_suite: namespace: UserBundle psr4_prefix: UserBundle spec_path: src/UserBundle src_path: src/UserBundle spec_prefix: Spec user_suite: namespace: Domain\User psr4_prefix: Domain\User spec_path: src/Domain/User src_path: src/Domain/User spec_prefix: Spec
Save the file as
phpspec.yml in root directory.
If you would run:
phpspec describe Domain/User/ValueObject/UserName
It should create a file
Some lines in suites might look like duplication, but I found that you have to set all the options. Otherwise there are issues with file creation/updating. You could skip
spec_prefix option if you don't mind specifications directory in lowercase.