PHP Community

Phix 0.16.0 Released

Planet-PHP - Thu, 23/05/2013 - 22:10

Phix is a tool for creating and managing PHP components and tools and releasing them as PEAR packages.

I’ve pushed out Phix 0.16.0 this evening, with the following changes:

  • phing build-vendor now removes the component’s own code from the vendor/ folder. (We build the vendor/ folder using PEAR, which installs the component into the vendor/ folder … sigh)
  • An update to Phing changed the default behaviour of the <fileset> tag, breaking backwards-compatibility. I’ve updated our build.xml file to make the <fileset> tag revert back to its original behaviour.

To update your copy of Phix, please run:

pear upgrade phix/phix4componentdev

Any problems, please let me know.

Catégories: Open Source, PHP Community

UA Testing with Selenium and PHPUnit

Planet-PHP - Thu, 23/05/2013 - 20:00

Last week I spoke at php[tek] 2013 where I explained to people how to get started with Selenium IDE to record user interaction with the web interface, convert them to PHPUnit testcases and automatically execute them on multiple browsers on multiple platforms.
The feedback I got was awesome, you're all a great crowd! But on twitter I also received a bunch of questions regarding how to set up multiple platforms and why I used Windows in my presentation to deploy to.
So today I deceided it was time to write a full article on this subject.
What is Selenium?
Selenium is a tool that allows you to continuously test user interfaces of web applications. The most common usages for Selenium testing are the following:
  • testing elements are (not) on the web interface
  • users can't break out a certain flow on the web interface
  • calculated values are correct after modification
  • errors appear on screen when mistakes are made by users
  • reported issues are valid
In general we call these type of tests User Acceptance Tests or UAT and are all focused from the point of the end-user, the person using the web interface to accomplish a certain goal.
Why are they important?
UAT have their own right to exist. Just like regular unit, performance and stress tests they have their own agenda and are adressing a particular part of your application that needs testing. All to prevent your customers/visitors from finding issues, bugs or just unfunctional pieces on your web application and loose their trust in your products or services.
Therefor it's always good to invest in the "visibile" part of your web application. Especially when using javascript, you want to ensure it always works as intended.
Disclaimer
Selenium tests are in no way a replacement for regular unit tests. Their focus is on generated output of your web application within a browser. Unit tests are still necessary to ensure the logic of your application is not broken when making modifications or adding new functionality!
Setting things up
You can write your own Selenium tests by hand, but the easiest way is to use the 

Truncated by Planet PHP, read more at the original (another 36325 bytes)

Catégories: Open Source, PHP Community

Anna Filina: Full Test Coverage is Impractical

PHPDeveloper.org - Thu, 23/05/2013 - 19:06

In her latest post Anna Filina proposes that full test coverage is an impractical way to measure the quality of your software. It can provide a false sense of security, even if the tests are poorly written.

Many developers claim that to achieve high quality software, developers must create automated tests that ensure that all possible execution routes have been covered. This is also known as full path coverage. I will argue that different types of software require different testing approaches and that full path coverage is impractical in almost every case. Too many tests simply create clutter.

She looks at how it's impractical to expect that all tests will be written efficiently or even correctly. Even simple tests are enough to show up on code coverage reports but may only be painting part of the picture. She also notes that not all software can be tested the same way - things like APIs require different testing skills/methods than something like consumer software.

In the end, there are no exact rules on how much to test. The most important thing to keep in mind is that writing tests for the sake writing tests is futile and costly. [...] Focus on building great software. Tests are a tool to make it better. Just don't overdo it. Link: http://annafilina.com/blog/full-test-impractical

ZFort Group: The Battle of the Titans. Zend vs. Symfony

PHPDeveloper.org - Thu, 23/05/2013 - 18:55

In this new post to the ZFort blog Elena Bizina compares Symfony and Zend Framework from her perspective, looking at things like functionality, general understanding and community.

Zend and Symfony are the two frameworks that are often compared. Which one is more functional? Which one is more preferable in terms of productivity? Which one is better for general understanding? Which of these two has a larger community? I've asked Zfort Group experts to help me with these questions, and here's what we have come to.

She first gives a high-level overview of each framework, pointing out a few of the features and tools they have built-in. She then goes on to answer the questions above, noting that she sees Symfony as coming out in the lead. Some of the questions are a little vague, so it's not entirely clear why one is different than the other. What do you think? Leave a comment here with your opinions.

Link: http://www.zfort.com/blog/zend-vs-symfony

Lorna Mitchell: Simplest PHP Generator Example

PHPDeveloper.org - Thu, 23/05/2013 - 17:31

On her blog Lorna Mitchell has posted an example of a basic generator written in PHP, a feature of the upcoming PHP version 5.5.

I really like the generators feature that's arriving in PHP 5.5, and since we're now into release candidate releases, it's actually not that far away. I've been speaking on this topic and I thought I'd share my trivially simple code example from my slides.

She includes an example of a very basic generator using the new "yield" keyword and how to implement it in a simple foreach loop. There's also a little talk about when is a good time to use generators in your applications (two examples: complex number calculation and working with large data sets a chunk at a time). For more information on how these generators will work, check out this page in the PHP manual.

Link: http://www.lornajane.net/posts/2013/simplest-php-generator-example

Engine Yard: A Conversation About Testing in PHP

PHPDeveloper.org - Thu, 23/05/2013 - 16:42

On the Engine Yard blog today they've posted a conversation about testing between Ed Finkler and Chris Hartjes (also the hosts of the DevHell podcast).

Our friends Ed Finkler and Chris Hartjes recently had a chat about testing in PHP. Read on to get the low down on different testing tools and their relative merits-check it out as Ed and Chris weep for the future, come to some interesting conclusions and get their hands dirty so you don't have to.

They talk some about the current tools for unit testing in PHP applications and show what a sample test looks like. Ed talks about how the current testing tools can make it intimidating for people to get started testing and mentions the built-in testing library in Python that is a bit easier. There's also some mention of acceptance/functional testing and the Behat + Mink combo.

Link: https://blog.engineyard.com/2013/a-conversation-about-testing-in-php

Community News: Packagist Latest Releases for 05.23.2013

PHPDeveloper.org - Thu, 23/05/2013 - 15:03
Recent releases from the Packagist:

Swede From Future Says He Can Code

Planet-PHP - Thu, 23/05/2013 - 11:22
A revaluation today as a Swedish national, who has traveled back in time, says he can code!
Catégories: Open Source, PHP Community

PGSQL Cheat Sheet

Planet-PHP - Thu, 23/05/2013 - 11:22
This table provides a simple ready reference to some common commands used in PostgreSQL. Ideal for those more accustomed to MySQL or other databases.
Catégories: Open Source, PHP Community

Simple Mysql PHP Menu

Planet-PHP - Thu, 23/05/2013 - 11:22
There are possibly as many menu systems available for PHP and MySQL as there are PHP programmers. Here is yet another way of generating menus from a database.
Catégories: Open Source, PHP Community

Simple Mysql PHP Menu

Planet-PHP - Thu, 23/05/2013 - 11:22
There are possibly as many menu systems available for PHP and MySQL as there are PHP programmers. Here is yet another way of generating menus from a database.
Catégories: Open Source, PHP Community

Test For Prime Numbers With PHP Regular Expression

Planet-PHP - Thu, 23/05/2013 - 11:22
This function provides a novel method of testing if a number is prime, by using a PHP regular expression.
Catégories: Open Source, PHP Community

Web2bb 0.0.9 Released

Planet-PHP - Thu, 23/05/2013 - 11:22
This is the latest update to the WEB2BB Framework and includes a simple fix for an error that failed to catch an exception. The WEB2BB framework is a fully functioning MVC style framework that utilizes the best features of PHP 5.3 and above. By making use of the latest additions to PHP, the WEB2BB framework is able to provide sleek code and optimal performance. It does not try to be all things to all people and so the codebase is kept to a minimum.
Catégories: Open Source, PHP Community

nWire Eclipse Zend Plugin Review

Planet-PHP - Thu, 23/05/2013 - 11:22
PHPRO.ORG receives many emails requesting reviews for magazines, web sites, application development tools, applications, books etc. Now and again, one of these catches the eye and deserves further inspection. Recently, a request for a product called nWire arrived which allegedly "accelerates PHP development by helping developers navigate through their code and better understand the architecture of their application". Here is a closer look at nWire.
Catégories: Open Source, PHP Community

Trim All Members Of An Array With PHP

Planet-PHP - Thu, 23/05/2013 - 11:22
This little helper function provides a simple method to trim the white space from the beginning and end of all the elements in an array. It uses the call to array trim, which, in turn, calls the trim() function. The iteration is handled internally and so provides maximum performance then dealing with the the problem in user code.
Catégories: Open Source, PHP Community

Full Test Coverage is Impractical

Planet-PHP - Wed, 22/05/2013 - 21:21

Many developers claim that to achieve high quality software, developers must create automated tests that ensure that all possible execution routes have been covered. This is also known as full path coverage. I will argue that different types of software require different testing approaches and that full path coverage is impractical in almost every case. Too many tests simply create clutter.

Let’s look at the impracticality first. Writing tests requires skill and effort. Everybody on your team is probably not a testing expert. Not only may it be difficult to get started with testing, but you will generate a great amount of code with its load of maintenance. Tests are not immune to their own errors either. I have uncovered a number of incorrect test cases in every project, including PHP itself.

A full coverage can give a fake sense of security, because you won’t second guess your tests and there will be too many to effectively audit them. That doesn’t mean that more tests is bad. It means that you must strike a good balance between the number of tests and the assurance that you are seeking. Look at it as a car insurance that costs more per year than the price on your car. You want to feel safe with the right insurance, but at some point, it’s more trouble than it’s worth. You can easily end up with more test code than software code, so watch out.

My second point is that different software justifies different tests. Software that is meant to be used by other software — such as a programming language, a framework or an API — would require more in-depth testing. I would recommend writing a few tests per function, to make sure that they return expected values. Testing all paths may still not be necessary, because some paths may prove redundant. Let’s take a date parsing function as an example. If you can parse “2013-05-22 13:00″ and “May 22, 2013 1:00pm” correctly, then perhaps testing the permutation “2013-05-22 1:00pm” may be unnecessary. Be smart about your tests: choose quality over quantity.

For consumer software, you may not need to test everything. I recommend to skip obvious tests. For example, it is obvious that when you first instanciate this class, getTotal() will return zero.

class ShoppingCart {
  protected $total = 0;

  function getTotal() {
    return $this->total;
  }
}

Writing overly obvious test cases is like underlining text that is already highlighted. I usually start testing areas that can have impact the business, such as losing data or selling 0.01 quantity of a product.

In the end, there are no exact rules on how much to test. The most important thing to keep in mind is that writing tests for the sake writing tests is futile and costly. Not only that, but your colleagues won’t bother reading or maintaining tests if they are only there for their own sake and provide too little value. Focus on building great software. Tests are a tool to make it better. Just don’t overdo it.

Catégories: Open Source, PHP Community

Full Test Coverage is Impractical

Planet-PHP - Wed, 22/05/2013 - 21:21

Many developers claim that to achieve high quality software, developers must create automated tests that ensure that all possible execution routes have been covered. This is also known as full path coverage. I will argue that different types of software require different testing approaches and that full path coverage is impractical in almost every case. Too many tests simply create clutter.

Let’s look at the impracticality first. Writing tests requires skill and effort. Everybody on your team is probably not a testing expert. Not only may it be difficult to get started with testing, but you will generate a great amount of code with its load of maintenance. Tests are not immune to their own errors either. I have uncovered a number of incorrect test cases in every project, including PHP itself.

A full coverage can give a fake sense of security, because you won’t second guess your tests and there will be too many to effectively audit them. That doesn’t mean that more tests is bad. It means that you must strike a good balance between the number of tests and the assurance that you are seeking. Look at it as a car insurance that costs more per year than the price on your car. You want to feel safe with the right insurance, but at some point, it’s more trouble than it’s worth. You can easily end up with more test code than software code, so watch out.

My second point is that different software justifies different tests. Software that is meant to be used by other software — such as a programming language, a framework or an API — would require more in-depth testing. I would recommend writing a few tests per function, to make sure that they return expected values. Testing all paths may still not be necessary, because some paths may prove redundant. Let’s take a date parsing function as an example. If you can parse “2013-05-22 13:00″ and “May 22, 2013 1:00pm” correctly, then perhaps testing the permutation “2013-05-22 1:00pm” may be unnecessary. Be smart about your tests: choose quality over quantity.

For consumer software, you may not need to test everything. I recommend to skip obvious tests. For example, it is obvious that when you first instanciate this class, getTotal() will return zero.

class ShoppingCart {
  protected $total = 0;

  function getTotal() {
    return $this->total;
  }
}

Writing overly obvious test cases is like underlining text that is already highlighted. I usually start testing areas that can have impact the business, such as losing data or selling 0.01 quantity of a product.

In the end, there are no exact rules on how much to test. The most important thing to keep in mind is that writing tests for the sake writing tests is futile and costly. Not only that, but your colleagues won’t bother reading or maintaining tests if they are only there for their own sake and provide too little value. Focus on building great software. Tests are a tool to make it better. Just don’t overdo it.

Catégories: Open Source, PHP Community

Full Test Coverage is Impractical

Planet-PHP - Wed, 22/05/2013 - 21:21

Many developers claim that to achieve high quality software, developers must create automated tests that ensure that all possible execution routes have been covered. This is also known as full path coverage. I will argue that different types of software require different testing approaches and that full path coverage is impractical in almost every case. Too many tests simply create clutter.

Let’s look at the impracticality first. Writing tests requires skill and effort. Everybody on your team is probably not a testing expert. Not only may it be difficult to get started with testing, but you will generate a great amount of code with its load of maintenance. Tests are not immune to their own errors either. I have uncovered a number of incorrect test cases in every project, including PHP itself.

A full coverage can give a fake sense of security, because you won’t second guess your tests and there will be too many to effectively audit them. That doesn’t mean that more tests is bad. It means that you must strike a good balance between the number of tests and the assurance that you are seeking. Look at it as a car insurance that costs more per year than the price on your car. You want to feel safe with the right insurance, but at some point, it’s more trouble than it’s worth. You can easily end up with more test code than software code, so watch out.

My second point is that different software justifies different tests. Software that is meant to be used by other software — such as a programming language, a framework or an API — would require more in-depth testing. I would recommend writing a few tests per function, to make sure that they return expected values. Testing all paths may still not be necessary, because some paths may prove redundant. Let’s take a date parsing function as an example. If you can parse “2013-05-22 13:00″ and “May 22, 2013 1:00pm” correctly, then perhaps testing the permutation “2013-05-22 1:00pm” may be unnecessary. Be smart about your tests: choose quality over quantity.

For consumer software, you may not need to test everything. I recommend to skip obvious tests. For example, it is obvious that when you first instanciate this class, getTotal() will return zero.

class ShoppingCart {
  protected $total = 0;

  function getTotal() {
    return $this->total;
  }
}

Writing overly obvious test cases is like underlining text that is already highlighted. I usually start testing areas that can have impact the business, such as losing data or selling 0.01 quantity of a product.

In the end, there are no exact rules on how much to test. The most important thing to keep in mind is that writing tests for the sake writing tests is futile and costly. Not only that, but your colleagues won’t bother reading or maintaining tests if they are only there for their own sake and provide too little value. Focus on building great software. Tests are a tool to make it better. Just don’t overdo it.

Catégories: Open Source, PHP Community

Simplest PHP Generator Example

Planet-PHP - Wed, 22/05/2013 - 20:30

I really like the generators feature that's arriving in PHP 5.5, and since we're now into release candidate releases, it's actually not that far away. I've been speaking on this topic and I thought I'd share my trivially simple code example from my slides.

Writing a Generator

The generators use the yield keyword to feed values out as they are iterated over. In code, they really look a lot like a function (or method):

<?php
function getValues() {
    // totally trivial example
    yield "Apple";
    yield "Ball";
    yield "Cat";
}

The main difference is that this "function" will retain its state and yield the next value when it is used again.

Using a Generator

It's not obvious from the calling code that a generator is in use - and that's a feature IMO. Here's an example that uses the generator declared above:

<?php
$stuff = getValues();

foreach($stuff as $thing) {
    echo $thing . "\n";
}


From this, you might assume that getValues() returns an iterator or array. I can imagine refactoring applications that absolutely do expect either of those to use generators instead, so that's intentional! If you do var_dump($stuff), however, you'll see an object of type Generator.

Each time the foreach tries to fetch the next item from $stuff, the getValues() generator gets called, and runs until a yield statement causes a value to be emitted.

When To Use Generators

There's nothing in these examples that makes a generator a better choice than, say, returning an array, so why are generators even useful? For the most part, they will be great for either formulaic or very large datasets. If you wanted to perform some task on all prime numbers up to ten digits long, you could certainly generate a list and iterate over it. However, that list could be quite large, and the generator could calculate and supply the next value on an as-needed basis.

The other use is for data sets which are large in comparison to the size of the memory available to PHP. A generator could fetch data in a loop, or read incrementally from a stream, and only have that one piece of data hanging around in PHP's memory at any one time.

Looking Forward to Generators

Generators are just one more in a long string of understated features coming in to the newer versions of PHP, but it's one that will make your data-heavy applications run light and quick - I can't thank the PHP core team enough for bringing us this feature!

Lorna is an independent web development consultant, author and trainer, available for work (interesting projects only). This post was originally published at LornaJane

Catégories: Open Source, PHP Community
Syndiquer le contenu