ShrimPHP

Posted 2012-08-23
Written by Matt Frost
Category code

ShrimPHP is a project I started to practice the Test Driven Development skills I have been gathering. I figured I'd do a framework because while I have plenty of experience interacting with Zend, CodeIgniter and things of the sort; writing your own routing classes, controllers and view classes help to clarify those concepts a little bit more.

Why?

I know the last thing that the eco-system needs is another framework, there are great frameworks out there and they should be used if they fit the needs you have. Personally, I've run into situations where I start prototyping and all I really need is logic/presentation separation. Using Zend FW is overkill for what I need; so I've made this to keep everything really basic. Don't view this as an attempt to change the world, just an attempt to understand it a little bit more. Once something gets beyond the prototype stage, I'd be forced with the decision to add on to this or use a more mature framework.

Technical Stuff

As I mentioned, I started this project as a way to practice to Test Driven Development. So I started writing my tests based on what I wanted the code to do and then simply made my code do it. What excites me about that is that even in the areas where I made faulty assumptions, I have the tests in place. As the assumptions change, I can change the tests to help prevent technical debt from creeping in.

I wrote all my unit tests for PHPUnit and practiced the very meticulous process of writing a test line, testing, writing code for that line, testing and continuing that process over and over. To avoid tightly coupling the components, I made use of the dependency injection to manage all the dependencies. This prevents a class from creating other objects by instantiating them within a method. As you may have noticed, I also got Selenium up and running yesterday, so I'll be writing the integration tests that I need using PHPUnit_Selenium.

What now?!

As I mentioned, I'm certainly not trying to change the world; but I am looking for feedback on the way I did certain things. This project has been a learning experience and what better way to learn than to get feedback from other really smart developers? Feedback on how I wrote my tests, the strategy I used in certain areas of the codebase or things that I got sloppy with all come to mind. So if you've got a few minutes to spare; I'd love to hear what you think. ShrimPHP on Github

Comments

Gravatar
Jc

2012-11-21

have look at silex, for simple presentation/logic separation for quick and dirty pages it's perfect :) You can even reasonably grow with it...

Let me give you an example: a hosting company I worked for was switching its dns hosted domains to dnssec on a certain deadline. Customers had an option to opt out from this switch, so I had to do a quick app for this. Silex would be perfect - its a simple information gathering app and you are 99% sure that you won't add any features and you'll throw it away on the switchover deadline anyway.

But if you do your logic in classes and templates in twig for example, you wouldn't have any problem switching the app to symfony should it start growing beyond a point where having a real framework with common conventions, etc. starts saving time. So even if you did it in silex, its only a light refactoring to move it elsewhere.

From what I found out though, starting even a tiny symfony2 projects takes almost no ammount of time, you just go through a checklist and could have it running in a few hours. So really, I'd use silex for anything I'm 99% sure I won't need to expand much.

I guess the moral of this post is to try to write reasonably 'detachable' code (with clear external dependency integration points). When you do, you can use pretty much anything and not bang your head later.

Posting comments after has been disabled.