当前位置: 首页>>代码示例>>PHP>>正文


PHP UnitTester::assertThrows方法代码示例

本文整理汇总了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.');
 }
开发者ID:objective-php,项目名称:serializer,代码行数:9,代码来源:ResourceTest.php

示例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.');
 }
开发者ID:objective-php,项目名称:serializer,代码行数:14,代码来源:EncoderTest.php

示例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);
 }
开发者ID:objective-php,项目名称:serializer,代码行数:15,代码来源:NormalizerTest.php

示例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);
 }
开发者ID:objective-php,项目名称:serializer,代码行数:16,代码来源:SerializerTest.php


注:本文中的UnitTester::assertThrows方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。