首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在PHPUnit中对当前测试类进行预测?

如何在PHPUnit中对当前测试类进行预测?
EN

Stack Overflow用户
提问于 2017-01-01 19:04:09
回答 0查看 740关注 0票数 0

我有这样一个案例,我想运行PHPUnit测试并检查当前测试类的行为,如下所示:

代码语言:javascript
复制
public function it_allows_to_add_items()
{
        // Create prophesies
        $managerProphecy = $this->getProphet(ListingManager::class);
        $listingItemProphecy = $this->getProphet(ListingItemInterface::class);

        $listing = factory(\App\Misc\Listings\Listing::class)->create();
        $manager = new ListingManager($listing);

        $item = factory(\App\Misc\Listings\ListingItem::class)->make(['listing_id' => null]);
        $item2 = factory(\App\Misc\Listings\ListingItem::class)->make(['listing_id' => null]);

        $manager->addItem($item);
        $managerProphecy->validate($listingItemProphecy)->shouldBeCalledTimes(2);
        $manager->addItem($item2);

        $this->assertTrue(true);
    }

这有可能吗?

我当然会得到

代码语言:javascript
复制
1) GenericListingManagerTest::it_allows_to_add_items
Some predictions failed:
  Double\App\Misc\Listings\ListingManager\P2:
    Expected exactly 2 calls that match:
      Double\App\Misc\Listings\ListingManager\P2->validate(exact(Double\ListingItemInterface\P1:00000000058d2b7a00007feda4ff3b5f Object (
        'objectProphecy' => Prophecy\Prophecy\ObjectProphecy Object (*Prophecy*)
    )))
    but none were made.
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41414984

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档