1

I'm just looking at Omnipay with the aim of adding support for another gateway. After installing with Composer, I tried running the Paypal (as an example gateway) and Omnipay Common tests. With both packages, I adjusted bootstrap.php so that it could locate the composer autoload file. The Paypal tests run fine (green).

However, the common tests fail with 1 failure and 38 errors. All failures/errors are in AbstractGatewayTest, AbstractRequestTest, AbstractResponseTest.

This leads me to wonder if something changed in how PHPUnit or Mockery handle mocked abstract classes. I'm using PHPUnit 3.7.34. I have most recently been using PHPUnit 4.0.* for Laravel projects, but Omnipay requires 3.7.

composer.lock indicates I'm using Mockery 0.9.0. I'm running php 5.4.* installed via macports on OS X Mavericks.

Anyone have insight into what might be tripping me up? Thanks!

EDIT: Sample failure messages:

There were 38 errors:

1) Omnipay\Common\AbstractGatewayTest::testGetShortName
BadMethodCallException: Method Mockery_0_Omnipay_Common_AbstractGateway::getDefaultParameters() does not exist on this mock object

.../vendor/omnipay/common/src/Omnipay/Common/AbstractGateway.php:53
.../vendor/omnipay/common/src/Omnipay/Common/AbstractGateway.php:40
.../vendor/mockery/mockery/library/Mockery/Container.php:426
.../vendor/mockery/mockery/library/Mockery/Container.php:210
.../vendor/mockery/mockery/library/Mockery.php:71
.../vendor/omnipay/common/tests/Omnipay/Common/AbstractGatewayTest.php:12

2) Omnipay\Common\Message\AbstractRequestTest::testInitializeWithParams
Argument 1 passed to Omnipay\Common\Message\AbstractRequest::__construct() must implement interface Guzzle\Http\ClientInterface, none given

.../vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:46
.../vendor/mockery/mockery/library/Mockery/Container.php:426
.../vendor/mockery/mockery/library/Mockery/Container.php:210
.../vendor/mockery/mockery/library/Mockery.php:71
.../vendor/omnipay/common/tests/Omnipay/Common/Message/AbstractRequestTest.php:14

where "..." is my source code area.

Edward Barnard
  • 346
  • 3
  • 17
  • What do you mean by "I adjusted bootstrap.php so that it could locate the composer autoload file"? You shouldn't need to adjust anything. Travis CI seems to be running the tests fine. You should run the tests in a separate checkout of the omnipay repository, not from your main project. – Adrian Macneil Apr 05 '14 at 02:07

1 Answers1

0

Following Adrian Macneil's advice and explanation, I did a separate checkout of the Omnipay common files, and the unit tests indeed run green (successfully):

git clone git@github.com:omnipay/common.git
cd common/
composer update --dev && composer dump-autoload
vendor/bin/phpunit 

yields:

PHPUnit 3.7.34 by Sebastian Bergmann.

Configuration read from /Users/ewb/startrib/omnipay/common/phpunit.xml.dist

...............................................................  63 / 161 ( 39%)
............................................................... 126 / 161 ( 78%)
...................................

Time: 94 ms, Memory: 8.00Mb

OK (161 tests, 258 assertions)

For the record, I adjust bootstrap.php as follows. This allows me to run the tests when they are included by Composer as dependencies. I'm new to both composer and Laravel (omnipay has nothing to do with Laravel), so my approach appears to not be best practice. Thanks for the advice!

The following version of bootstrap.php walks up its source tree (with a sanity limit of 5 levels) until it finds the directory containing vendor/autoload.php.

<?php

error_reporting(E_ALL | E_STRICT);

// Locate and include the composer autoloader
$sanity = 5;
$dir = realpath(__DIR__);
do {
    $dir = dirname($dir);
    $autoload = $dir.'/vendor/autoload.php';
} while ($sanity-- && !file_exists($autoload));
$autoloader = require $autoload;

// autoload abstract TestCase classes in test directory
$autoloader->add('Omnipay', __DIR__);
Edward Barnard
  • 346
  • 3
  • 17