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

PHP Roundtable:
035: Immutable PHP
Nov 25, 2015 @ 09:53:44

The PHP Roundtable podcast has posted their latest episode, recorded live with host Sammy Kaye Powers and guests Larry Garfield, Matthew Weier O'Phinney and Glen Hickle talking about immutability in PHP.

Immutability plays a huge role in functional programming and many languages support immutability directly; like the readonly keyword in C#. It is possible to create immutable objects in PHP, but the language lacks inherent immutable features for scalar variables and class properties. We discuss how to bring functional programming concepts to PHP and brainstorm some features that could possibly be added to future versions of PHP to offer better immutability support.

You can watch the live recording of this latest episode either through the in-page video player or directly over on YouTube. If you enjoy the show, be sure to also subscribe to their feed and follow them on Twitter for information on the latest episodes (and when future live recordings are happening).

tagged: phproundtable ep32 immutability programming feature functional support

Link: https://www.phproundtable.com/episode/immutability-and-functional-concepts-in-php

Dalibor Karlović:
Testing your Symfony application on production
Oct 05, 2015 @ 09:14:50

In a new tutorial Dalibor Karlović shows you how to test your Symfony application in production to get a more "real world" picture of how your application is performing for the rest of the world.

The problem here is that you almost cannot guarantee that you can replicate the production environment down to a single detail, it might have a slightly different underlying system, a slightly different network setup, even a different updates applied might mean it works for you, but not on production.

He starts the post by talking about the testing support already built into Symfony and the different parts tested by unit versus functional tests. He gets into some actual (functional) test examples, showing how to evaluate the response from an API request and where the major part of the overhead is - the database interaction. He takes the next step and looks at how to avoid "impure" functional testing and only then starts talking about switching between database types (SQLite vs MySQL) for better performance measurements. Finally, he gets to the topic of the article, running tests in production, and includes a "gotcha" to look out for (hint: don't hard-code IDs).

tagged: test symfony application production functional unit sqlite mysql

Link: https://medium.com/@dkarlovi/testing-your-symfony-application-on-production-a143483768c9

Hafiz Waheeduddin Ahmad:
API Testing: Installing and Using Codeception
Jun 15, 2015 @ 15:45:41

Hafiz Waheeduddin Ahmad has a new post to his site, part three of a series he's posted on API testing, looking at the use of Codeception for testing API output and functionality.

In this post, we will have a look on how we can use Codeception for API testing.

He starts by helping you get Codeception installed through Composer through a "require" command line call. He then walks you through the setup of the project and how to use the "codecept" command line tool. He covers the generated directory structure the bootstrapping created and how to set up a sample configuration for your API. He then gets into writing an example test, showing how to check things like authentication, HTTP header information, response codes and response contents. Finally he shows how to run the tests in both a normal and more verbose way.

tagged: api testing series part3 codeception introduction functional

Link: http://haafiz.me/development/api-testing-installing-and-using-codeception

Laravel 5 and Behat: BFFs
Jan 13, 2015 @ 10:35:27

The Laracasts site has a new screencast posted showing you how to integrate Behat with Laravel for functional testing of your application. Behat is an automated testing tool, written in PHP, that's made for frontend functional tests rather than backend, unit tests

It has always been a little tricky to hook Behat into Laravel. But, luckily, that's no longer the case. In this lesson, from scratch, we'll install both Laravel 5 and Behat 3, and then learn about using a special extension to make working with the two that much easier. In a follow-up lesson, we'll move on to discussing general BDD, and best practices for constructing your feature files.

You can watch the screencast on the Laracasts site and you can find out more about Behat from its documentation.

tagged: laracast laravel behat functional testing extension tutorial screencast

Link: https://laracasts.com/lessons/laravel-5-and-behat-bffs

Liip Blog:
Functional Programming in PHP
Nov 06, 2014 @ 12:20:35

On the Liip blog today there's a tutorial from Gilles Crettenand giving you an overview of functional programming in PHP. While PHP is not normally used as a functional language, it is possible to simulate the same effect.

Functional programming has gained a lot of traction those 3 to 5 last years. [...] Those [frameworks and languages] are all cool and shiny new toys, but we can benefit from some techniques without having to learn a new tool, just by applying some principles to our everyday PHP! But first of all, what exactly is functional programing?

He starts off with some of the basics of functional programming, some of the difficulties that can come with it and, of course, the advantages it can provide. From here he starts in with code examples. He shows how functions become "first-class citizens" and how they can be applied to various elements. He illustrates this with a few array manipulation examples. Next up are "utility functions" for evaluating the data given (like "any" or "all"). He ends the post looking at the idea of "memoization", or the caching of the results of function calls against data. He shows how to accomplish this with static local variables in PHP and includes a wrapper you can pass any callable function into and have the results cache automatically.

tagged: functional programming introduction language function cache

Link: http://blog.liip.ch/archive/2014/11/05/functional-programing-in-php.html

Basic Functional Testing With Symfony 2's Crawler
Oct 23, 2014 @ 10:21:33

In this new tutorial on the NetTuts.com site Andrew Perkins shares a way that you can use Symfony2's own Crawler to do some simple functional testing.

Testing your web applications is one of the best things you can do to ensure its health, safety, and security, both for the app and your app's visitors. Symfony 2 offers a complete integration testing suite that you can use to make sure your applications run just as you expect. Today we'll look at how we can use Symfony 2 and PHPUnit, the testing framework that it employs, to write basic functional tests using the Crawler.

He starts off by helping you get a Symfony2 instance installed, the Standard edition, and grabbing the latest PHPUnit phar file from the project's site. He then gets into the actual development of the Crawler bundle, using the command line Symfony tool to do some of the automatic code generation for you. They show how to execute the PHPUnit tests and make the first controller/action/routes for the sample pages to test. He then makes the first test file, extending the "WebTestCase" class from the Symfony2 components. He makes a simple client, executes the request and shows how to test various parts of the response (including an example of mimicking the clicking of a link).

tagged: crawler symfony2 functional testing tutorial introduction

Link: http://code.tutsplus.com/tutorials/basic-functional-testing-with-symfony-2s-crawler--cms-20666

Functional Programming in PHP Release
Sep 08, 2014 @ 11:14:22

While not a mainstream practice in the PHP world, functional programming has been a topic that's popped up again and again over the years. If you've ever wondered what it's all about and how to get started with it in your applications, take a look at php[architect].

This book is for anyone that has an interest in functional programming or PHP as an advanced programming language. If you are curious or have never even heard of functional programming before then this is the gentle introductory text you have been looking for. Equally it serves those seeking to exploit the advanced functional concepts such as monads in a PHP context.

This book comes from some of the experience Simon has had with functional programming in the past (and taught about in presentations). It provides examples showing the techniques of functional programming applied in PHP including: map/reduce, currying and composition. The book can be purchased either directly from php[architect] or from Amazon (or Amazon.co.uk).

tagged: functional programming release book phparchitect simonholywell

Link: http://www.functionalphp.com

Three Devs & A Maybe Podcast:
Functional Programming with Simon Holywell
Jul 23, 2014 @ 11:03:45

Three Devs & A Maybe podcast has released their latest episode today: Episode #35 - an interview with Simon Holywell. Simon is the author of an upcoming book about functional programming in PHP.

This week we are lucky to have Simon Holywell on the show to talk all things Functional Programming. Initially starting off with a concrete definition of Functional Programming, we move on to a brief history of the paradigm and immutability. Following this we explain recursion (and tail-recursion), along with closures and higher-order functions. From this base we are able to then talk about the different languages available to you which cater towards the functional mindset (i.e. Haskell). We then set our sights on the PHP language and what/wish it had to offer when exploring the functional paradigm. Finally, we mention his upcoming book, along with experiences presenting at user-group meet-ups.

Topics mentioned in this episode include:

You can listen to this latest episode either through the in-page player or by downloading the mp3 directly.

tagged: threedevsandamaybe podcast ep35 simonholywell functional php

Link: http://threedevsandamaybe.com/posts/functional-programming-with-simon-holywell/

SitePoint PHP Blog:
Functional Testing in Symfony2
Mar 04, 2014 @ 11:16:45

Taylor Ren has written up a new tutorial for the SitePoint PHP blog today walking you through a method for functional testing a Symfony application with the help of Symfony's own "WebTestCase" functionality.

In my previous article, we demonstrated how to load sample data into our Symfony development environment. The test data may not be useful as it stands on its own. When coupled with Functional Testing, however, it becomes a life saver. [...] Functional Testing is different. We don’t look at the “correctness” of a single function, which should be verified by a Unit Test, but look at the bigger picture. The question answered by Functional Testing is: Is our app performing well in the sense that it displays the right content, corresponds to a user’s interaction, etc?

He shows how to create a simple WebTestCase-based test to fetch the main page of a site, locate a few pieces of information and click on a certain link. Once this test passes, he adds a bit more to the test, checking the data in the page following the click.

tagged: symfony2 functional testing tutorial webtestcase

Link: http://www.sitepoint.com/functional-testing-symfony2/

VG Tech:
Generating Code Coverage of Behat Tests
Jan 22, 2014 @ 10:52:57

On the VGTech blog today Christer Edvartsen looks at a method of generating the code coverage of Behat tests using a special bit of code and the $_SERVER superglobal to detect what parts of the code is being executed.

Yes, I know, it sounds silly, but bear with me. The nature of acceptance tests is not really to tests units of code, but to assure that the behavior of your application meets a certain set of criteria (Behat Scenarios). When your applications grow over time, code coverage can be a nice tool to help you pinpoint where you need to add more tests. In a perfect world tests are added while implementing new features so that your applications are always fully tested, but that isn’t always as easy as it sounds.

The first chunk of code is something that would go in the router of your application, capturing the "collect coverage" and "enable coverage" input variables. The other part of the code creates a unique ID in the set up and uses it in a call (via Guzzle) to the server to start the tracking. In the tear down method, it sends the call to get the coverage results and process them through the PHP_CodeCoverage tool from Sebastian Bergmann.

tagged: code coverage behat test tutorial functional

Link: http://tech.vg.no/2014/01/21/generating-code-coverage-of-behat-tests