public function testCanAddSelf()
 {
     $e1 = new ExceptionCollection();
     $e1->add(new \Exception("Test"));
     $e2 = new ExceptionCollection();
     $e2->add(new \Exception("Test 2"));
     $e1->add($e2);
     $this->assertEquals("Test\nTest 2", $e1->getMessage());
 }
Пример #2
0
 public function testCanAddSelf()
 {
     $e1 = new ExceptionCollection();
     $e1->add(new \Exception("Test"));
     $e2 = new ExceptionCollection('Meta description!');
     $e2->add(new \Exception("Test 2"));
     $e3 = new ExceptionCollection();
     $e3->add(new \Exception('Baz'));
     $e2->add($e3);
     $e1->add($e2);
     $message = $e1->getMessage();
     $this->assertEquals("(Exception) Test\n" . "(Guzzle\\Common\\Exception\\ExceptionCollection)\n" . "    Meta description!\n" . "    (Exception) Test 2\n" . "    (Guzzle\\Common\\Exception\\ExceptionCollection)\n" . "        (Exception) Baz", $message);
 }
 /**
  * Add exceptions to the collection
  *
  * @param ExceptionCollection|\Exception $e Exception to add
  *
  * @return ExceptionCollection;
  */
 public function add($e)
 {
     if ($e instanceof self) {
         foreach ($e as $exception) {
             $this->exceptions[] = $exception;
         }
     } elseif ($e instanceof \Exception) {
         $this->exceptions[] = $e;
     }
     $this->message = implode("\n", array_map(function ($e) {
         return $e->getMessage();
     }, $this->exceptions));
     return $this;
 }
 public function testCanAddSelf()
 {
     $e1 = new ExceptionCollection();
     $e1->add(new \Exception("Test"));
     $e2 = new ExceptionCollection('Meta description!');
     $e2->add(new \Exception("Test 2"));
     $e3 = new ExceptionCollection();
     $e3->add(new \Exception('Baz'));
     $e2->add($e3);
     $e1->add($e2);
     $message = $e1->getMessage();
     $this->assertContains("(Exception) ./tests/Guzzle/Tests/Common/Exception/ExceptionCollectionTest.php line ", $message);
     $this->assertContains("\n    Test\n\n    #0 ", $message);
     $this->assertContains("\n\n(Guzzle\\Common\\Exception\\ExceptionCollection) ./tests/Guzzle/Tests/Common/Exception/ExceptionCollectionTest.php line ", $message);
     $this->assertContains("\n\n    Meta description!\n\n", $message);
     $this->assertContains("    (Exception) ./tests/Guzzle/Tests/Common/Exception/ExceptionCollectionTest.php line ", $message);
     $this->assertContains("\n        Test 2\n\n        #0 ", $message);
     $this->assertContains("        (Exception) ./tests/Guzzle/Tests/Common/Exception/ExceptionCollectionTest.php line ", $message);
     $this->assertContains("            Baz\n\n            #0", $message);
 }