Why Lithium is Worth a Look

lithium-largeThere is no time like the present to start working on a New Year’s Resolution.  Unfortunately, I had no intention of doing that today, I had a completely different agenda which was derailed from the word “go”.  It started with trying to get Xdebug up and running on my Macbook with Mountain Lion and AMPPS.  I must have gone through the build process 20 times before it finally started working because I found someone else who had created a folder full of .so files and I just started running through them until they worked.  But I digress…

One of my resolutions is to launch a project this year which will essentially start with a port of something I wrote last year into a standalone application, then I will build on it from there.  I have been working on the Roadmap and EER Model for it, and today I wanted to start thinking about how I wanted to develop it.  As it happens, the first tweet I saw this morning was from Chris Hartjes, and as I was reading through a bunch of stuff this morning, I really started thinking that maybe the best thing for this project would be to use test driven development.

From there, the next thought became, “Ok, what framework am I going to use?”.  I had already made up my mind earlier that I was going to do it on CodeIgniter, and I started trying to get PHPUnit working with it, and it really just was not going well.  Then I started thinking about a host of other things I wanted to consider for this app.  Namespaces and better autoloading for things like static methods were on that list, neither of which were going to work out very well on a CodeIgniter platform.  Don’t get me wrong, I still love using CodeIgniter, and when it comes to getting something up and running in a hurry to meet an urgent need or deadline, it is absolutely my go-to framework.    But, when thinking about the sheer complexity of this particular app, I definitely wanted to have every tool available to me that PHP and frameworks in general have to offer.

Enter my New Year’s Resolution.  I promised myself that I would pick up another framework this year and I had been introduced to Lithium at Codeworks in a presentation given by Elizabeth Naramore several months ago.  So I downloaded it, and went through the obligatory blog tutorial, all of which seemed pretty straightforward.  Ok, so chances are I can actually use Lithium and not feel like a complete idiot.  So now let’s go through the checklist for my app:

  • Autoloading:  Native and PSR compliant as far as I can tell.  Cannot ask for much more than that.
  • Namespaces:  Yep, integral to the system and the directory structure revolves around it. Exactly what I was looking for.  Check!
  • Integration with PHPUnit: NO!…Not needed, as Lithium has an integral testing framework, native to the system and the core code has 90%+ test coverage.

Ok, so this looks promising.  Now for the rest of the stuff I use when developing:

  • phpCodesniffer:  Are there sniffs for Lithium’s coding style recommendations?  Couldn’t find any…and again, it doesn’t matter.  Lithium has its own plugin for code QA that checks for coding style violations, and the GUI for this is woven into the unit testing GUI.
  • APIGen:  Lithium has a plugin for this as well, no need to manage it separately.
  • phpmd (Mess Detector):  Cyclomatic complexity checks are integral to the Lithium unit testing feature.
  • Command line tools:  Built into Lithium. And I love that I can use the CLI to generate the classes for testing each model.

What impresses me about Lithium?  I can see that I will spend less time flipping back and forth between tools because 4 of the ones I currently work with are either built in or are a plugin.  Also it is a PHP 5.3+ only framework.  This tells me that the devs on this project want to have all tools available to them to produce a framework.  And they seem to have done it very well.  Also, it seems like the CRUD tools available in Lithium are pretty powerful, and I can see where putting models together for an app is going to be quick, especially if you name your tables so that Lithium will default to them based on class name.  I like the use of static methods in Lithium as well.  It is well done and promotes speed of development.

Where does Lithium fall short?  The User Guide needs a bit of help.  It is a little hard to follow, and there are some things that the user guide assumes you know, or  you already read somewhere else in the guide.  It also seems to allude to other functionality available, but then doesn’t give a lot of detail.  This seems to be particularly true for data retrieval.  I think that beginning and intermediate programmers may be a little frustrated at first.  That said, I still think it is worth the time and the effort to get to know Lithium better.  The framework shows a lot of promise, and the architecture of it leaves me with the impression that the devs spent a lot of time thinking through what a developer needs to get the job done quickly.

I can definitely see some tutorial posts and more info on Lithium’s features in the near future!



, ,

  1. #1 by Juan Treminio on January 2, 2013 - 2:09 pm

    I cannot overstate how silly it is for a framework to create its own unit testing library when you have the much more mature, thorough and industry-standard PHPUnit.

    • #2 by Andrew on January 2, 2013 - 3:03 pm

      Hi Juan, thanks for the reply. I can certainly understand that perspective, and it makes a lot of sense. I guess one of the things that I found was good about it was that removing the requirement of dealing with a 3rd party library might encourage people to do testing who otherwise wouldn’t since the time spent setting it up was already taken care of. I think that like several other built-in solutions, as a dev becomes more and more advanced at it, they eventually may hit a ceiling and decide to move out to a more robust tool that gives more flexibility if needed. Thanks again for visiting & commenting!

    • #3 by daschl on January 3, 2013 - 12:55 pm

      Nothing prevents you from using PHPUnit if you prefer it! Its just much more integrated into the framework and I’ll promise you’ll like it when you try.

      If the wheel you reinvent is arguably better, then its worth the effort. And don’t forget you can put on your own “industry standard” wheels when it gets bumpy.

      • #4 by Andrew on January 3, 2013 - 1:57 pm

        Agreed, and thanks so much for stopping by!

    • #5 by Tom on January 3, 2013 - 7:03 pm

      Um, because a test suite that is customized to the framework could end up doing a better job… Or, because there’s less maintenance in keeping up to date with PHPUnit changes… Or… I understand the logic of not re-inventing the wheel, but sometimes there’s simply altogether different wheels for different cars. Though if you want to go ahead and put those wheels on Lithium no one is stopping you. I think one of the biggest reasons why it comes bundled with the framework is to get more people to pay attention and write testable code. Breaking down barriers.

      • #6 by Andrew on January 3, 2013 - 7:05 pm

        Tom, I definitely like the idea of anything that makes it easier to test and get used to the idea of unit testing, especially since the topic is such a timely one these days. Thanks for stopping by and posting a comment!

    • #7 by Nate Abele on January 4, 2013 - 11:49 am

      Juan: I’m sorry you get offended when people make choices or have priorities that are different from yours.

  2. #8 by Mariano Iglesias on January 3, 2013 - 12:54 pm

    IF there’s one thing lithium excels at is its flexibility. There’s no reason why you couldn’t use PHPUnit on your li3 app. In fact at http://www.workana.com I use li3 as the main framework, doctrine2 for the data layer, and PHPUnit for testing

    • #9 by Andrew on January 3, 2013 - 1:57 pm

      Thanks a bunch for reading and commenting

  3. #10 by gwoo on January 3, 2013 - 1:43 pm

    Andy, you nailed it. You realized why it was important to make testing, qa, etc part of the core. You can always add phpunit if you want the “industry standard”, of course there is a plugin for that. Get started fast, code an app in an hour, with all the tools you need. $simple = true. Maybe we should mention though that the Lithium web dashboard is un-paralleled, the cli test command is optimized for travis-ci, and it runs way faster in some naive tests. All that for under a few hundred kilobytes. I think it’s pretty obvious why we built things the way we did. In any case, I look forward to seeing your progress. Help us with the guide! We need you. Make sure you stop by #li3 on freenode.

    • #11 by Andrew on January 3, 2013 - 1:56 pm

      Thanks for the comment, I was the guy on IRC last night offering to help :) I hate being the guy who complains and then doesn’t get involved. First PR will be coming soon!

Comments are closed.