Open Journal Systems  3.3.0
ExceptionCollectionTest.php
1 <?php
2 
4 
6 
8 {
9  private function getExceptions()
10  {
11  return array(
12  new \Exception('Test'),
13  new \Exception('Testing')
14  );
15  }
16 
17  public function testAggregatesExceptions()
18  {
19  $e = new ExceptionCollection();
20  $exceptions = $this->getExceptions();
21  $e->add($exceptions[0]);
22  $e->add($exceptions[1]);
23  $this->assertContains("(Exception) ./tests/Guzzle/Tests/Common/Exception/ExceptionCollectionTest.php line ", $e->getMessage());
24  $this->assertContains(" Test\n\n #0 ./", $e->getMessage());
25  $this->assertSame($exceptions[0], $e->getFirst());
26  }
27 
28  public function testCanSetExceptions()
29  {
30  $ex = new \Exception('foo');
31  $e = new ExceptionCollection();
32  $e->setExceptions(array($ex));
33  $this->assertSame($ex, $e->getFirst());
34  }
35 
36  public function testActsAsArray()
37  {
38  $e = new ExceptionCollection();
39  $exceptions = $this->getExceptions();
40  $e->add($exceptions[0]);
41  $e->add($exceptions[1]);
42  $this->assertEquals(2, count($e));
43  $this->assertEquals($exceptions, $e->getIterator()->getArrayCopy());
44  }
45 
46  public function testCanAddSelf()
47  {
48  $e1 = new ExceptionCollection();
49  $e1->add(new \Exception("Test"));
50  $e2 = new ExceptionCollection('Meta description!');
51  $e2->add(new \Exception("Test 2"));
52  $e3 = new ExceptionCollection();
53  $e3->add(new \Exception('Baz'));
54  $e2->add($e3);
55  $e1->add($e2);
56  $message = $e1->getMessage();
57  $this->assertContains("(Exception) ./tests/Guzzle/Tests/Common/Exception/ExceptionCollectionTest.php line ", $message);
58  $this->assertContains("\n Test\n\n #0 ", $message);
59  $this->assertContains("\n\n(Guzzle\\Common\\Exception\\ExceptionCollection) ./tests/Guzzle/Tests/Common/Exception/ExceptionCollectionTest.php line ", $message);
60  $this->assertContains("\n\n Meta description!\n\n", $message);
61  $this->assertContains(" (Exception) ./tests/Guzzle/Tests/Common/Exception/ExceptionCollectionTest.php line ", $message);
62  $this->assertContains("\n Test 2\n\n #0 ", $message);
63  $this->assertContains(" (Exception) ./tests/Guzzle/Tests/Common/Exception/ExceptionCollectionTest.php line ", $message);
64  $this->assertContains(" Baz\n\n #0", $message);
65  }
66 }
Guzzle\Common\Exception\ExceptionCollection
Definition: ExceptionCollection.php:8
Guzzle\Tests\Common\Exception
Definition: BatchTransferExceptionTest.php:3
Guzzle\Tests\GuzzleTestCase
Definition: GuzzleTestCase.php:22
Guzzle\Tests\Common\Exception\ExceptionCollectionTest\testCanSetExceptions
testCanSetExceptions()
Definition: ExceptionCollectionTest.php:28
Guzzle\Tests\Common\Exception\ExceptionCollectionTest
Definition: ExceptionCollectionTest.php:7
Guzzle\Tests\Common\Exception\ExceptionCollectionTest\testAggregatesExceptions
testAggregatesExceptions()
Definition: ExceptionCollectionTest.php:17
Guzzle\Tests\Common\Exception\ExceptionCollectionTest\testActsAsArray
testActsAsArray()
Definition: ExceptionCollectionTest.php:36
Guzzle\Tests\Common\Exception\ExceptionCollectionTest\testCanAddSelf
testCanAddSelf()
Definition: ExceptionCollectionTest.php:46