예제 #1
0
 public function testThrow()
 {
     try {
         $errors = new MultiException();
         $errors->add(new Exception('Foo'));
         $errors->add(new Exception('Bar'));
         $errors->add(new Exception('Baz'));
         if (!$errors->isEmpty()) {
             throw $errors;
         }
     } catch (MultiException $ex) {
         $this->assertEquals(3, $ex->count());
         $this->assertInstanceOf(\T4\Core\Exception::class, $ex[0]);
         $this->assertInstanceOf(\T4\Core\Exception::class, $ex[1]);
         $this->assertInstanceOf(\T4\Core\Exception::class, $ex[2]);
         $this->assertEquals('Foo', $ex[0]->getMessage());
         $this->assertEquals('Bar', $ex[1]->getMessage());
         $this->assertEquals('Baz', $ex[2]->getMessage());
     }
 }
예제 #2
0
 public function testThrow()
 {
     try {
         $exception = new MultiException();
         $exception->add('Foo');
         $exception->add('Bar');
         $exception->add('Baz');
         if (!$exception->isEmpty()) {
             throw $exception;
         }
     } catch (MultiException $ex) {
         $this->assertEquals(3, $ex->count());
         $exceptions = $ex->getExceptions();
         $this->assertInstanceOf('T4\\Core\\Exception', $exceptions[0]);
         $this->assertInstanceOf('T4\\Core\\Exception', $exceptions[1]);
         $this->assertInstanceOf('T4\\Core\\Exception', $exceptions[2]);
         $this->assertEquals('Foo', $exceptions[0]->getMessage());
         $this->assertEquals('Bar', $exceptions[1]->getMessage());
         $this->assertEquals('Baz', $exceptions[2]->getMessage());
     }
 }
예제 #3
0
파일: Model.php 프로젝트: sapak12/t4
 /**
  * @param array|\T4\Core\Std $data
  * @return $this
  * @throws \T4\Core\MultiException
  */
 public function fill($data)
 {
     if ($data instanceof IArrayable) {
         $data = $data->toArray();
     } else {
         $data = (array) $data;
     }
     $errors = new MultiException();
     foreach ($data as $key => $value) {
         try {
             $this->{$key} = $value;
         } catch (Exception $e) {
             $errors->add($e);
         }
     }
     if (!$errors->isEmpty()) {
         throw $errors;
     }
     return $this;
 }