AbstractPreviewExtractorTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * This file is part of the PHPExiftool package.
  4. *
  5. * (c) Alchemy <support@alchemy.fr>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace PHPExiftool\Test;
  11. use PHPExiftool\PreviewExtractor;
  12. abstract class AbstractPreviewExtractorTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @covers PHPExiftool\PreviewExtractor::extract
  16. */
  17. public function testExtract()
  18. {
  19. $extractor = new PreviewExtractor($this->getExiftool());
  20. $tmpDir = sys_get_temp_dir() . '/tests' . mt_rand(10000, 99999);
  21. mkdir($tmpDir);
  22. $files = $extractor->extract(__DIR__ . '/../../../files/ExifTool.jpg', $tmpDir);
  23. $this->assertInstanceOf('\\DirectoryIterator', $files);
  24. $n = 0;
  25. $unlinks = array();
  26. foreach ($files as $file) {
  27. if ($file->isDot() || $file->isDir()) {
  28. continue;
  29. }
  30. $unlinks[] = $file->getPathname();
  31. $n ++;
  32. }
  33. foreach ($unlinks as $u) {
  34. unlink($u);
  35. }
  36. $this->assertEquals(1, $n);
  37. }
  38. /**
  39. * @expectedException \PHPExiftool\Exception\LogicException
  40. */
  41. public function testExtractWrongFile()
  42. {
  43. $extractor = new PreviewExtractor($this->getExiftool());
  44. $tmpDir = sys_get_temp_dir() . '/tests' . mt_rand(10000, 99999);
  45. $extractor->extract(__DIR__ . '/ExifTool.jpg', $tmpDir);
  46. }
  47. /**
  48. * @expectedException \PHPExiftool\Exception\LogicException
  49. */
  50. public function testExtractWrongDir()
  51. {
  52. $extractor = new PreviewExtractor($this->getExiftool());
  53. $tmpDir = sys_get_temp_dir() . '/tests' . mt_rand(10000, 99999);
  54. $extractor->extract(__DIR__ . '/../../../files/ExifTool.jpg', $tmpDir);
  55. }
  56. abstract protected function getExiftool();
  57. }