Omnipay常见的抽象类测试失败

时间:2014-04-04 17:43:19

标签: phpunit mockery omnipay

我只是看Omnipay,目的是增加对另一个网关的支持。在使用Composer安装后,我尝试运行Paypal(作为示例网关)和Omnipay Common测试。使用这两个包,我调整了bootstrap.php,以便它可以找到composer autoload文件。 Paypal测试运行良好(绿色)。

但是,常见测试失败,1次失败,38次错误。所有失败/错误都在AbstractGatewayTest,AbstractRequestTest,AbstractResponseTest中。

这让我想知道PHPUnit或Mockery如何处理模拟抽象类的方式发生了变化。我正在使用PHPUnit 3.7.34。我最近一直在使用PHPUnit 4.0。*用于Laravel项目,但Omnipay需要3.7。

composer.lock表示我正在使用Mockery 0.9.0。我在OS X Mavericks上通过macports安装了php 5.4。*。

任何人都可以了解可能会绊倒我的事情?谢谢!

编辑:示例失败消息:

有38个错误:

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

其中“...”是我的源代码区域。

1 个答案:

答案 0 :(得分:0)

根据Adrian Macneil的建议和解释,我对Omnipay常用文件进行了单独检查,单元测试确实运行为绿色(成功):

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

的产率:

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)

为了记录,我按如下方式调整bootstrap.php。这允许我在Composer作为依赖项包含它们时运行测试。我是作曲家和Laravel的新手(omnipay与Laravel无关),所以我的方法似乎不是最佳实践。谢谢你的建议!

以下版本的 bootstrap.php 遍历其源代码树(理由限制为5级),直到找到包含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__);