为什么类GuzzleHttp \ Client的对象无法转换为字符串?

时间:2017-10-23 16:30:35

标签: php oauth guzzle

这是我的方法

class MyClass 
{
  protected client; 
  public function setCl($clientArg)
  {
    // check for invalid argument type - client has to be a guzzle client
    if ($clientArg.get_class() != $this->client.get_class() ||
      !($clientArg instanceof GuzzleHttp\Client))
      throw new InvalidArgumentException("Argument type must be of Guzzle client");

    $this->client = $clientArg;
  }
}

测试已经调用了这个方法:

class TestClass extends \PHPUnit_Framework_TestCase 
{
  protected $myClass
  public function testSetCl() {
    $cl = new Client();
    $res = $this->myClass->setCl($cl); // why does a setter need to return something?

    $this->assertInstanceOf(Client::class, $res);
  }
}

标题中发布的错误是我在运行测试时收到的错误。为什么呢?

1 个答案:

答案 0 :(得分:0)

发生这种情况的原因是:

$clientArg.get_class() != $this->client.get_class()

在PHP中,。是串联,因此当改为:

$clientArg->get_class() != $this->client->get_class()

这很有效。