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

Frank de Jonge:
Finally, file streams, and deferred execution in PHP.
Jun 03, 2016 @ 11:26:52

In a post to his site Frank de Jonge looks at a few different topics around the idea of "cleaning up after yourself" when it comes to the use of finally, file streams and deferred execution.

Cleaning up after yourself can be a tedious task. For example, closing file handlers after using them needs to be done. A programmer's life isn't all about the happy path. When things go pear-shaped you might end up duplicating cleanup code throughout your code. This is horrible, let's explore an alternative.

He starts by looking at the use of resources for file handling instead of something like file_get_contents. Along with this, however, comes "less happy" things to do around cleanup of the resource in case of error or when complete. He suggests that it can be better handled and, after comparing a PHP function version to a Go function doing the same, refactors to make use of finally to close the resource in one place (and it is always called exception on exception). He refactors it even more by splitting it out into a "cleanup" function that can be reused in other places where resources are accessed.

tagged: finally file resource trycatch cleanup tutorial

Link: https://blog.frankdejonge.nl/finally-file-streams-and-deferred-execution-in-php/

Matthew Turland:
Customizing Codeception Database Cleanup
May 12, 2014 @ 11:15:24

If you're a Codeception user, you'll find Matthew Turland's latest post interesting. In it he shares a way to customize database cleanup between the tests. Codeception handles it a bit differently that how PHPUnit's Db module does.

Recently, I was looking into ways to speed up the runtime of the test suite at Blopboard. We use the Codeception framework to write functional tests for our REST API, part of which entails putting the database into a known state using Codeception’s Db module. The behavior of this module is similar to that of the PHPUnit Database extension with one exception: where PHPUnit only truncates tables and leaves their schemas intact, Codeception removes the database structure and expects the SQL dump it uses to recreate it between tests. I must admit to not understanding this design decision of Codeception, nor attempts to clarify it.

He admits that his solution is "a bit hacky" but it does work to truncate the table rather than drop the entire schema and wait for a rebuild. His "DbHelper" class is used in place of the Db module. He traced through the execution path of the Db module and found a "hook" where he could override the "cleanup" method to prevent the schema drop and replace it with a truncate. He also includes code for a suggested addition to Codception that would handle the same thing in a more integrated way.

tagged: customize database cleanup codeception tutorial schema truncate phpunit

Link: http://matthewturland.com/2014/05/09/customizing-codeception-database-cleanup

Zumba Engineering Blog:
Mocking Singleton PHP classes with PHPUnit
Nov 26, 2012 @ 09:51:04

On the Zumba Engineering blog today Chris Taylor has a new post about mocking in PHPUnit, specifically how to handle those pesky Singleton methods lurking around your codebase.

In many of our projects, utilities and vendor classes are implemented with a singleton pattern. [...] In this post, we’ll cover a nice way to inject a PHPUnit mock object for use in testing methods that utilize singleton classes.

He starts by introducing mocking and how to use mock classes in PHPUnit with a simple "sayHello" example. Adding on another layer, he creates a "SomeclassMock" class, defining its own "expects" and "cleanup" methods. This class forces the Singleton method to act more like a regular non-static method and "resets" it after each use.

tagged: mocking phpunit class singleton expects cleanup tutorial

Link:

Richard Thomas' Blog:
ZF please before you go 2.0 gunho please clean out the attic
Jan 28, 2010 @ 12:20:21

Richard Thomas has a suggestion for the Zend Framework development group - clean out the attic before you hit the 2.0 mark.

A big focus of 2.0 it seems is going to be performance and cleaning up the structure to make use of php 5.3 features which is great, I have been preaching the need for ZF to start taking performance as a real concern for a while now. On the other hand they have gotten to a certain point that they need to reflect on what they already have and not let the spiderwebs grow to large.

Richard points out that the Zend Framework, which has a focus on being a "business-class framework" and having the best to offer, has quite a few parts of it that are older and aren't well maintained. This sort of thing could cause some big problems down the line and could even cause some doubt over the developer's choice of frameworks.

tagged: zendframework opinion cleanup maintenance

Link:

SDA Asia:
Yahoo Helping Zend with PHP 6, says Andi Gutmans
Jul 21, 2006 @ 05:33:28

According to this post on the SDA Asia site today, Andi Gutmans is quoted as saying that Yahoo is doing their share in helping PHP6 come along that much faster.

Yahoo is Helping Zend with PHP 6, says Andi Gutmans co-founder and vice president of technology at Israeli-based company Zend Technologies, in an interview with Stephen Shankland of c|net news. PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

They mention what PHP6 will be and include a link to the (oldish) meeting notes concerning it. Be sure to check out the comments for some interesting questions...

tagged: yahoo help php6 zend cleanup apc oop unicode yahoo help php6 zend cleanup apc oop unicode

Link:

SDA Asia:
Yahoo Helping Zend with PHP 6, says Andi Gutmans
Jul 21, 2006 @ 05:33:28

According to this post on the SDA Asia site today, Andi Gutmans is quoted as saying that Yahoo is doing their share in helping PHP6 come along that much faster.

Yahoo is Helping Zend with PHP 6, says Andi Gutmans co-founder and vice president of technology at Israeli-based company Zend Technologies, in an interview with Stephen Shankland of c|net news. PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

They mention what PHP6 will be and include a link to the (oldish) meeting notes concerning it. Be sure to check out the comments for some interesting questions...

tagged: yahoo help php6 zend cleanup apc oop unicode yahoo help php6 zend cleanup apc oop unicode

Link: