| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-06 23:38:04 +01:00
										 |  |  | namespace Tests\FFMpeg\Unit\Format\Audio; | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-06 23:38:04 +01:00
										 |  |  | use Tests\FFMpeg\Unit\TestCase; | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  | use FFMpeg\Format\Audio\DefaultAudio; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | abstract class AudioTestCase extends TestCase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public function testExtraParams() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-02-13 00:39:31 +01:00
										 |  |  |         $extraParams = $this->getFormat()->getExtraParams(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertIsArray($extraParams); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         foreach ($extraParams as $param) { | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |             $this->assertScalar($param); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testGetAudioCodec() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->assertScalar($this->getFormat()->getAudioCodec()); | 
					
						
							|  |  |  |         $this->assertContains($this->getFormat()->getAudioCodec(), $this->getFormat()->getAvailableAudioCodecs()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testSetAudioCodec() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $format = $this->getFormat(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         foreach ($format->getAvailableAudioCodecs() as $codec) { | 
					
						
							|  |  |  |             $format->setAudioCodec($codec); | 
					
						
							|  |  |  |             $this->assertEquals($codec, $format->getAudioCodec()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testSetInvalidAudioCodec() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-02-13 00:39:31 +01:00
										 |  |  |         $this->expectException('\FFMpeg\Exception\InvalidArgumentException'); | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |         $this->getFormat()->setAudioCodec('invalid-random-audio-codec'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testGetAvailableAudioCodecs() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->assertGreaterThan(0, count($this->getFormat()->getAvailableAudioCodecs())); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testGetAudioKiloBitrate() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-02-13 00:39:31 +01:00
										 |  |  |         $this->assertIsInt($this->getFormat()->getAudioKiloBitrate()); | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testSetAudioKiloBitrate() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $format = $this->getFormat(); | 
					
						
							|  |  |  |         $format->setAudioKiloBitrate(256); | 
					
						
							|  |  |  |         $this->assertEquals(256, $format->getAudioKiloBitrate()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testSetInvalidKiloBitrate() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-02-13 00:39:31 +01:00
										 |  |  |         $this->expectException('\FFMpeg\Exception\InvalidArgumentException'); | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |         $this->getFormat()->setAudioKiloBitrate(0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testSetNegativeKiloBitrate() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-02-13 00:39:31 +01:00
										 |  |  |         $this->expectException('\FFMpeg\Exception\InvalidArgumentException'); | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |         $this->getFormat()->setAudioKiloBitrate(-10); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-25 09:55:00 +02:00
										 |  |  |     public function testGetAudioChannels() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-02-13 00:39:31 +01:00
										 |  |  |         $this->assertNull($this->getFormat()->getAudioChannels()); | 
					
						
							| 
									
										
										
										
											2014-06-25 09:55:00 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testSetAudioChannels() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $format = $this->getFormat(); | 
					
						
							|  |  |  |         $format->setAudioChannels(2); | 
					
						
							|  |  |  |         $this->assertEquals(2, $format->getAudioChannels()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testSetInvalidChannels() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-02-13 00:39:31 +01:00
										 |  |  |         $this->expectException('\FFMpeg\Exception\InvalidArgumentException'); | 
					
						
							| 
									
										
										
										
											2014-06-25 09:55:00 +02:00
										 |  |  |         $this->getFormat()->setAudioChannels(0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testSetNegativeChannels() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-02-13 00:39:31 +01:00
										 |  |  |         $this->expectException('\FFMpeg\Exception\InvalidArgumentException'); | 
					
						
							| 
									
										
										
										
											2014-06-25 09:55:00 +02:00
										 |  |  |         $this->getFormat()->setAudioChannels(-10); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |     public function testCreateProgressListener() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-02-13 00:23:11 +01:00
										 |  |  |         $media = $this->getMockBuilder('FFMpeg\Media\MediaTypeInterface')->getMock(); | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |         $media->expects($this->any()) | 
					
						
							|  |  |  |             ->method('getPathfile') | 
					
						
							|  |  |  |             ->will($this->returnValue(__FILE__)); | 
					
						
							|  |  |  |         $format = $this->getFormat(); | 
					
						
							|  |  |  |         $ffprobe = $this->getFFProbeMock(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         foreach ($format->createProgressListener($media, $ffprobe, 1, 3) as $listener) { | 
					
						
							|  |  |  |             $this->assertInstanceOf('FFMpeg\Format\ProgressListener\AudioProgressListener', $listener); | 
					
						
							|  |  |  |             $this->assertSame($ffprobe, $listener->getFFProbe()); | 
					
						
							|  |  |  |             $this->assertSame(__FILE__, $listener->getPathfile()); | 
					
						
							|  |  |  |             $this->assertSame(1, $listener->getCurrentPass()); | 
					
						
							|  |  |  |             $this->assertSame(3, $listener->getTotalPass()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @return DefaultAudio | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     abstract public function getFormat(); | 
					
						
							|  |  |  | } |