News Feed
Jobs Feed
Sections




News Archive
feed this:

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

Federico Cargnelutti:
TDD Checking the return value of a Stub
April 16, 2014 @ 10:25:15

Federico Cargnelutti has a helpful post to his site today for the unit testing/TDD crowd about checking the retuned value from a stub of an object in your tests. He's using the built-in mocking framework here, not something like Mockery.

State verification is used to ensure that after a method is run, the returned value of the SUT is as expected. Of course, you may need to use Stubs on a test double or a real object to tell the object to return a value in response to a given message. [...] In PHP, for example, you dynamically type the return value within the body of the method. This means that PHP mocking libraries cannot check the type of the return value and provide guarantees about what is being verified. This leads to the awkward situation where a refactoring may change the SUT behaviour and leave a stub broken but with passing tests.

He gives an example of a few classes - a Presenter and Collaborator - and a test that mocks out the Collaborator instance, calling a "getStories" method on it. He shows a situation where all tests pass in the initial version, but after some changes to the return type, a test that should fail doesn't. His solution for the issue revolves around DocBlock annotations and the Return Value instead of the built-in mock object return method.

0 comments voice your opinion now!
tdd unittest return value stub passing test returnvalue mock

Link: http://blog.fedecarg.com/2014/04/15/checking-the-return-value-of-a-stub/

Francesco Tassi:
Switching From TDD to BDD With Behat and Symfony2
August 16, 2013 @ 13:27:32

In this new post to his site Francesco Tassi shares his experience making the switch from doing just test-driven development on his Symfony2-based applications to behavior-driven development using Behat, Mink and PHPSpec.

Recently I started a small extra project with a smart fellow from my local PHP User Group, since the project was quite simple and both of us were willing to learn something new, we decided to give BDD a try. In the PHP world BDD means Behat, Mink and PHPSpec. [...] In this post I won't cover all the details about BDD, Behat or PHPSpec, I'd rather describe how I switched from PHPUnit and TDD to BDD (and also show some bits of code).

He talks about the switch in mindset that comes along with adopting BDD and how you think about testing - not what it does, but what it should do. He talks some about test organization, configuration and his process for executing them. There's a bit about working with databases (with fixtures and @BeforeScenario) including the code for the feature file to make it happen.

0 comments voice your opinion now!
tdd testdriven bdd behaviordriven behat symfony2 tutorial

Link: http://www.ftassi.com/blog/2013/08/12/switching-from-tdd-to-bdd-with-behat-and-symfony2

MaltBlue.com:
Why Testing Makes a Project Successful and You Can't Afford to Deny It
April 24, 2013 @ 10:48:15

Matthew Setter has a new article on his MaltBlue site today that suggests that one of the reasons a project is successful is because of effective testing.

Like many of us, despite being told repeatedly how great testing is, the benefits it will bring, the time it will save and how it will improve the quality of my applications, I too considered testing a second-thought. I saw it as something which was both expensive and time-consuming. If I was genuine with you, I'd say I believed it be be nothing more than a "nice to have", after the application was written. If you also feel (or have felt) this way - know that you're not alone.

He realized, though, that the usual false assumptions about testing were just that and starteed getting into testing, TDD and BDD on recent projects. He talks some about some general thoughts around testing like "testing can't be an after-thought" and the fact that it's no always easy. He includes a way of thinking about testing in your application and the confidence good, solid tests can bring.

0 comments voice your opinion now!
testing project success unittest tdd bdd opinion

Link: http://www.maltblue.com/software-development/testing/why-successful-software-includes-testing

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/

Justin Carmony:
First Serious Attempts with PHPUnit, Composer, and the Omniture API
March 20, 2013 @ 09:37:53

In a new post to his site Justin Carmony shares some of his experiences with doing test-driven development (TDD) for a new project he was working on interfacing with the Omniture API. In it he shares six lessons he learned during the work.

At work we use Omniture for our web analytics, and for a long time I've wanted query our Omniture Data to run some internal reports. I discovered that Omniture has a restful reporting api, and after using it for a little bit I decided it would be nice to write a wrapper library for it. Since I had recently taken the PHP Testing Bootcamp from Chris Hartjes, I decided I wanted write it using Test Driven Development and really get my feet wet. I also decided I wanted to make the library compatible with Composer. After the weekend was over, I had an almost finished library that just requires some more work to be done, but I learned a great deal that I thought I'd share.

He's broken the post up into sections, each with their own summary:

  • TDD is 90% changing the way to write code, and 10% writing tests
  • Understanding Mock Objects is the real key.
  • It takes almost twice as long to write code and tests then just code
  • Its extremely easy to get out of the habit of writing tests.
  • You'll refactor quicker and more often when writing tests
  • Having testable code made me feel much better about sharing the code.
0 comments voice your opinion now!
tdd testdriven development rest api omniture composer lessons


Scott Mattocks:
D is for Documentation
March 04, 2013 @ 09:30:16

Scott Mattocks has wrapped up his series about LUCID development with the final letter of the acronym - D is for Documentation.

Despite mankind's best efforts, writing code is still clearly an exercise for talking to computers. It has not evolved to the point where talking to a computer is as easy and natural as talking to other people. That's why documentation is so important. Programming languages are just a translation of a developer's intent into something a computer can execute.

He points out that even a little documentation can go a long way (even in presentations with code in the slides). It provides context and the intent of the code, not just details about what it's doing. He proposes a compliment practice to test-driven development (TDD) that turns the documentation process around - Documentation Driven Development. This is essentially writing up what the code does first, then writing tests to check it and only then writing the code to make it happen.

If you're interested in the rest of the articles in the series, check out the LUCID article on his site with links to each letter's article.

0 comments voice your opinion now!
lucid development principles documentation tdd


NetTuts.com:
Better Workflow in PHP With Composer, Namespacing, and PHPUnit
January 21, 2013 @ 10:49:15

On NetTuts.com there's a new screencast posted showing you a good way to create a better workflow in your PHP development using Composer and PHPUnit.

In this video tutorial, we'll again focus on workflow. Specifically, we'll use Composer's built-in autoloading capabilities, along with namespacing, to make for an elegant testing experience. We'll also review a handful of PHPUnit best practices, as we get setup with these tools.

He shows you how to use Composer to load in the packages from other projects (as well as your own) and using PHPUnit to execute unit tests for your application. He uses test-driven development, but it's not a required part of the workflow. He helps you create a simple "Calculator" test. He also shows how to manually modify the Composer classmap to load in your own classes.

0 comments voice your opinion now!
workflow screencast phpunit composer namespace tdd unittest


NetTuts.com:
Why 2013 is the Year of PHP
January 16, 2013 @ 09:21:38

On NetTuts.com today there's a new article that suggests that 2013 is the "Year of PHP" and how recent additions to the language are going to effect its future.

2012 was an excellent year for the PHP community, thanks to many badly needed features being added to version 5.4, as well as the countless projects, advancing PHP to the next level. In this article, I'd like to review a handful of the issues that people had with PHP in the past, and provide a glimpse at why 2013 just may be the year of PHP!

They talk about some of the hostility (stigma) that's always been present when people talk about using PHP and a reminder that PHP, as good as it is, isn't perfect either. They talk some about the current state of the language and community and about how tools like Composer and methods like test-driven development (as well as major features being added to the language) have it poised for even more growth in the next year.

0 comments voice your opinion now!
yearofphp opinion composer tdd stigma language


John Cleary:
12 TDDs of Christmas
December 27, 2012 @ 09:17:26

In an effort to spread the good practices that TDD (test-driven development) can bring to your development, John Cleary has proposed what he's calling this "12 TDDs of Christmas" for the end of the year. The goal is to get you doing TDD, one piece at a time, and seeing the benefits.

So here is the challenge. Starting Wednesday 26th Dec and for the following 12 days I'm going to do just one kata per day. I'm calling it the 12 TDDs of Christmas and it would be pretty cool if a few other people out there took up the challenge with me 0 fancy it?

The 12 days started on December 26th, so there's a little catch up work to do, but you're not too far behind. The "katas" are short problems to solve that only require a bit of code to get working. The idea, though, is that you practice with the test-first methods and use these examples as the assertions.

0 comments voice your opinion now!
tdd testdriven development kata learn 12days


Matt Frost:
TDD For the Unconverted
November 20, 2012 @ 12:45:46

Matt Frost has a new post today helping to explain test-driven development (TDD) for the unconverted and some of the things that come with it in practice.

You've heard of Test Driven Development, but you think; "I've got a horrifying monstrosity for a codebase, it's not testable so I can't do TDD". Let me be the first to tell you that you're wrong. I'm not into writing really controversial pieces, castigating people for not doing things a certain way. If you've considered TDD at any point in time, it's because you understand (at least in the theoretical sense) that having predictable software is beneficial. So this is for you, unconverted developer...

He talks about how using TDD can help you build confidence in your code, make debugging issues easier in the project simpler and how - despite the initial time it takes to implement it in the process - it's worth it in the end. He also includes a few helpful suggestions when your team doesn't want to follow the method.

0 comments voice your opinion now!
tdd testdriven development opinion bug confidence process



Community Events











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


hack podcast security framework facebook install release package unittest language project introduction component composer database application hhvm performance symfony2 example

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