8

I use git with submodules, and I've hard time to figure out how to organize my files. I develop in PHP, and use unit testing. So right now, I use this organization for each module:

  • src/
  • tests/

That seems like a brilliant idea, but the problem is that when I do a "git submodule add" to a project, I'll have that path: project/modules/News/src/index.php

The src/ folder is really problematic.

Should I simply put all my file in the module root, and have a tests/ folder mixed in the source ? To me that sound bad. What are you doing ?

Edit: The src/ Folder is problematic because of the autoload. I should not have to put "src" in all my class name...

1
  • Question about the Edit: The problem is that you want classnames matching to the folder structure. Ofc each Module should also have it's own tests and that is a problem because you can't include (like BarModule/src => module/Bar) with git submodules? (just checking that i get your requirements rights) Commented Mar 29, 2011 at 16:28

3 Answers 3

4

Your folder layout is mostly irrelevant as long as the autoloader can find your files somehow. If you are using PEAR convention for mapping class names to their source files, you can add the src directory to the include path or stack a second autoloader. Then you dont have to add src to the class names.

The alternative to PEAR convention would be to use a static mapping between files and classes. There is a tool that can automatically generate such an autoloader for you at GitHub.

The static autoloader approach is also used in PHP Project Wizard. That tool will create src and tests folders, including your phpunit config and the build file to connect your project with Jenkins CI. It's a convenient package.

As for including submodules, consider putting them into a lib or ext folder. An example of how that looks can be found in the phpdox project at GitHub. Make sure you also look at the main bootstrap file to see how to include the various autoloaders then.

Sign up to request clarification or add additional context in comments.

2 Comments

You're right, except that I can have 30+ modules in a project. So I'll to stack 30+ autoloaders, wouldn't that be terrible ? I already know (and collaborate) to the phpdox project ;) But that's not the same kind of submodule. In my case a submodule will be more like a wordpress plugin. Also this project must be php 5.2 :(
@FMaz008 why dont you just use TheSeer's PHPAB and let it iterate over the entire projects, including your 30 submodules and use that single autoloader then? IIRC PHPAB has a template for 5.2 as well, so version shouldnt be an issue.
3

What I did when faced with this problem was to create a folder called vendors and place all the submodules into that. Then I symlinked using relative paths the directories to the locations I wanted them in my code. You can commit the symlinks to git and they will still work when other pull the repository. Of course this only works if you are using a *nix based OS.

For example:

modules/
vendor/module1/src/

Could be symlinked like so (from the modules directory):

ln -s ../vendor/module1/src module1

Not sure if this solves your problem or not.

1 Comment

Some versions of Windows have something like symlinks, you could try them. I don't develop on Windows so I have never tried.
0

I would not have the tests in a separate module. Keep it in the same repository.

1 Comment

I've never planed to put my test in a different repository. All module are bundled with their own tests.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.