BatchResultsTest.php
1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace GuzzleHttp\Tests;
use GuzzleHttp\BatchResults;
/**
* @covers \GuzzleHttp\BatchResults
*/
class BatchResultsTest extends \PHPUnit_Framework_TestCase
{
public function testExposesResults()
{
$a = new \stdClass();
$b = new \stdClass();
$c = new \stdClass();
$hash = new \SplObjectStorage();
$hash[$a] = '1';
$hash[$b] = '2';
$hash[$c] = new \Exception('foo');
$batch = new BatchResults($hash);
$this->assertCount(3, $batch);
$this->assertEquals([$a, $b, $c], $batch->getKeys());
$this->assertEquals([$hash[$c]], $batch->getFailures());
$this->assertEquals(['1', '2'], $batch->getSuccessful());
$this->assertEquals('1', $batch->getResult($a));
$this->assertNull($batch->getResult(new \stdClass()));
$this->assertTrue(isset($batch[0]));
$this->assertFalse(isset($batch[10]));
$this->assertEquals('1', $batch[0]);
$this->assertEquals('2', $batch[1]);
$this->assertNull($batch[100]);
$this->assertInstanceOf('Exception', $batch[2]);
$results = iterator_to_array($batch);
$this->assertEquals(['1', '2', $hash[$c]], $results);
}
/**
* @expectedException \RuntimeException
*/
public function testCannotSetByIndex()
{
$hash = new \SplObjectStorage();
$batch = new BatchResults($hash);
$batch[10] = 'foo';
}
/**
* @expectedException \RuntimeException
*/
public function testCannotUnsetByIndex()
{
$hash = new \SplObjectStorage();
$batch = new BatchResults($hash);
unset($batch[10]);
}
}