本文整理汇总了PHP中UnitTester::assertThrows方法的典型用法代码示例。如果您正苦于以下问题:PHP UnitTester::assertThrows方法的具体用法?PHP UnitTester::assertThrows怎么用?PHP UnitTester::assertThrows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitTester
的用法示例。
在下文中一共展示了UnitTester::assertThrows方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testResourceSetCanGetAResourceChild
public function testResourceSetCanGetAResourceChild()
{
$resource1 = new Resource();
$this->resourceSet->addChild($resource1);
$this->assertEquals($resource1, $this->resourceSet->getResource($resource1->getId()));
$this->tester->assertThrows(function () {
$this->resourceSet->getResource('reallyInvalidId');
}, 'Exception', 'An exception as to be thrown.');
}
示例2: testJsonEncoder
public function testJsonEncoder()
{
$encoder = new JsonEncoder();
$resource = (new Resource())->setName('resource test');
$resourceSet = (new ResourceSet())->addChild($resource);
$encoder->setFormatter(new TestFormatter());
$encodedData = $encoder->encode($resource);
$this->assertEquals('{"name":"resource-test"}', $encodedData);
$encodedData = $encoder->encode($resourceSet);
$this->assertEquals('[{"name":"resource-test"}]', $encodedData);
$this->tester->assertThrows(function () use($encoder) {
$encoder->decode('somethingsomething');
}, 'Exception', 'An exception as to be thrown.');
}
示例3: testDoctrineNormalizer
public function testDoctrineNormalizer()
{
$normalizer = new DoctrineNormalizer();
$normalizer->setBaseUri('http://example.com/');
$this->tester->assertThrows(function () use($normalizer) {
$normalizer->normalize('somethingsomething');
}, 'Exception', 'An exception as to be thrown.');
$normalizer->setEntityManager($this->em);
$resource = $normalizer->normalize($this->album);
$this->assertEquals('http://example.com/', $normalizer->getBaseUri());
$this->assertInstanceOf(Resource::class, $resource);
$this->assertEquals($this->em, $normalizer->getEntityManager());
$resourceSet = $normalizer->normalize($this->albums);
$this->assertInstanceOf(ResourceSet::class, $resourceSet);
}
示例4: testSerializer
public function testSerializer()
{
$serializer = new Serializer();
$serializer->setPaginator(new PagerFantaAdapter(new Pagerfanta(new ArrayAdapter([$this->testData]))));
$this->tester->assertThrows(function () use($serializer) {
$serializer->serialize('somethingsomething');
}, 'Exception', 'An exception as to be thrown.');
$serializer->setNormalizer($this->normalizer);
$this->tester->assertThrows(function () use($serializer) {
$serializer->serialize('somethingsomething');
}, 'Exception', 'An exception as to be thrown.');
$serializer->setFormatter($this->formatter);
$serializer->setEncoder($this->encoder);
$serializedData = $serializer->serialize($this->testData);
$this->assertEquals('{"name":"data","page":1}', $serializedData);
}