-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathFrameTest.php
More file actions
160 lines (135 loc) · 5.42 KB
/
FrameTest.php
File metadata and controls
160 lines (135 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
namespace Char0n\FFMpegPHP\Tests;
use Char0n\FFMpegPHP\Movie;
use Char0n\FFMpegPHP\Frame;
use PHPUnit\Framework\TestCase;
class FrameTest extends TestCase
{
protected static $moviePath;
/**
* @var Movie
*/
protected $movie;
/**
* @var Frame
*/
protected $frame;
public static function setUpBeforeClass(): void
{
self::$moviePath = dirname(__FILE__).DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'test.mp4';
}
public static function tearDownAfterClass(): void
{
self::$moviePath = null;
}
public function setUp(): void
{
$this->movie = new Movie(self::$moviePath);
$this->frame = $this->movie->getFrame(1);
}
public function tearDown(): void
{
$this->movie = null;
$this->frame = null;
}
public function testConstructor()
{
$this->expectException(\Exception::class);
$this->expectExceptionCode(334563);
new Frame('test', 0.0);
}
public function testFrameExtracted()
{
$this->assertInstanceOf(Frame::class, $this->frame);
}
public function testGetWidth()
{
$this->assertIsInt($this->frame->getWidth(), 'Frame width is of integer type');
$this->assertEquals(640, $this->frame->getWidth(), 'Frame width should be int(640)');
}
public function testGetHeight()
{
$this->assertIsInt($this->frame->getHeight(), 'Frame height is of integer type');
$this->assertEquals(272, $this->frame->getHeight(), 'Frame height should be int(272)');
}
public function testGetPts()
{
$this->assertIsFloat($this->frame->getPts(), 'Pts is of integer type');
$this->assertEquals(0.0, $this->frame->getPts(), 'Pts should be float(0.0)');
}
public function testGetPresentationTimestamp()
{
$this->assertIsFloat($this->frame->getPresentationTimestamp(), 'Presentation timestamp is of integer type');
$this->assertEquals(
0.0,
$this->frame->getPresentationTimestamp(),
'Presentation timestamp should be float(0.0)'
);
$this->assertEquals(
$this->frame->getPts(),
$this->frame->getPresentationTimestamp(),
'Presentation timestamp should equal Pts'
);
}
public function testResize()
{
$oldWidth = $this->frame->getWidth();
$oldHeight = $this->frame->getHeight();
$this->frame->resize(300, 300);
$this->assertIsInt($this->frame->getWidth(), 'Frame width is of integer type');
$this->assertEquals(300, $this->frame->getWidth(), 'Frame width should be int(300)');
$this->assertIsInt($this->frame->getHeight(), 'Frame height is of integer type');
$this->assertEquals(300, $this->frame->getHeight(), 'Frame height should be int(300)');
$this->frame->resize($oldWidth, $oldHeight);
$this->assertIsInt($this->frame->getWidth(), 'Frame width is of integer type');
$this->assertEquals(640, $this->frame->getWidth(), 'Frame width should be int(640)');
$this->assertIsInt($this->frame->getHeight(), 'Frame height is of integer type');
$this->assertEquals(272, $this->frame->getHeight(), 'Frame height should be int(272)');
}
public function testCrop()
{
$oldWidth = $this->frame->getWidth();
$oldHeight = $this->frame->getHeight();
$this->frame->crop(100);
$this->assertIsInt($this->frame->getWidth(), 'Frame width is of integer type');
$this->assertEquals(640, $this->frame->getWidth(), 'Frame width should be int(300)');
$this->assertIsInt($this->frame->getHeight(), 'Frame height is of integer type');
$this->assertEquals(172, $this->frame->getHeight(), 'Frame height should be int(172)');
$this->frame->resize($oldWidth, $oldHeight);
$this->assertIsInt($this->frame->getWidth(), 'Frame width is of integer type');
$this->assertEquals(640, $this->frame->getWidth(), 'Frame width should be int(640)');
$this->assertIsInt($this->frame->getHeight(), 'Frame height is of integer type');
$this->assertEquals(272, $this->frame->getHeight(), 'Frame height should be int(272)');
}
public function testToGdImage()
{
$gdImage = $this->frame->toGDImage();
$this->assertTrue(
is_resource($gdImage) || get_class($gdImage) === 'GdImage',
'GdImage is of resource(gd2) type or \GdImage class'
);
}
public function testSerializeUnserialize()
{
$serialized = serialize($this->frame);
$this->frame = null;
$this->frame = unserialize($serialized);
$this->assertIsInt($this->frame->getWidth(), 'Frame width is of integer type');
$this->assertEquals(640, $this->frame->getWidth(), 'Frame width should be int(640)');
$this->assertIsInt($this->frame->getHeight(), 'Frame height is of integer type');
$this->assertEquals(272, $this->frame->getHeight(), 'Frame height should be int(272)');
}
public function testClone()
{
$gdImage = $this->frame->toGdImage();
$cloned = clone $this->frame;
if (is_resource($gdImage)) {
$uoid = (string) $gdImage;
$cuoid = (string) $cloned->toGdImage();
} else {
$uoid = spl_object_id($gdImage);
$cuoid = spl_object_id($cloned->toGdImage());
}
$this->assertNotEquals($uoid, $cuoid);
}
}