Feed aggregator

Juan Treminio: Unit Testing Tutorial Part V: Mock Methods and Overriding Constructors

PHPDeveloper.org - Fri, 05/04/2013 - 16:38

Juan Treminio has posted the latest part of his unit testing series to his site today - the fifth part that looks at using mock methods on mock objects and overriding constructors.

Previously in my PHPUnit tutorial series, you learned about the very powerful concept of mock objects and stub methods. This concept is central to successful unit testing, and once it fully 'clicks' in your head you will start to realize how useful and simple testing can be. There is also another thing I want to make clear: creating tests is basically a puzzle - you simply have to go step by step, making sure all the pieces fit together correctly so you can get your green. I hope to make clear what I mean by the end of this tutorial.

He assumes you already know about mock objects and introduces the concept of "stub methods" and "mock methods", noting the difference between them. He then gets into what he calls the "four pathways of getMockBuilder" and talks about the rationale behind mocking methods in the first place. He then gets into constructors and how you can work around the "bad" ones with help from mock object functionality.

If you're interested in reading the rest of the series, you can find links to them here.

Link: http://jtreminio.com/2013/03/unit-testing-tutorial-part-5-mock-methods-and-overriding-constructors/

Community News: Packagist Latest Releases for 04.05.2013

PHPDeveloper.org - Fri, 05/04/2013 - 15:07
Recent releases from the Packagist:

Are we missing out on true learning opportunities?

Planet-PHP - Fri, 05/04/2013 - 13:00
“Using singletons is bad. Don’t do it, ever.” “Don’t micro optimize your code! It’s pointless!” “Don’t worry about performance until you have performance problems.” “100% code coverage is necessary for your unit tests.” “No optimization without benchmarking first!” We’ve all said these things at some time or another to a junior developer that we were [...]
Categories: Open Source, PHP Community

PHPBuilder.com: Building a PHP RSS Aggregator

PHPDeveloper.org - Thu, 04/04/2013 - 20:09

On PHPBuilder.com today there's a quick tutorial showing you how to build an RSS aggregator that can pull in RSS content and drop it into a MySQL table.

RSS stands for Really Simple Syndication. It is a Web format that allows website owners to distribute their latest and frequently updated content in a standardized way. RSS feed is actually an XML document that can be easily read by using RSS reader software or built-in functions in programming languages, such as PHP or Java. In this article, the focus will be on building a RSS aggregator in PHP.

They introduce the basics of an RSS feed - a specially formatted XML document with values for individual posts (like "title" and "link". They provide the SQL structure for the "article" and "feed" tables and the code to pull out each "feed" record, parse it and drop that into the "article" table for later consumption. They show two different methods for getting the content - one using file_get_contents and another using cURL.

Link: http://www.phpbuilder.com/articles/php-functions/xml/building-a-php-rss-aggregator.html

PHPMaster.com: Multi-Language Support in CodeIgniter

PHPDeveloper.org - Thu, 04/04/2013 - 19:52

New on PHPMaster.com there's a tutorial by Rakhitha Nimesh about using the multi-language support to CodeIgniter applications. This functionality is included as a default part of the framework using internal language files.

Multi-language support, also known as internationalization, is a key feature of modern web applications. Most of the full-stack PHP frameworks come with multi-language support which enables us to dynamically present our application's interface in different languages without duplicating the existing source code for each language. Today we're going to discuss how we can enable multiple languages using CodeIgniter as well as a few tricks to customize the core functionality.

He shows where in the configuration to set the default language and where you'll need to put the language files so CodeIgniter can find them. Sample code shows how to load in the language files and how to pass certain values out to the view for display. He also includes an example of using CodeIgniter's own hooks system to call the language file load via a "LanguageLoader" class after the controller instance is created.

Link: http://phpmaster.com/multi-language-support-in-codeigniter/

MaltBlue.com: Zend Framework 2 Forms - Simple and Available Everywhere

PHPDeveloper.org - Thu, 04/04/2013 - 18:29

Matt Setter has a new post to his site today about forms in Zend Framework 2 including a full example on how to use them to create a form for user information (first name, last name).

I think it goes without saying, forms are one of the central elements of any web-based application. They're used for everything from logging in, to searching content and managing information. Given that, they should be first-class citizens, able to be developed and reused with relative ease. [...] However, given the amount of options, configurability and flexibility required, this isn't always easy. [...] In today's post, I'm going to assume you have a basic understanding of how forms work now. [...] I'm going to show you how to create flexible, reusable forms in one module and by the power of the ServiceManager reuse them throughout your application.

He starts with the inclusion of a dependency needed for his example - the ZfcUser component (installed via Composer). He then moves on to the actual code for the form creating a reusable module, an entity class for the User and the Fieldset/Form classes for the contents of the form. He also includes the code for the controller action and the view that outputs the form itself and handles the repopulation automagically (and includes a CSRF token).

Link: http://www.maltblue.com/zend-framework/simple-zend-framework-2-forms

Igor Wiedler: Stateless Services

PHPDeveloper.org - Thu, 04/04/2013 - 17:41

Igor Wiedler has a recent post to his site about creating stateless services, specifically in the context of using a dependency injection container to manage the objects your application uses.

As more frameworks and libraries, particularly in the PHP world, move towards adopting the Dependency Injection pattern they are all faced with the problem of bootstrapping their application and constructing the object graph. In many cases this is solved by a Dependency Injection Container (DIC). Such a container manages the creation of all the things. The things it manages are services. Or are they?

He notes that, according to some of the principles of domain-driven design, "services" should be stateless - the results of calls to the service shouldn't alter it, it should only depend on the values passed in. He goes on to put this into the context of a DIC and gives an example of the "request service" (and how it violates the DDD principles of statelessness). He talks some about scopes (dependencies) and mutable services. He talks about methods to get around these issues with the "request" instance, ultimately coming to the conclusion that event listeners might be the way to go.

Link: https://igor.io/2013/03/31/stateless-services.html

Andrew Podner: Make it Testable-No Matter how Painful it is

PHPDeveloper.org - Thu, 04/04/2013 - 16:39

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. Link: http://unassumingphp.com/make-it-testable-no-matter-how-painful-it-is/

Community News: Packagist Latest Releases for 04.04.2013

PHPDeveloper.org - Thu, 04/04/2013 - 15:04
Recent releases from the Packagist:

Making Your App Infintely More Testable

Planet-PHP - Thu, 04/04/2013 - 14:00
You’re writing a PHP application. You know you need to write tests. Tests aren’t something that comes naturally to you yet; you’re still working on learning the ins and outs of PHPUnit (the default standard framework). But you know that right now, your app isn’t testable. What can you do to make it testable? The [...]
Categories: Open Source, PHP Community

PostgreSQL 9.2.4, 9.1.9, 9.0.13 and 8.4.17 released

Postgresql.org - Thu, 04/04/2013 - 02:00

The PostgreSQL Global Development Group has released a security update to all current versions of the PostgreSQL database system, including versions 9.2.4, 9.1.9, 9.0.13, and 8.4.17. This update fixes a high-exposure security vulnerability in versions 9.0 and later. All users of the affected versions are strongly urged to apply the update immediately.

A major security issue fixed in this release, CVE-2013-1899, makes it possible for a connection request containing a database name that begins with "-" to be crafted that can damage or destroy files within a server's data directory. Anyone with access to the port the PostgreSQL server listens on can initiate this request. This issue was discovered by Mitsumasa Kondo and Kyotaro Horiguchi of NTT Open Source Software Center.

Two lesser security fixes are also included in this release: CVE-2013-1900, wherein random numbers generated by contrib/pgcrypto functions may be easy for another database user to guess, and CVE-2013-1901, which mistakenly allows an unprivileged user to run commands that could interfere with in-progress backups. Finally, this release fixes two security issues with the graphical installers for Linux and Mac OS X: insecure passing of superuser passwords to a script, CVE-2013-1903 and the use of predictable filenames in /tmp CVE-2013-1902. Marko Kreen, Noah Misch and Stefan Kaltenbrunner reported these issues, respectively.

We are grateful for each developer's efforts in making PostgreSQL more secure.

This release also corrects several errors in management of GiST indexes. After installing this update, it is advisable to REINDEX any GiST indexes that meet one or more of the conditions described below.

This update release also contains fixes for many minor issues discovered and patched by the PostgreSQL community in the last two months, including:

  • Fix GiST indexes to not use "fuzzy" geometric comparisons for box, polygon, circle, and point columns
  • Fix bugs in contrib/btree_gist for GiST indexes on text, bytea, bit, and numeric columns
  • Fix bugs in page splitting code for multi-column GiST indexes
  • Fix buffer leak in WAL replay causing "incorrect local pin count" errors
  • Ensure crash recovery before entering archive recovery during unclean shutdown when recovery.conf is present
  • Avoid deleting not-yet-archived WAL files during crash recovery
  • Fix race condition in DELETE RETURNING
  • Fix possible planner crash after adding columns to a view depending on another view
  • Eliminate memory leaks in PL/Perl's spi_prepare() function
  • Fix pg_dumpall to handle database names containing "=" correctly
  • Avoid crash in pg_dump when an incorrect connection string is given
  • Ignore invalid indexes in pg_dump and pg_upgrade
  • Include only the current server version's subdirectory when backing up a tablespace with pg_basebackup
  • Add a server version check in pg_basebackup and pg_receivexlog
  • Fix contrib/dblink to handle inconsistent settings of DateStyle or IntervalStyle safely
  • Fix contrib/pg_trgm's similarity() function to return zero for trigram-less strings
  • Enable building PostgreSQL with Microsoft Visual Studio 2012
  • Update time zone data files for DST law changes in Chile, Haiti, Morocco, Paraguay, and some Russian areas

As always, update releases only require installation of packages and a database system restart. You do not need to dump/restore or use pg_upgrade for this update release. Users who have skipped multiple update releases may need to perform additional, post-update steps; see the Release Notes for details.

Links:

Categories: PHP Community

QaFoo.com: Code Coverage with Behat

PHPDeveloper.org - Wed, 03/04/2013 - 19:37

On the QaFoo blog today there's a post for those using the Behat testing tool showing a way to collect code coverage metrics based on your tests using the PHP_CodeCoverage library and phpcov.

There is generally no point in having code coverage for Behat test cases because of their nature: The purpose of an acceptance test is to assert a certain behavior of an application, not to technically test a piece of code. Therefore, there is no point in checking for uncovered code pieces in order to write a Behat test for it. That said, there is still a scenario where you want to peek at code coverage of Behat tests: When creating them as wide-coverage tests before starting to refactor legacy code. Behat in combination with Mink provides you with a great tool for such tests.

They help you get the tools installed and show the code you'll need to add to the application itself to collect the coverage data as the tests execute. It keys off of a file existing/not existing to know if it should execute the coverage or not. The phpcov tool can then be used to generate the HTML output of the coverage information for easy viewing.

Link: http://qafoo.com/blog/040_code_coverage_with_behat.html

php|architect: March 2013 Issue Released - APIs

PHPDeveloper.org - Wed, 03/04/2013 - 18:51

The March issue of php|architect magazine has been published and this month it's all about APIs. Articles in this issue include:

  • Building APIs in Zend Framework 2 (Chris Tankersley)
  • Good API Design Is Not a Fairy Tale (Keith Casey)
  • API Documentation and Testing with I/O Docs (Jason McCreary)
  • Education Station: Fix Poorly Written Legacy Code with PHP-CS-Fixer (Matthew Setter)
  • (Re)Introducing Magento: Configuration XML (Ben Marks)

You can pick up this single issue for about $5 USD or you can subscribe for a full 12 issues (PDF edition).

Link: http://www.phparch.com/2013/04/phparchitect-march-issue-apis/

Systems Architect: Distributed application in PHP with Apache Zookeeper

PHPDeveloper.org - Wed, 03/04/2013 - 17:24

On his Systems Architect site Lukasz Kujawa has posted an introduction to Apache Zookeeper and how to use it in your PHP applications. Zookeeper is "a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services."

Apache ZooKeeper is the coolest technology I recently came across. I found it when I was doing a research about Solr Cloud features. [...] Running multiple application as one logical program is nothing new. In fact creating such a software was one of my first jobs many years ago. This type of architecture is confusing and very tricky to work with. Apache ZooKeeper tries to provide a generic set of tools to manage such a software.

He shows you how to get the PHP extension for Zookepper (along with needed libraries) compiled and installed in your server setup. He includes a sample class that shows you how to connect to the Zookepper server and add a "watcher" your PHP script will respond to when changes happen. The post also has a "Watcher" class example, showing how to use Zookeeper as part of a distributed application. There's some links at the bottom of the post that can also help you get more details on Zookeeper and the PHP interface.

Link: http://systemsarchitect.net/distributed-application-in-php-with-apache-zookeeper/

Community News: Web & PHP Conference 2013

PHPDeveloper.org - Wed, 03/04/2013 - 16:16

The folks behind the Web & PHP Magazine have announced a new event they'll be putting on in San Jose, California in September of this year - the Web & PHP Conference. It's a four day conference featuring sessions, keynotes, an expo and "open knowledge sharing".

Web & PHP Magazine invites you to its first ever conference. This four-day event in September will immerse you in a world of continuously changing and evolving web technologies. Developers will get together and trade great ideas at Web & PHP Con. Whether your interests lay in core PHP, security, testing, architecture, frameworks or cloud, this is the place for you. Maybe HTML5, CSS3, responsive design, UX, mobile web or web-based mobile apps are where it's at for you. That's okay - we'll have loads. And if Agile, DevOps, Continuous Delivery or strategies are in your presentation bucket list, you won't be disappointed. Come and hear about latest technologies and methods, discuss your own project developments and find new solutions.

They've also opened their call for papers so you can submit your own ideas to present. There's a wide range of themes they're looking for at the event including things like:

  • Core PHP
  • Testing & Quality
  • HTML5 & CSS3
  • Mobile Web, Responsive Design
  • User Experience Design (UX)
  • E-Commerce, Magento, etc

Hurry and get your submissions in though - the deadline is April 26th!

Link: http://webandphp.com/conference/webandphpcon2013

Community News: Packagist Latest Releases for 04.03.2013

PHPDeveloper.org - Wed, 03/04/2013 - 15:06
Recent releases from the Packagist:

Community News: Latest Releases from PHPClasses.org

PHPDeveloper.org - Wed, 03/04/2013 - 14:02

Code Coverage with Behat

Planet-PHP - Wed, 03/04/2013 - 07:52
There is generally no point in having code coverage for Behat test cases because of their nature: The purpose of an acceptance test is to assert a certain behavior of an application, not to technically test a piece of code. Therefore, there is no point in checking for uncovered code pieces in order to write a Behat test for it.That said, there is still a scenario where you want to peek at code coverage of Behat tests: When creating them as wide-coverage tests before starting to refactor legacy code. Behat in combination with Mink provides you with a great tool for such tests.
Categories: Open Source, PHP Community
Syndicate content