我如何在PHPUnit中assertInstanceOf()?

我已经为单元测试编写了这段代码

<?PHP

namespace tests;

use data\address\Address;
use lists\Collection;
use PHPUnit\Framework\TestCase;

class CollectionTest extends TestCase
{
    public function testIsCollectionOf()
    {
        $Collection = new Collection(Address::class);
        $this->assertInstanceOf($Collection, Collection::class);
    }
}

当我跑过它时,我得到了这个错误

PHPUnit 5.4.6 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.0.6-6+donate.sury.org~trusty+1
Configuration: /var/www/project/PHPunit.xml

E                                                                   1 / 1 (100%)


Time: 33 ms, Memory: 2.00MB

There was 1 error:

1) tests\CollectionTest::testIsCollectionOf
PHPUnit_Framework_Exception: Argument #1 (No Value) of PHPUnit_Framework_Assert::assertInstanceOf() must be a class or interface name

/var/www/project/vendor/PHPunit/PHPunit/src/Util/InvalidArgumentHelper.PHP:30
/var/www/project/vendor/PHPunit/PHPunit/src/Framework/Assert.PHP:1323
/var/www/project/tests/CollectionTest.PHP:19
/var/www/project/vendor/PHPunit/PHPunit/src/Framework/TestCase.PHP:1081
/var/www/project/vendor/PHPunit/PHPunit/src/Framework/TestCase.PHP:932
/var/www/project/vendor/PHPunit/PHPunit/src/Framework/TestResult.PHP:701
/var/www/project/vendor/PHPunit/PHPunit/src/Framework/TestCase.PHP:888
/var/www/project/vendor/PHPunit/PHPunit/src/Framework/TestSuite.PHP:753
/var/www/project/vendor/PHPunit/PHPunit/src/TextUI/TestRunner.PHP:465
/var/www/project/vendor/PHPunit/PHPunit/src/TextUI/Command.PHP:162
/var/www/project/vendor/PHPunit/PHPunit/src/TextUI/Command.PHP:113

ERRORS!
Tests: 1, Assertions: 0, Errors: 1

现在如果我var_dump($Collection)我得到了:

object(Collection)#18 (2) {
  ["class_name":"Collection":private]=>
  string(32) "data\address\Address"
  ["_items":protected]=>
  array(0) {
  }
}

为什么?我的测试用例有什么问题?

解决方法:

参数的顺序是错误的.试试这个:

$this->assertInstanceOf(Collection::class, $Collection);

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...