ArchiveTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Alchemy\Zippy\Tests\Archive;
  3. use Alchemy\Zippy\Tests\TestCase;
  4. use Alchemy\Zippy\Archive\ArchiveInterface;
  5. use Alchemy\Zippy\Archive\Archive;
  6. class ArchiveTest extends TestCase
  7. {
  8. public function testNewInstance()
  9. {
  10. $archive = new Archive($this->getResource('location'), $this->getAdapterMock(), $this->getResourceManagerMock());
  11. $this->assertTrue($archive instanceof ArchiveInterface);
  12. return $archive;
  13. }
  14. public function testCount()
  15. {
  16. $mockAdapter = $this->getAdapterMock();
  17. $mockAdapter
  18. ->expects($this->once())
  19. ->method('listMembers')
  20. ->will($this->returnValue(array('1', '2')));
  21. $archive = new Archive($this->getResource('location'), $mockAdapter, $this->getResourceManagerMock());
  22. $this->assertEquals(2, count($archive));
  23. }
  24. public function testGetMembers()
  25. {
  26. $mockAdapter = $this->getAdapterMock();
  27. $resource = $this->getResource('location');
  28. $mockAdapter
  29. ->expects($this->once())
  30. ->method('listMembers')
  31. ->with($this->equalTo($resource))
  32. ->will($this->returnValue(array('1', '2')));
  33. $archive = new Archive($this->getResource('location'), $mockAdapter, $this->getResourceManagerMock());
  34. $members = $archive->getMembers();
  35. $this->assertTrue(is_array($members));
  36. $this->assertEquals(2, count($members));
  37. }
  38. public function testAddMembers()
  39. {
  40. $resource = $this->getResource('location');
  41. $mockAdapter = $this->getAdapterMock();
  42. $mockAdapter
  43. ->expects($this->once())
  44. ->method('add')
  45. ->with($this->equalTo($resource), $this->equalTo(array('hello')), $this->equalTo(true));
  46. $resourceManager = $this->getResourceManagerMock();
  47. $archive = new Archive($resource, $mockAdapter, $resourceManager);
  48. $this->assertEquals($archive, $archive->addMembers(array('hello')));
  49. }
  50. public function testRemoveMember()
  51. {
  52. $mockAdapter = $this->getAdapterMock();
  53. $mockAdapter
  54. ->expects($this->once())
  55. ->method('remove');
  56. $archive = new Archive($this->getResource('location'), $mockAdapter, $this->getResourceManagerMock());
  57. $this->assertEquals($archive, $archive->removeMembers('hello'));
  58. }
  59. private function getAdapterMock()
  60. {
  61. return $this->getMock('Alchemy\Zippy\Adapter\AdapterInterface');
  62. }
  63. }