chadcf

Using PHPUnit Fixtures with Behat and Mink

This seems like something that should be fairly trivial but the fixture functionality for PHPUnit's DBUnit is mostly encapsulated in one class which is designed to be used in Test Cases. Since PHP doesn't support multiple inheritance this poses somewhat of a problem if you are using Behat and Mink for BDD but want to be able to easily reset your database after each test. There are some other options out there, using Doctrine or ezComponents, but for me it seemed like DBUnit was the easiest thing to integrate especially since I was already using PHPUnit.

Mocking Authorize.net with VCR and webmock

Recently I was faced with making some fairly major changes to a Transaction class for a project, with exactly 0 tests written for it. This class is responsible for taking in information on an order (products, customer, etc), billing the customer via authorize.net and saving the appropriate entries to the database. It's a bit heavy and not exactly an ideal class, but it works and the goal is to now modify the way it works without breaking anything. Obviously, having tests is a good idea here.

Introducing stamp for PHP - simple date formatting

A while back I discovered the excellent stamp gem for ruby. It gives you a fantastic way to format dates by simply supplying an example string, rather than having to remember the various formatting parameters to traditional date formatting functions. I've found this so useful that I had to create a PHP version, which I also lamely called stamp.

Stamp provides a simple method to format dates. For example:

Using capybara as a javascript capable replacement for Mechanize

Recently I had a task come to me, to update a content scraper that was written years ago with Ruby and Mechanize. Unfortunately in the interim, the site had been completely revamped and was useless without javascript. Even though mechanize has been updated over the years, it still does not support javascript. This left me in something of a quandry... So I though, well, I do testing of rails apps that is essentially like screen scraping, and I have used a driver that supports javascript...

Why I love rails

has_many :sales, :foreign_key => :CardID do
  def most_recent
    first(:order => "DateSold DESC")
  end
  def active
    first(:conditions => ["EffectiveDate <= :date AND ExpirationDate >= :date", {:date => Time.now}])
  end
end

There you go.

@object.sales = array of all sales
@object.sales.most_recent = most recent sale
@object.sales.active = sale with a date range that contains today

Drupal Performance and Scaling Part 1 - Anonymous Users

Recently I got curious about how well, overall, Drupal performs and how well it can be made to scale. I've been doing some experimenting with different setups and benchmarking and thought I'd offer, in one place a nice summary of the options available to scale drupal websites and my opinion of the various options. The first part of this covers the basic built in drupal performance features and is a good introduction for new users. After that we'll explore some more advanced scaling techniques.

© 2013 chadcf