Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用私钥/公钥与PHPunit进行外部API集成测试_Php_Api_Laravel_Phpunit_Laravel 5.3 - Fatal编程技术网

使用私钥/公钥与PHPunit进行外部API集成测试

使用私钥/公钥与PHPunit进行外部API集成测试,php,api,laravel,phpunit,laravel-5.3,Php,Api,Laravel,Phpunit,Laravel 5.3,我正在尝试为使用XeroAPI的web应用程序编写一些集成测试。我正在使用PHP单元和Laravel5.3框架。无论何时运行测试,我都会遇到500个错误,我猜这与未找到私钥/公钥有关,或者可能与未找到.env文件中的API密钥有关。如果我在浏览器中运行应用程序,我会得到预期的结果,没有错误 我有三个文件(ca bundle.crt、privatekey.pem和publickey.cer)位于目录certs/Xero中,还有两个API密钥位于我的文件中。所有这些都是API调用所需要的 我的测试文

我正在尝试为使用XeroAPI的web应用程序编写一些集成测试。我正在使用PHP单元和Laravel5.3框架。无论何时运行测试,我都会遇到500个错误,我猜这与未找到私钥/公钥有关,或者可能与未找到
.env
文件中的API密钥有关。如果我在浏览器中运行应用程序,我会得到预期的结果,没有错误

我有三个文件(
ca bundle.crt
privatekey.pem
publickey.cer
)位于目录
certs/Xero
中,还有两个API密钥位于我的
文件
中。所有这些都是API调用所需要的

我的测试文件包含以下代码:

<?php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class XeroGatewayTest extends TestCase
{
  use DatabaseTransactions;

  /** @test */ 
  public function it_returns_a_list_of_invoices_for_a_customer()
  {
    $customer = factory(App\Customer::class)->create();

    $this->get('/api/changes/invoices/'.$customer->id);

    $this->assertResponseOk();
    $this->seeJson();
  }
}
配置文件被传递到其构造函数中的自定义
XeroServiceProvider
类中。然后使用该类进行API调用

现在,当我在浏览器中运行应用程序时,我得到了我想要的结果(一个包含客户发票详细信息的json对象)。但是,当我在终端中运行测试时,我得到:

1) XeroGatewayTest::it_returns_a_list_of_invoices_for_a_customer
Expected status code 200, got 500.
Failed asserting that false is true.

/home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:663
/home/ubuntu/workspace/tests/integration/invoicing/XeroGatewayTest.php:18

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
我还更新了我的
composer.json
文件,包括以下内容:

<?php

return [

  'xero' => [
    'core_version'    => '2.0',
    'payroll_version' => '1.0',
    'file_version'    => '1.0',
  ],

  'oauth' => [
    'callback' => 'oob',

    'consumer_key'    => env('XERO_KEY'),
    'consumer_secret' => env('XERO_SECRET'),

    'rsa_private_key' => file_get_contents(__DIR__.'/../certs/Xero/privatekey.pem'),
    'rsa_public_key'  => file_get_contents(__DIR__.'/../certs/Xero/publickey.cer'),
  ],

  'curl' => [
    CURLOPT_USERAGENT => 'The Builder',
    CURLOPT_CAINFO    => '../certs/Xero/ca-bundle.crt',
  ]

];
{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.3.16",
        "calcinai/xero-php": "^1.3"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.0",
        "symfony/css-selector": "3.1.*",
        "symfony/dom-crawler": "3.1.*"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ],
        "files": [
            "certs/Xero/ca-bundle.crt",
            "certs/Xero/privatekey.pem",
            "certs/Xero/publickey.cer",
        ],
    },
...

非常感谢您提供的任何帮助/建议。

您能通过
$this->dump()
显示整个响应吗?哈哈!在用
$this->dump()显示响应后,我可以看到
ca bundle.crt
文件有问题。我只需要将
\uuuu DIR\uuuu
添加到该文件路径,现在一切都好了。感谢您的帮助。您能通过
$this->dump()显示整个响应吗?
!在用
$this->dump()显示响应后,我可以看到
ca bundle.crt
文件有问题。我只需要将
\uuuu DIR\uuuu
添加到该文件路径,现在一切都好了。谢谢你的帮助