PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/test/FFmpegAnimatedGifTest.php

http://github.com/char0n/ffmpeg-php
PHP | 101 lines | 68 code | 16 blank | 17 comment | 1 complexity | 801e68d4178afd3701263d4bcd07d4f5 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Testing framework: PHPUnit (http://www.phpunit.de)
  4. *
  5. * 1.) Install phpunit on your operating system
  6. * 2.) Run the test
  7. *
  8. * phpunit --bootstrap test/bootstrap.php test/FFmpegAnimatedGifTest.php
  9. */
  10. /**
  11. * FFmpegAnimatedGifTest contains tests for FFmpegAnimatedGif class
  12. *
  13. * @author char0n (Vladim?­r Gorej, gorej@codescale.net)
  14. * @category tests
  15. * @package FFmpegPHP
  16. * @license New BSD
  17. * @version 2.6
  18. */
  19. class FFmpegAnimatedGifTest extends PHPUnit_Framework_TestCase {
  20. protected static $outFilePath;
  21. protected static $moviePath;
  22. protected $movie;
  23. protected $frame1;
  24. protected $frame2;
  25. protected $anim;
  26. public static function setUpBeforeClass() {
  27. self::$outFilePath = sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid('anim', true).'.gif';
  28. self::$moviePath = dirname(__FILE__).DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'test.mp4';
  29. }
  30. public static function tearDownAfterClass() {
  31. self::$outFilePath = null;
  32. self::$moviePath = null;
  33. }
  34. public function setUp() {
  35. $this->movie = new FFmpegMovie(self::$moviePath);
  36. $this->frame1 = $this->movie->getFrame(1);
  37. $this->frame2 = $this->movie->getFrame(2);
  38. $this->anim = new FFmpegAnimatedGif(self::$outFilePath, 100, 120, 1, 0);
  39. }
  40. public function tearDown() {
  41. $this->movie = null;
  42. $this->frame1 = null;
  43. $this->frame2 = null;
  44. $this->anim = null;
  45. if (file_exists(self::$outFilePath)) unlink(self::$outFilePath);
  46. }
  47. public function testAddFrame() {
  48. $frame = $this->movie->getFrame(3);
  49. $memoryBefore = memory_get_usage();
  50. $this->anim->addFrame($frame);
  51. $memoryAfter = memory_get_usage();
  52. $this->assertGreaterThan($memoryBefore, $memoryAfter, 'Memory usage should be higher after adding frame');
  53. }
  54. public function testGetAnimation() {
  55. $this->anim->addFrame($this->frame1);
  56. $this->anim->addFrame($this->frame2);
  57. $animData = $this->anim->getAnimation();
  58. $this->assertEquals(20936, strlen($animData), 'Animation binary size should be int(20936)');
  59. }
  60. public function testSave() {
  61. $this->anim->addFrame($this->frame1);
  62. $this->anim->addFrame($this->frame2);
  63. $saveResult = $this->anim->save();
  64. $this->assertEquals(true, $saveResult, 'Save result should be true');
  65. $this->assertEquals(true, file_exists(self::$outFilePath), 'File "'.self::$outFilePath.'" should exist after saving');
  66. $this->assertEquals(20936, filesize(self::$outFilePath), 'Animation binary size should be int(20936)');
  67. $imageInfo = getimagesize(self::$outFilePath);
  68. $this->assertEquals(100, $imageInfo[0], 'Saved image width should be int(100)');
  69. $this->assertEquals(120, $imageInfo[1], 'Saved image height should be int(120)');
  70. }
  71. public function testSerializeUnserialize() {
  72. $this->anim->addFrame($this->frame1);
  73. $this->anim->addFrame($this->frame2);
  74. $serialized = serialize($this->anim);
  75. $this->anim = null;
  76. $this->anim = unserialize($serialized);
  77. $saveResult = $this->anim->save();
  78. $this->assertEquals(true, $saveResult, 'Save result should be true');
  79. $this->assertEquals(true, file_exists(self::$outFilePath), 'File "'.self::$outFilePath.'" should exist after saving');
  80. $this->assertEquals(20936, filesize(self::$outFilePath), 'Animation binary size should be int(20936)');
  81. $imageInfo = getimagesize(self::$outFilePath);
  82. $this->assertEquals(100, $imageInfo[0], 'Saved image width should be int(100)');
  83. $this->assertEquals(120, $imageInfo[1], 'Saved image height should be int(120)');
  84. }
  85. }