|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Omnipay\Common; |
| 4 | + |
| 5 | +use Omnipay\TestCase; |
| 6 | + |
| 7 | +class ItemBagTest extends TestCase |
| 8 | +{ |
| 9 | + public function setUp() |
| 10 | + { |
| 11 | + $this->bag = new ItemBag; |
| 12 | + } |
| 13 | + |
| 14 | + public function testConstruct() |
| 15 | + { |
| 16 | + $bag = new ItemBag(array(array('name' => 'Floppy Disk'))); |
| 17 | + $this->assertCount(1, $bag); |
| 18 | + } |
| 19 | + |
| 20 | + public function testAll() |
| 21 | + { |
| 22 | + $items = array(new Item, new Item); |
| 23 | + $bag = new ItemBag($items); |
| 24 | + |
| 25 | + $this->assertSame($items, $bag->all()); |
| 26 | + } |
| 27 | + |
| 28 | + public function testReplace() |
| 29 | + { |
| 30 | + $items = array(new Item, new Item); |
| 31 | + $this->bag->replace($items); |
| 32 | + |
| 33 | + $this->assertSame($items, $this->bag->all()); |
| 34 | + } |
| 35 | + |
| 36 | + public function testAddWithItem() |
| 37 | + { |
| 38 | + $item = new Item; |
| 39 | + $item->setName('CD-ROM'); |
| 40 | + $this->bag->add($item); |
| 41 | + |
| 42 | + $contents = $this->bag->all(); |
| 43 | + $this->assertSame($item, $contents[0]); |
| 44 | + } |
| 45 | + |
| 46 | + public function testAddWithArray() |
| 47 | + { |
| 48 | + $item = array('name' => 'CD-ROM'); |
| 49 | + $this->bag->add($item); |
| 50 | + |
| 51 | + $contents = $this->bag->all(); |
| 52 | + $this->assertInstanceOf('\Omnipay\Common\Item', $contents[0]); |
| 53 | + $this->assertSame('CD-ROM', $contents[0]->getName()); |
| 54 | + } |
| 55 | + |
| 56 | + public function testGetIterator() |
| 57 | + { |
| 58 | + $item = new Item; |
| 59 | + $item->setName('CD-ROM'); |
| 60 | + $this->bag->add($item); |
| 61 | + |
| 62 | + foreach ($this->bag as $bagItem) { |
| 63 | + $this->assertSame($item, $bagItem); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + public function testCount() |
| 68 | + { |
| 69 | + $this->bag->add(new Item); |
| 70 | + $this->bag->add(new Item); |
| 71 | + $this->bag->add(new Item); |
| 72 | + |
| 73 | + $this->assertSame(3, count($this->bag)); |
| 74 | + } |
| 75 | +} |
0 commit comments