當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。