exception() 공개 정적인 메소드

Checks if the function throws exception.
public static exception ( callable $function, $class, $message = NULL, $code = NULL ) : Exception
$function callable
리턴 Exception
예제 #1
0
파일: Helper.php 프로젝트: Kaliver/grido
 public static function assertTypeError($function)
 {
     if (PHP_VERSION_ID < 70000) {
         Assert::error($function, E_RECOVERABLE_ERROR);
     } else {
         Assert::exception($function, '\\TypeError');
     }
 }
예제 #2
0
 public function testFetchLastRawRows()
 {
     $source = $this->createArraySourceWithDataStructure();
     Assert::exception(function () use($source) {
         $source->fetchLastRawRows();
     }, InvalidStateException::class);
     $source->fetchAll();
     $rawData = $source->fetchLastRawRows();
     Assert::count(self::FULL_USER_COUNT, $rawData);
     foreach ($rawData as $item) {
         Assert::type(ArrayHash::class, $item);
     }
 }
예제 #3
0
 public function testFetchLastRawRows()
 {
     $source = new NetteDbTableSource($this->tableName, 'id', $this->user, $this->context);
     Assert::exception(function () use($source) {
         $source->fetchLastRawRows();
     }, InvalidStateException::class);
     $source->fetchAll();
     $rawData = $source->fetchLastRawRows();
     Assert::count(self::FULL_USER_COUNT, $rawData);
     foreach ($rawData as $item) {
         Assert::type(Database\Table\ActiveRow::class, $item);
     }
 }
예제 #4
0
 public function testExportFiltered()
 {
     $data = $this->data;
     $callback = function ($source) use($data) {
         Assert::same($data, $source);
     };
     $export = $this->grid->addExportCallback('Export', $callback, TRUE);
     $this->grid->addFilterText('name', 'Name');
     $grid = $this->grid;
     $trigger = function () use($grid) {
         $this->grid->handleExport(1);
     };
     Assert::exception($trigger, 'Ublaboo\\DataGrid\\Exception\\DataGridException', 'You have to set a data source first.');
     $this->grid->setDataSource($this->data);
     $this->grid->handleExport(1);
 }
예제 #5
0
 /**
  * @dataProvider dataObjectClasses
  */
 public function testGetIdInvalidObject($class)
 {
     $metadata = $this->getMetadataFor($class);
     $object = new \stdClass();
     Assert::exception(function () use($metadata, $object) {
         $metadata->getId($object);
     }, 'NForms\\Exceptions\\MetadataException');
 }
예제 #6
0
 public final function testMaxRedirects()
 {
     $client = $this->createClient();
     $client->onRequest(function () use(&$counter) {
         $counter++;
     });
     $request = new Request('GET', $this->baseUrl . '/redirect-loop', ['X-Max-Loop-Count' => 5]);
     $client->maxRedirects = 6;
     $counter = -1;
     $response = $client->process(clone $request);
     Assert::same(5, $counter);
     Assert::same('Redirection finished', $response->getBody());
     Assert::same(200, $response->getCode());
     $client->maxRedirects = 5;
     $counter = -1;
     $response = $client->process(clone $request);
     Assert::same(5, $counter);
     Assert::same('Redirection finished', $response->getBody());
     Assert::same(200, $response->getCode());
     $client->maxRedirects = 4;
     $counter = -1;
     Assert::exception(function () use($client, $request) {
         $client->process($request);
     }, 'Bitbang\\Http\\RedirectLoopException', 'Maximum redirect count (4) achieved.');
     Assert::same(4, $counter);
 }
예제 #7
0
<?php

use Tester\Assert;
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/Token.php";
//valid value
$value = str_repeat('BeerNowThere0sATemporarySolution', 2);
$tokenFoo = new Token($value);
Assert::same("BeerNowThere0sATemporarySolutionBeerNowThere0sATemporarySolution", $tokenFoo->getValue());
//compare with another object of same value
$tokenBar = new Token("BeerNowThere0sATemporarySolutionBeerNowThere0sATemporarySolution");
$areSame = $tokenBar->sameValueAs($tokenFoo);
Assert::true($areSame);
//compare with another object of different value
$value = str_repeat('CraftBeerLovers0', 4);
//
$tokenPub = new Token($value);
Assert::same("CraftBeerLovers0CraftBeerLovers0CraftBeerLovers0CraftBeerLovers0", $tokenPub->getValue());
$areSame = $tokenPub->sameValueAs($tokenBar);
Assert::false($areSame);
//invalid values
Assert::exception(function () {
    new Token(null);
}, InvalidArgumentException::class, "Token must be not empty");
Assert::exception(function () {
    new Token("InvalidTokenLength123456789");
}, InvalidArgumentException::class, "Token must be 64 characters long");
Assert::exception(function () {
    $value = str_repeat('?!@#$%^&', 8);
    new Token($value);
}, InvalidArgumentException::class, "Token must be valid base_64");
예제 #8
0
//-------------------------
// read
Assert::exception(function () {
    r('[');
}, 'transit\\TransitException');
Assert::exception(function () {
    r('{}');
}, 'transit\\TransitException');
Assert::exception(function () {
    r('["~#\'"]');
}, 'transit\\TransitException');
Assert::exception(function () {
    r('["^ ",1]');
}, 'transit\\TransitException');
Assert::exception(function () {
    r('["~#\'",1,2]');
}, 'transit\\TransitException');
Assert::equal('foo', r('"foo"'));
Assert::equal(0, r('0'));
Assert::equal(1, r('1'));
Assert::equal(2, r('2'));
Assert::equal(2.5, r('2.5'));
Assert::equal(null, r('null'));
Assert::equal(true, r('true'));
Assert::equal(false, r('false'));
Assert::nan(r('"~zNaN"'));
Assert::equal(INF, r('"~zINF"'));
Assert::equal(-INF, r('"~z-INF"'));
Assert::equal(new Keyword('a'), r('"~:a"'));
Assert::equal(new Symbol('a'), r('"~$a"'));
Assert::equal('foo', r('["~#\'","foo"]'));
예제 #9
0
 public function testFetchLastRawRows()
 {
     $source = new DoctrineSource(User::class, self::OWN_PRIMARY_KEY, $this->user, $this->columnMapping);
     Assert::exception(function () use($source) {
         $source->fetchLastRawRows();
     }, InvalidStateException::class);
     $source->fetchAll();
     $rawData = $source->fetchLastRawRows();
     Assert::count(self::FULL_USER_COUNT, $rawData);
     foreach ($rawData as $item) {
         Assert::type(User::class, $item);
     }
 }