News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

NetTuts.com:
How to Write Testable and Maintainable Code in PHP
May 16, 2013 @ 11:53:18

NetTuts.com has a new tutorial posted suggesting a few ways you can make testable and maintainable code in PHP applications.

Frameworks provide a tool for rapid application development, but often accrue technical debt as rapidly as they allow you to create functionality. Technical debt is created when maintainability isn't a purposeful focus of the developer. Future changes and debugging become costly, due to a lack of unit testing and structure. Here's how to begin structuring your code to achieve testability and maintainability - and save you time.

There's a few concepts they cover in the tutorial including DRY (don't repeat yourself), working with dependency injection and actually writing the tests with PHPUnit. They start with a bit of code that needs some work and use the tests to help refactor it into something that can be easily mocked (using Mockery).

0 comments voice your opinion now!
testable maintainable code tutorial bestpractice mock object

Link: http://net.tutsplus.com/tutorials/php/how-to-write-testable-and-maintainable-code-in-php

Andrew Podner:
Make it Testable-No Matter how Painful it is
April 04, 2013 @ 09:39:27

In a new post Andrew Podner recommends that, as you're doing your day to day development, you try your hardest to create testable code, no matter how painful it is.

I look at the situation we have gotten into by having this problem [of replacing a large legacy application], and frankly, it is like the tech version of 'Scared Straight'. The paranoia of such a far reaching application within the enterprise that absolutely has to deploy successfully and also be very flexible to meet the needs of the future have driven me to the point of near madness in trying to make sure this thing is bulletproof, enter Test Driven Development.

He includes an example situation he recently was faced with in his code...and opted for the "easy" way out (difficult to test). He talks some about the issues, dependencies and coupled code this has created. He does, however, show a solution to the issue - passing in the dependencies as they're needed, not defining them in the method.

For me, writing custom apps in an enterprise environment is not about rapid deployment and looking like a hero. It is about deploying software with a design life of 7-10 years, because the change management involved in deployment is not something you want be be doing over and over again. Testable code with 100% coverage of unit tests, well developed integration testing, and prolific use of tools like PHPUnit & Selenium are part of the development culture because while speed is important, durability is even more critical to business.
0 comments voice your opinion now!
testable code unittest tdd testdriven refactor dependencies

Link: http://unassumingphp.com/make-it-testable-no-matter-how-painful-it-is/

Chris Hartjes:
So You Want to Write Tests
December 19, 2012 @ 09:07:26

Chris Hartjes has written up a new post for his site, So you want to write tests, giving a good overview of some of the things you'll need to consider when wanting to move into a more test-friendly development world.

I often get asked for some advice on how to get started with writing tests for your PHP code. It's a fair question, since I am presenting myself as an expert-ninja-rockstar-sensei-opinionated-egomaniac on the topic. I often struggle with coming up with an answer that can fit into the 140 characters available via Twitter, but clearly this is not a good strategy. As an early Christmas 2012 present to all my loyal followers, who put up with my never-ending stream of nonsense and provide a slowly-increasing portion of my income, here are my thoughts on how to get started with testing your PHP code.

He offers a list of suggestions, each with a bit of explanation:

  • Learn how to recognize untestable code
  • Keep learning the language
  • Chain units of code together for greatness
  • Start asking "how am I going to test this?"
  • Stop people from pushing code without proof it's fixed
  • Stop people from doing things manually
  • Stop using tools without test suites
  • Always wonder if you're doing it right
0 comments voice your opinion now!
unittest advice opinion testable application


Chris Hartjes:
The Birth of Grumpy Learning
December 03, 2012 @ 12:51:45

Chris Hartjes (aka "The Grumpy Programmer") has made a name for himself in the PHP community as a big proponent of testing of all sorts in web applications. He's taking things to the next level with his own "Grumpy Learning" grouping.

As I also create more products I need a place for them all to live. I have books, and now a course I can teach and I am planning on producing screencasts for sale as well. With that in mind, I am happy to announce I have created Grumpy Learning, an umbrella site for all my training and teaching efforts to hang from.

His first book covered writing testable application, his second book looks more specifically at using PHPUnit. His latest offering is a PHP Testing Bootcamp - a three-session guided look at some of the concepts he shares not only in his books but also from his own experience (January 3rd, 10th & 17th).

0 comments voice your opinion now!
unittest testing learning webinar testable application phpunit


Brandon Savage's Blog:
Book Review The Grumpy Programmer's Guide To Building Testable Applications
April 18, 2012 @ 10:53:45

On his blog Brandon Savage has a new post reviewing a book from Chris Hartjes, "The Grumpy Programmer's Guide To Building Testable Applications".

When most developers think about books on testing, they think about books that highlight things like "test driven development" or "how to build a test for X." [...] This is not true of Chris Hartjes' book, "The Grumpy Programmer's Guide To Building Testable PHP Applications". When I asked Chris if I could review his book, I expected a step-by-step guide to writing tests. What I got was a step-by-step guide to building an application that COULD be tested. There's a big difference, and it's important to understand the distinction.

He points out that the book provides more about good application structure than who to write the tests for it. It provides a guide to creating modular applications that can be easily pulled apart and tested as well as some practical examples. He also includes a few "wise words" quoted from the book including: "if it's not yours, wrap it up" and "testing is good; testable applications are better."

You can pick up your own copy of the book fron its page on the Leanpub site.

0 comments voice your opinion now!
book review testable applications chrishartjes


Qafoo Blog:
Webinar "Writing Testable Code"
March 21, 2012 @ 12:54:49

As Tobias Schlitt points out in this recent post to the Qafoo blog, the recording of a webinar he did (for Zend) about "Writing Testable Code" has been posted for listening online.

In this session you will gain insight into the secret of writing easily testable code and you'll learn how this relates essentially to good object orientation.

The recording is just one of many webinars Zend offers on a wide range of development topics, including:

Almost all presentations also come with PDF versions of their slides attached, too.

0 comments voice your opinion now!
webinar write testable code qafoo tobiasschlitt


Volker Dusch's Blog:
The UNIT in unit testing
March 15, 2012 @ 08:24:03

Volker Dusch has a new post reminding us about what the "unit" part of "unit testing" means - small chunks of testable parts in an application.

What does the word UNIT in unit testing stand for? Think of an answer and read on! So? Did you say "A method! Because we test methods!"? If so let me offer another perspective.

He suggests that, rather than about just the methods in the class, it's more about testing the "observable behaviors" of the class. That is, anything that you could publicly use the class for and have something happen. He gives examples of this shift in focus - calling setValue and evaluating the result versus just calling the class property itself (then calling the method). He also includes a bit about testing behaviors - what happens when my script does [this] and how does that effect the overall class.

When your tests fail but the class "still works" and you need to "fix the tests" the your tests are worth a lot less as they don't really give you that cozy safety net that they should provide you with.
0 comments voice your opinion now!
unit unittesting opinion recommendation behavior method testable


Misko Hevery's Blog:
Guide Writing Testable Code
January 07, 2009 @ 10:29:39

In this slightly older (Nov 2008) but useful post to Misko's blog, he takes a look at a few common flaws that you should avoid in writing up your code (in any language really).

To keep our code at Google in the best possible shape we provided our software engineers with these constant reminders. Now, we are happy to share them with the world.

Here's the list of the flaws:

  • Flaw #1: Constructor does Real Work
  • Flaw #2: Digging into Collaborators
  • Flaw #3: Brittle Global State & Singletons
  • Flaw #4: Class Does Too Much

Each includes some warning signs to keep an eye out for to see if you and your code might be straying the wrong way.

0 comments voice your opinion now!
testable guide hint flaw avoid warning sign



Community Events





Don't see your event here?
Let us know!


series podcast code wordpress language developer project threedevsandamaybe framework release configure api list laravel bugfix library introduction community application interview

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework