FileStrategyTestCase.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Alchemy\Zippy\Tests\FileStrategy;
  3. use Alchemy\Zippy\Adapter\AdapterInterface;
  4. use Alchemy\Zippy\Tests\TestCase;
  5. use Alchemy\Zippy\FileStrategy\FileStrategyInterface;
  6. abstract class FileStrategyTestCase extends TestCase
  7. {
  8. /** @test */
  9. public function getFileExtensionShouldReturnAnString()
  10. {
  11. $that = $this;
  12. $container = $this->getMock('Alchemy\Zippy\Adapter\AdapterContainer');
  13. $container
  14. ->expects($this->any())
  15. ->method('offsetGet')
  16. ->will($this->returnCallback(function($offset) use ($that) {
  17. if (array_key_exists('Alchemy\Zippy\Adapter\AdapterInterface', class_implements($offset))) {
  18. return $that->getMock('Alchemy\Zippy\Adapter\AdapterInterface');
  19. }
  20. return null;
  21. }));
  22. $extension = $this->getStrategy($container)->getFileExtension();
  23. $this->assertNotEquals('', trim($extension));
  24. $this->assertInternalType('string', $extension);
  25. }
  26. /** @test */
  27. public function getAdaptersShouldReturnAnArrayOfAdapter()
  28. {
  29. $that = $this;
  30. $container = $this->getMock('Alchemy\Zippy\Adapter\AdapterContainer');
  31. $container
  32. ->expects($this->any())
  33. ->method('offsetGet')
  34. ->will($this->returnCallback(function($offset) use ($that) {
  35. if (array_key_exists('Alchemy\Zippy\Adapter\AdapterInterface', class_implements($offset))) {
  36. return $that->getMock('Alchemy\Zippy\Adapter\AdapterInterface');
  37. }
  38. return null;
  39. }));
  40. $adapters = $this->getStrategy($container)->getAdapters();
  41. $this->assertInternalType('array', $adapters);
  42. foreach ($adapters as $adapter) {
  43. $this->assertInstanceOf('Alchemy\\Zippy\\Adapter\\AdapterInterface', $adapter);
  44. }
  45. }
  46. /**
  47. * @return FileStrategyInterface
  48. */
  49. abstract protected function getStrategy($container);
  50. }