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

QaFoo:
Testing Effects of Commands With Phake::capture()
Mar 11, 2016 @ 15:15:15

On the QaFoo blog they've posted an article sharing a quick testing tip when using Phake to test APIs where the calls don't return any data.

Today I want to share a simple trick for the excellent Mocking library Phake (I wrote about it before) when testing state on APIs that don't return values.

Testing becomes harder when you are using command / query separation in your code and service operations don't return values anymore. If your command method creates objects and passes them down the stack, then you usually want to make assertions on the nature of the changes.

He gives an example of a class that creates an Order object and saves it but doesn't return a value. He shows how to update this with Phake in the test to capture and verify that the calls are correctly made and the number of products on the order is correct.

tagged: phake capture tutorial example unittest return value

Link: https://qafoo.com/blog/078_phake_capture.html

SitePoint PHP Blog:
Automate PHP with Phake – Real World Examples
Jul 10, 2014 @ 17:51:07

The SitePoint PHP blog has posted part two of their series looking at using Phake for automation in your applications. In this second part they take some of the basics they shared in part one and apply them in some more practical examples.

In part one, we covered the basics of Phake and demonstrated ways of executing tasks with it, covering groups, dependencies, and arguments. In this part, we’ll look at some sample real world applications of Phake. Note that the following examples are largely based on things that I usually do manually that need some sort of automation.

He includes three different task examples, each with the code to make them happen (and descriptions of what it's doing):

  • Uploading Files to Server with a Phake task
  • Seeding the Database
  • Syncing Data

You can find out more about Phake on the project's GitHub page (including grouping, aborting and describing tasks).

tagged: phake automate library tutorial part2 practical example

Link: http://www.sitepoint.com/automate-php-phake-real-world-examples/

Automate PHP with Phake – Introduction
Jul 07, 2014 @ 21:08:46

On the SitePoint PHP blog there's a new tutorial showing you how to automate your PHP development and deployment with Phake.

As developers, we often have to do repetitive tasks such as updating the database structure, seeding the database, writing CRUD code, running tests, and uploading files to a server. Wouldn’t it be great if we could automate these mundane tasks and proceed with solving the more important problems such as making our app more secure or more usable to our users? Phake, an automation tool written for PHP, can do those tasks for you.

They show you how to use Phake (not to be confused with this Phake) including getting it installed via Composer and the creation of a first Phakefile. The include examples of simple tasks, dependencies, grouping, adding descriptions and passing arguments. The command to run the tasks and the resulting output is also included.

tagged: phake automate introduction library

Link: http://www.sitepoint.com/automate-php-phake-introduction/

DZone.com:
PHPUnit vs. Phake cheatsheet
Apr 19, 2013 @ 14:53:45

On DZone.com today Giorgio Sironi has posted a "cheat sheet" to help you correlate the functionality of two PHP unit testing tools - PHPUnit vs Phake (for mocking objects).

Benjamin Eberlei introduced me to Phake with his recent article: it is a Composer-ready PHP library that integrates easily with PHPUnit and provides an independent Test Doubles framework, capable of producing Stubs, Mocks, and Spies. The syntax and object model reminds me of Mockito, the Java Test Double framework from the authors of Growing Object-Oriented Software. I like tools that do one thing and do it well, and after experimenting with Phake I'm using it on all new code.

He compares the two tools on a few different pieces of functionality including creating stubs, mocks and spies. Sample code is included for both sides. It's not a detailed guide by any means, but it can give you a better picture of how the two compare.

tagged: phpunit phake mock stub unittest spies compare cheetsheet

Link: http://css.dzone.com/articles/phpunit-vs-phake-cheatsheet

QaFoo.com:
Mocking with Phake
Mar 13, 2013 @ 17:53:26

On the QaFoo blog today there's a new tutorial posted showing you how to make unit test mocks with Phake, a testing tool that works a bit differently that other options (PHPUnit's own mocking and Mockery).

The use of Mock and Stub Objects is an important skill to learn when using Test Driven Development (TDD). Mock objects allow you to replace dependencies of an object with lookalikes, much like crash test dummies are used during automobile safety tests so humans aren't harmed. [...] Using Mocks in PHPUnit tests means using the built-in MockObjects library for quite some years. In the last years two contenders emerged that can be used as optional dependencies in PHPUnit. [...] This blog post introduces Phake, because it works quite differently than both PHPUnit Mock Objects and Mockery.

They include a code example of how to create mocks with Phake, showing it's different approach to defining the mocked methods. They explain each part of the code, detailing the use of the "when", "thenReturn" and "verify" methods. You can find out more about Phake and see other examples in the project's documentation.

tagged: mocking unittest phake library tutorial introduction

Link:

Mike Lively's Blog:
Pear Channel set up for Phake
Dec 31, 2010 @ 19:30:42

Mike Lively has a new post about a PEAR channel he's set up for his Phake mocking tool on his digitalsandwich.com domain.

For those that may not have caught my first post on the subject, Phake is a mock framework that I announced a couple of days ago in Introducing Phake Mocking Framework. It was recommended in the comments that I get it on a pear channel somewhere, which is something I have wanted to do but hadn’t had a reason to do until this week. Well, now there is an official Digital Sandwich Pear Channel that is hosting Phake.

Discover the channel with the PEAR installer and run the install with the path provided. He notes that the release is alpha because of the lack of documentation but, despite this, the API is stable. Also, you'll need to be using PHP 5.2+ to use the tool.

tagged: phake mock testing framework unittest pear channel

Link:

Mike Lively's Blog:
Introducing Phake Mocking Framework
Dec 29, 2010 @ 14:40:27

Mike Lively has a new post to his blog today looking at a mocking framework he's developed to work hand in hand with PHPUnit to make mocking easier and more robust.

I have used PHPUnit heavily now for the last 4 years. As anyone that is heavily involved in writing Unit Tests knows, test doubles (commonly referred to as mock objects) are a necessary part of your toolbox. The mocking options that we used to have for PHP unit testing have traditionally been fairly limited and most all of them in some form or another were ports of JMock. The way PHP operates as well as some decisions made to more closely emulate how JMock does things lead to functionality in the existing mock library for PHPUnit that for some are a hassle.

To help eliminate this hassle, he create the Phake mocking framework - a tool that comes at mocking a different way than the normal PHPUnit procedures. He includes some sample code for a class to test, a simple stub for getting a value and how to use it in a basic test. By calling a "Phake::mock()" on the class to make an object, you can call the method and run a "verify()" to ensure that the results are correct. He talks about some other options that the mocking allows too like calling a "no interaction" method on a mock and argument capturing.

tagged: mock framework unittest phake github phpunit

Link:

Pavel Shevaev's Blog:
taskman: yet another Ant alternative
Oct 14, 2010 @ 14:56:39

Pavel Shevaev has put together what he calls "yet another Ant alternative" - a tool written in PHP to create project related tasks in a style that matches the Ant and rake methods.

There is a lib-taskman project on the google code hosting where you can find the full documentation, sources and latest releases. It's probably not that elegant as rake but if you want to stick to PHP and have Ant-alike functionality without any XML programming then taskman may turn out to be handy. taskman is very simple to use, it requires only one include, all its code resides in one PHP file, and it has no external dependencies.

He includes a basic use example that sets up the build with "task_hello", "task_comma", "task_world" and "task_say" methods that each do some basic output to show the flow of the process. He also gives examples of possible uses for the tasks like database bootstrapping, auto-code generation, project deployment, etc. He also mentions two other PHP-based projects that do similar things - pake and Phake.

tagged: rake build tool taskman ant alternative phake pake

Link:


Trending Topics: