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:
Refactoring Legacy Code Part 9 - Analyzing Concerns
July 24, 2014 @ 11:27:56

The NetTuts.com site has posted part nine in their series sharing helpful hints and methods for refactoring legacy code. In this new post they continue on with their example application and look at where methods should be moved to/created and mocking in their tests.

In this tutorial, we will continue to focus on our business logic. We will evaluate if RunnerFunctions.php belongs to a class and if so, to which class? We will think about concerns and where methods belong. Finally, we will learn a little bit more about the concept of mocking.

They show how to move some of the "Runner" functions from procedural to OOP, integrating them with some of the classes and methods that already exist. Tests are also included showing how it all links together. From there they get into concerns about the placement of functionality and how that relates to the work at hand. They also use Mockery to mock out some of the needed objects in their tests for the new structure.

0 comments voice your opinion now!
refactor legacy code series part6 concerns functionality mock unittest

Link: http://code.tutsplus.com/tutorials/refactoring-legacy-code-part-9-analyzing-concerns--cms-21760

Matthias Noback:
The PHP testing experience Interview by Fernando Arconada
July 15, 2014 @ 09:54:12

Matthias Noback has a new post today, an interview that was conducted with him by Fernando Arconda about his experience and thoughts around testing in PHP-driven applications.

Fernando Arconada interviewed me about the subject of testing. He is writing a book about testing Symfony2 applications: Testing para Aplicaciones Symfony2. Fernando will translate this interview to Spanish and and add it to his book, together with the articles in my A better PHP testing experience series.

The interview starts with some background on who Matthias is and what kinds of things he's done in the past with BDD and TDD testing. He answers questions about testing, even for small projects, and if the sought after "100% coverage" is a good mark to try for. They discuss tooling and include some recommendations to beginner developers to help them get testing quickly. A large part of the interview also shares some of his thoughts around the "BDD/TDD is dead" debate that happened not too long ago.

0 comments voice your opinion now!
interview fernandoarconda testing bdd tdd unittest

Link: http://php-and-symfony.matthiasnoback.nl/2014/07/the-php-testing-experience-interview-by-fernando-arconada/

Matthias Noback:
A better PHP testing experience Part II Pick your test doubles wisely
July 10, 2014 @ 09:36:27

Matthias Noback has posted the second part in his look at a better PHP testing experience, focusing this time on picking test doubles wisely. Test doubles are a more general term for what most developers who test code might call a "mock".

In the introduction to this series I mentioned that testing object interactions can be really hard. Most unit testing tutorials cover this subject by introducing the PHPUnit mocking sub-framework. The word "mock" in the context of PHPUnit is given the meaning of the general concept of a "test double". In reality, a mock is a very particular kind of test double. [...] Each type of test double has its own merits and it is vital to the quality of your test suite that you know when to use which one.

He builds on the "non-assertion centric" approach he talked about in the first part and how a similar problem could be caused by the large amount of work needed to create complex mocks. He points out that having to create them in a specific way and the mocks being a bit difficult to use can make the tests fragile and easily broken. He looks at a few different kinds of test doubles (mocks, dummies, spies) with code examples for each for added clarification. He also makes two recommendations for testing instead of complex mocking: create the actual mock classes instead of just mocks and don't overuse mocking.

0 comments voice your opinion now!
testdouble mock unittest phpunit pick wisely

Link: http://php-and-symfony.matthiasnoback.nl/2014/07/test-doubles/

Matthias Noback:
A better PHP testing experience Part I Moving away from assertion-centric testing
July 07, 2014 @ 17:53:45

Matthias Noback has a new post today, part one in a series, looking at moving away from assertion-centric testing and more towards descriptive unit tests.

In the introduction article of this series I quickly mentioned that I think unit testing often focuses too much on assertions. [...] I used to preach these things myself too (yes, "development with tests" often comes with a lot of preaching). But now I don't follow these rules anymore. I will shortly explain my reasons. But before I do, let's take a step back and consider something that is known as the Test framework in a tweet, by Mathias Verraes.

He breaks up the rest of the article into three sections, each with a few paragraphs of description and code where appropriate:

  • Something is the case, or not
  • Only one assertion for each test?
  • Write assertions first and then work towards them?

He talks about the idea of "Arrange Act Assert" and makes some recommendations as to how to be more descriptive in your tests and make them easier to read and follow in the future.

0 comments voice your opinion now!
unittest experience assertion testing descriptive

Link: http://php-and-symfony.matthiasnoback.nl/2014/07/descriptive-unit-tests/

Loosely Coupled Podcast:
Episode 7 Building a Testing Culture
July 02, 2014 @ 11:30:19

The Loosely Coupled podcast has released episode #7 of their show: Building a Testing Culture. In this latest episode hosts Matt Frost and Jeff Carouth talk about their own experience with unit testing and make some recommendations on how to make it a priority in your group.

In this is episode Matt and Jeff discuss how to build a testing culture in your company. They discuss organization resistance, the importance of testing and how to move forward when the rest of your company is less than excited.

You can listen to this latest episode either through the in-page player or by downloading the mp3 directly. Be sure to subscribe to their feed if you like the show and want more.

0 comments voice your opinion now!
looselycoupled podcast ep7 unittest testing culture

Link: http://looselycoupled.info/blog/2014/06/30/episode-7-building-a-testing-culture/

NetTuts.com:
Refactoring Legacy Code Part 6 - Attacking Complex Methods
June 27, 2014 @ 13:17:37

The NetTuts.com site has posted the sixth part in their "Refactoring Legacy Code" series, this time with a focus on the more complex methods. They look at simplifying their contents and testing their various parts (better code coverage). The post is based completely on the contents of the previous five in the series, so if you haven't read up on those do that before starting.

In our previous five lessons we invested quite a lot of time in understanding our legacy system, in writing tests for whatever testable piece of code we could find. We reached a point to where we have quite a few tested methods but we still avoided the complex, hard to understand logic. It's now time for some serious coding.

The start with one of the more complex methods (roll) and work through it line-by-line to figure out what it's being given, how it's handling the data and what kinds of things it might return or modify inside. The break it down into to "parts" and figure out the right tests to write for each. With the method fully tested, they then start in on the refactor, teasing out various parts of the method into other methods and property changes. There's also a section at the end talking about pair programming and how it relates to good testing practices.

0 comments voice your opinion now!
refactor series tutorial part6 complex method unittest phpunit

Link: http://code.tutsplus.com/tutorials/refactoring-legacy-code-part-6-attacking-complex-methods--cms-21522

SitePoint PHP Blog:
Mock your Test Dependencies with Mockery
June 26, 2014 @ 14:26:58

The SitePoint PHP blog has a new post today by Peter Nijssen showing how to use a library that's an alternative to the internal PHPUnit mock handling. The post shows you how to use Mockery to test your applications and abstract out any outside dependencies.

Although not everyone is doing it yet, testing your application is one of the most essential parts of being a developer. Unit tests are the most common tests to run. With unit tests, you can check if a class behaves exactly like you intended it too. Sometimes, you are using a third party service within your application and it's hard to get everything set up to get this unit tested. That's exactly when mocking comes into play.

He starts with a brief introduction to the concept of mocking before getting into his examples. He shows how to get it installed (via Composer) and how to add it as a test listener to your PHPUnit configuration file. He then gets into an actual example: mocking out an external API dependency for a weather service. He shows a simple one-method mock example as well as a more complex example using a more randomized result rather than just a static one.

0 comments voice your opinion now!
mock unittest phpunit mockery tool introduction tutorial

Link: http://www.sitepoint.com/mock-test-dependencies-mockery/

NetTus.com:
You Requested It, We Made It Free PHP Testing Course
June 05, 2014 @ 10:26:49

On NetTuts.com today they've made an announcement about a new PHP testing course they're making available for free. The course is an introduction to testing your PHP applications and is taught by Andrew Perkins.

In this course, Andrew Perkins will teach you the very basics of testing in the PHP language. Learn what is needed to test PHP applications and why testing is important. Explore the differences between regular testing, test-driven development (TDD) and behavior-driven development (BDD). Along the way, take a look at the various frameworks that are available, to make sure your PHP websites run just as you expected. And lastly, compare and contrast the different types of tests that you can run such as unit, functional, and acceptance tests.

The training course covers a lot of the basics behind testing and several of the tools you can use along the way including PHPUnit, Codeception and Behat. It's a pretty quick overview, so don't expect too much in-depth coding and testing examples. The course with all videos included comes in at just a bit over an hour of content. You can find out more and sign up to have access to the training here.

0 comments voice your opinion now!
testing training course unittest functionaltest software introduction

Link: http://code.tutsplus.com/tutorials/you-requested-it-we-made-it-free-php-testing-course--cms-21283

NetTuts.com:
Refactoring Legacy Code Part 5 - Game's Testable Methods
May 27, 2014 @ 09:29:33

NetTuts.com continues on with their next part of their refactoring series today in this new post focusing on (unit) testing more of the application. This includes both the code for the tests and the before/after of the refactored code.

Old code. Ugly code. Complicated code. Spaghetti code. Gibberish nonsense. In two words, Legacy Code. This is a series that will help you work and deal with it. In our previous tutorial, we tested our Runner functions. In this lesson, it is time to continue where we left off by testing our Game class. [...] It is much better to start testing it by its short, testable methods. This is what we'll do in this lesson: find and test those methods.

They start with creating a new "Game" object and finding the first testable method in the class. The tutorial works through this and other related methods to build up a set of "Game" tests and eventually doing some refactoring on the tests themselves. With one method down and tested, they move on to finding and creating the tests for the next few testable methods, looking for something "controllable" that makes for easy testing.

0 comments voice your opinion now!
refactor legacy code series part5 unittest game method

Link: http://code.tutsplus.com/tutorials/refactoring-legacy-code-part-5-games-testable-methods--cms-21213

NetTuts.com:
Refactoring Legacy Code Part 4 - Our First Unit Tests
May 19, 2014 @ 13:57:41

NetTuts.com has posted the fourth part of their series guiding you through some recommended steps for refactoring legacy code. In this new post they build on the previous steps and focus more on the first steps into unit testing.

One of the key moments of refactoring a totally legacy code is when we start extracting small pieces from it and we start writing targeted unit tests for those small pieces. But this can be quite difficult, especially when you have code that is written so that it would be hard to compile or run if pieces of it are missing. We can't safely do large surgeries on a code we still barely understand and only a golden master test keeps us breaking it totally. Fortunately there are some techniques that can help us.

There's a brief introduction to unit testing and how it can be useful in a refactoring situation. They help you locate some isolated methods to start with and include a sample test (using PHPUnit). They talk about handling dependency injection, refactoring the tests themselves and working with dependencies across environments. Hints on isolating parts of the code that can be and how to refactor the tests to match are also included.

0 comments voice your opinion now!
refactor legacy code series part4 unittest phpunit

Link: http://code.tutsplus.com/tutorials/refactoring-legacy-code-part-4-our-first-unit-tests--cms-21146


Community Events





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


list podcast code threedevsandamaybe configure introduction testing experience install community framework wordpress interview opinion developer laravel unittest release language series

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