This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
<?php
$loader = require __DIR__.'/../vendor/autoload.php';
$loader->add('MediaVorus', __DIR__ . '/src');
// PHPUnit 6 introduced a breaking change that
// removed PHPUnit_Framework_TestCase as a base class,
// and replaced it with \PHPUnit\Framework\TestCase
if (!class_exists('\PHPUnit_Framework_TestCase') && class_exists('\PHPUnit\Framework\TestCase')) {
class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase');
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 530 B

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" standalone="yes"?>
<svg width="4in" height="3in" version="1.1"
xmlns = 'http://www.w3.org/2000/svg'>
<desc xmlns:myfoo="http://example.org/myfoo">
<myfoo:title>This is a financial report</myfoo:title>
<myfoo:descr>The global description uses markup from the
<myfoo:emph>myfoo</myfoo:emph> namespace.</myfoo:descr>
<myfoo:scene><myfoo:what>widget $growth</myfoo:what>
<myfoo:contains>$three $graph-bar</myfoo:contains>
<myfoo:when>1998 $through 2000</myfoo:when> </myfoo:scene>
</desc>
<metadata>
<rdf:RDF
xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs = "http://www.w3.org/2000/01/rdf-schema#"
xmlns:dc = "http://purl.org/dc/elements/1.1/" >
<rdf:Description about="http://example.org/myfoo"
dc:title="MyFoo Financial Report"
dc:description="$three $bar $thousands $dollars $from 1998 $through 2000"
dc:publisher="Example Organization"
dc:date="2000-04-11"
dc:format="image/svg+xml"
dc:language="en" >
<dc:creator>
<rdf:Bag>
<rdf:li>Irving Bird</rdf:li>
<rdf:li>Mary Lambert</rdf:li>
</rdf:Bag>
</dc:creator>
</rdf:Description>
</rdf:RDF>
</metadata>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,99 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1.1-111">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:exif="http://ns.adobe.com/exif/1.0/"
xmlns:tiff="http://ns.adobe.com/tiff/1.0/"
xmlns:xap="http://ns.adobe.com/xap/1.0/"
xmlns:xapMM="http://ns.adobe.com/xap/1.0/mm/"
xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
exif:ExifVersion="0.2.2.0"
exif:FlashpixVersion="0.1.0.0"
exif:ColorSpace="1"
exif:CompressedBitsPerPixel="3/1"
exif:PixelXDimension="1136"
exif:PixelYDimension="852"
exif:DateTimeOriginal="2005-06-09T20:09:27+02:00"
exif:DateTimeDigitized="2005-06-09T20:09:27+02:00"
exif:ExposureTime="4/10"
exif:FNumber="28/10"
exif:ShutterSpeedValue="42/32"
exif:ApertureValue="95/32"
exif:ExposureBiasValue="-3/3"
exif:MaxApertureValue="95/32"
exif:MeteringMode="5"
exif:FocalLength="5800/1000"
exif:FocalPlaneXResolution="2272000/224"
exif:FocalPlaneYResolution="1704000/168"
exif:FocalPlaneResolutionUnit="2"
exif:SensingMethod="2"
exif:FileSource="3"
exif:CustomRendered="0"
exif:ExposureMode="1"
exif:WhiteBalance="0"
exif:DigitalZoomRatio="2272/2272"
exif:SceneCaptureType="0"
exif:NativeDigest="36864,40960,40961,37121,37122,40962,40963,37510,40964,36867,36868,33434,33437,34850,34852,34855,34856,37377,37378,37379,37380,37381,37382,37383,37384,37385,37386,37396,41483,41484,41486,41487,41488,41492,41493,41495,41728,41729,41730,41985,41986,41987,41988,41989,41990,41991,41992,41993,41994,41995,41996,42016,0,2,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,22,23,24,25,26,27,28,30;CE459FE772DF591DDF5F63CA3F2A087B"
tiff:Make="Canon"
tiff:Model="Canon DIGITAL IXUS 40"
tiff:Orientation="1"
tiff:XResolution="1800000/10000"
tiff:YResolution="1800000/10000"
tiff:ResolutionUnit="2"
tiff:YCbCrPositioning="1"
tiff:ImageWidth="1136"
tiff:ImageLength="852"
tiff:NativeDigest="256,257,258,259,262,274,277,284,530,531,282,283,296,301,318,319,529,532,306,270,271,272,305,315,33432;D11E7FC551E751BE9E616260834B2A1D"
xap:CreateDate="2005-11-21T17:07:14+01:00"
xap:ModifyDate="2005-11-21T17:07:14+01:00"
xap:MetadataDate="2005-11-21T17:11:31+01:00"
xap:CreatorTool="Adobe Photoshop CS2 Windows"
xap:Rating="1"
xapMM:DocumentID="uuid:7A9636BAA85ADA11B611C7FA524F1F71"
xapMM:InstanceID="uuid:7B9636BAA85ADA11B611C7FA524F1F71"
dc:format="image/jpeg"
photoshop:ColorMode="3"
photoshop:ICCProfile="sRGB IEC61966-2.1"
photoshop:History="">
<dc:rights>
<rdf:Alt>
<rdf:li xml:lang='x-default'>© Copyright Phil Harvey</rdf:li>
<rdf:li xml:lang='fr'>© Droit d'auteur Phil Harvey</rdf:li>
</rdf:Alt>
</dc:rights>
<dc:subject>
<rdf:Bag>
<rdf:li>test1</rdf:li>
<rdf:li>&amp;-<![CDATA[&amp;]]>-&amp;</rdf:li>
</rdf:Bag>
</dc:subject>
<exif:ComponentsConfiguration>
<rdf:Seq>
<rdf:li>1</rdf:li>
<rdf:li>2</rdf:li>
<rdf:li>3</rdf:li>
<rdf:li>0</rdf:li>
</rdf:Seq>
</exif:ComponentsConfiguration>
<exif:Flash
exif:Fired="False"
exif:Return="0"
exif:Mode="2"
exif:Function="False"
exif:RedEyeMode="False"/>
<tiff:BitsPerSample>
<rdf:Seq>
<rdf:li>8</rdf:li>
<rdf:li>8</rdf:li>
<rdf:li>8</rdf:li>
</rdf:Seq>
</tiff:BitsPerSample>
<xapMM:DerivedFrom
stRef:instanceID="adobe:docid:photoshop:f481cc67-d8f5-11d9-a31e-a1606d941d83"
stRef:documentID="adobe:docid:photoshop:f481cc67-d8f5-11d9-a31e-a1606d941d83"/>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

View File

@@ -0,0 +1,56 @@
<?php
namespace MediaVorus;
use FFMpeg\FFProbe;
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use PHPExiftool\Reader;
use PHPExiftool\Writer;
class FileTest extends TestCase
{
/**
* Instantiate mediavorus to register the mime types
*/
public function setUp()
{
parent::setUp();
$logger = new Logger('test');
$logger->pushHandler(new NullHandler());
$mediavorus = new MediaVorus(Reader::create($logger), Writer::create($logger), FFProbe::create());
}
/**
* @covers MediaVorus\File::__construct
* @covers MediaVorus\File::getMimeType
*/
public function testGetMimeType()
{
$object = new File(__DIR__ . '/../../files/CanonRaw.cr2');
$this->assertEquals('image/x-tika-canon', $object->getMimeType());
}
/**
* @covers MediaVorus\File::__construct
* @covers MediaVorus\File::getMimeType
*/
public function testGetMimeTypeApe()
{
$object = new File(__DIR__ . '/../../files/APE.ape');
$this->assertEquals('audio/x-monkeys-audio', $object->getMimeType());
}
/**
* @covers MediaVorus\File::__construct
* @covers MediaVorus\Exception\ExceptionInterface
* @covers MediaVorus\Exception\FileNotFoundException
* @expectedException MediaVorus\Exception\FileNotFoundException
*/
public function testFileNotFound()
{
new File(__DIR__ . '/../../files/nonExistentFile');
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace MediaVorus\Media;
use MediaVorus\File;
use MediaVorus\TestCase;
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use PHPExiftool\Reader;
use PHPExiftool\Writer;
class DefaultMediaTest extends TestCase
{
/**
* @var DefaultMedia
*/
protected $object;
protected $GPSobject;
public function setUp()
{
parent::setUp();
$logger = new Logger('Tests');
$logger->pushHandler(new NullHandler());
$reader = Reader::create($logger);
$writer = Writer::create($logger);
$file = __DIR__ . '/../../../files/ExifTool.jpg';
$this->object = new DefaultMedia(new File($file), $reader->reset()->files($file)->first(), $writer);
$file = __DIR__ . '/../../../files/GPS.jpg';
$this->GPSobject = new DefaultMedia(new File($file), $reader->reset()->files($file)->first(), $writer);
}
public function testGetHash()
{
$this->assertEquals('47684e05475e7591e15140449b12bd6e3e1c82c44a89f1803410e82051a2c88e', $this->object->getHash('sha256'));
}
/**
* @covers \MediaVorus\Media\DefaultMedia::getFile
*/
public function testGetFile()
{
$this->assertInstanceOf('\MediaVorus\File', $this->object->getFile());
$this->assertEquals('ExifTool.jpg', $this->object->getFile()->getFilename());
}
/**
* @covers \MediaVorus\Media\DefaultMedia::getLongitude
*/
public function testGetLongitude()
{
$this->assertInternalType('float', $this->GPSobject->getLongitude());
$this->assertEquals(-1.91416666666667, $this->GPSobject->getLongitude());
}
/**
* @covers \MediaVorus\Media\DefaultMedia::getLongitudeRef
*/
public function testGetLongitudeRef()
{
$this->assertFalse(in_array($this->GPSobject->getLongitudeRef(), array('W', 'E')));
}
/**
* @covers \MediaVorus\Media\DefaultMedia::getLatitude
*/
public function testGetLatitude()
{
$this->assertInternalType('float', $this->GPSobject->getLatitude());
$this->assertEquals(54.9896666666667, $this->GPSobject->getLatitude());
}
/**
* @covers \MediaVorus\Media\DefaultMedia::getLatitudeRef
*/
public function testGetLatitudeRef()
{
$this->assertFalse(in_array($this->GPSobject->getLatitudeRef(), array('N', 'S')));
}
}

View File

@@ -0,0 +1,276 @@
<?php
namespace MediaVorus\Media;
use FFMpeg\FFProbe;
use MediaVorus\File;
use MediaVorus\MediaVorus;
use MediaVorus\Media\MediaInterface;
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use PHPExiftool\Reader;
use PHPExiftool\Writer;
class ImageTest extends MediaTestCase
{
/**
* @var Image
*/
protected $object;
protected $mediavorus;
protected $reader;
protected $writer;
protected $ffprobe;
public function setUp()
{
parent::setUp();
$logger = new Logger('Tests');
$logger->pushHandler(new NullHandler());
$this->reader = Reader::create($logger);
$this->writer = Writer::create($logger);
$file = __DIR__ . '/../../../files/ExifTool.jpg';
$this->object = new Image(new File($file), $this->reader->reset()->files($file)->first(), $this->writer);
$logger = new Logger('test');
$logger->pushHandler(new NullHandler());
$this->ffprobe = FFProbe::create();
$this->mediavorus = new MediaVorus($this->reader, $this->writer, $this->ffprobe);
}
/**
* @covers \MediaVorus\Media\Image::getType
*/
public function testGetType()
{
$this->assertEquals(MediaInterface::TYPE_IMAGE, $this->object->getType());
}
/**
* @covers \MediaVorus\Media\Image::isRawImage
*/
public function testIsrawImage()
{
$this->assertFalse($this->object->isRawImage());
$object = $this->mediavorus->guess(__DIR__ . '/../../../files/CanonRaw.cr2');
$this->assertTrue($object->isRawImage());
}
/**
* @covers \MediaVorus\Media\Image::getWidth
* @covers \MediaVorus\Media\Image::extractFromDimensions
*/
public function testGetWidth()
{
$this->assertTrue(is_int($this->object->getWidth()));
$this->assertEquals(8, $this->object->getWidth());
$objects = $this->mediavorus->inspectDirectory(__DIR__ . '/../../../files/');
foreach ($objects as $object) {
if ($object->getType() == MediaInterface::TYPE_IMAGE) {
if (in_array($object->getFile()->getFilename(), array('KyoceraRaw.raw', 'Font.dfont', 'XMP.svg'))) {
$this->assertNull($object->getWidth());
} else {
$this->assertTrue(is_int($object->getWidth()), $object->getFile()->getFilename() . " has int width");
}
}
}
}
/**
* @covers \MediaVorus\Media\Image::getHeight
* @covers \MediaVorus\Media\Image::extractFromDimensions
*/
public function testGetHeight()
{
$this->assertTrue(is_int($this->object->getHeight()));
$this->assertEquals(8, $this->object->getHeight());
$objects = $this->mediavorus->inspectDirectory(__DIR__ . '/../../../files/');
foreach ($objects as $object) {
if ($object->getType() == MediaInterface::TYPE_IMAGE) {
if (in_array($object->getFile()->getFilename(), array('KyoceraRaw.raw', 'Font.dfont', 'XMP.svg'))) {
$this->assertNull($object->getHeight());
} else {
$this->assertTrue(is_int($object->getHeight()), $object->getFile()->getFilename() . " has int width");
}
}
}
}
/**
* @covers \MediaVorus\Media\Image::getChannels
*/
public function testGetChannels()
{
$this->assertTrue(is_int($this->object->getChannels()));
$this->assertEquals(3, $this->object->getChannels());
}
/**
* @covers \MediaVorus\Media\Image::getFocalLength
*/
public function testGetFocalLength()
{
$this->assertTrue(is_float($this->object->getFocalLength()));
$this->assertEquals(6.0, $this->object->getFocalLength());
}
/**
* @covers \MediaVorus\Media\Image::getColorDepth
*/
public function testGetColorDepth()
{
$this->assertTrue(is_int($this->object->getColorDepth()));
$this->assertEquals(8, $this->object->getColorDepth());
}
/**
* @covers \MediaVorus\Media\Image::getCameraModel
*/
public function testGetCameraModel()
{
$this->assertTrue(is_string($this->object->getCameraModel()));
}
/**
* @covers \MediaVorus\Media\Image::getFlashFired
*/
public function testGetFlashFired()
{
$this->assertTrue(is_bool($this->object->getFlashFired()));
$object = $this->mediavorus->guess(__DIR__ . '/../../../files/photo01.JPG');
$this->assertInstanceOf('\MediaVorus\Media\Image', $object);
$this->assertFalse($object->getFlashFired());
$object = $this->mediavorus->guess(__DIR__ . '/../../../files/CanonRaw.cr2');
$this->assertInstanceOf('\MediaVorus\Media\Image', $object);
$this->assertFalse($object->getFlashFired());
$object = $this->mediavorus->guess(__DIR__ . '/../../../files/photoAutoNoFlash.jpg');
$this->assertInstanceOf('\MediaVorus\Media\Image', $object);
$this->assertFalse($object->getFlashFired());
$object = $this->mediavorus->guess(__DIR__ . '/../../../files/PhotoFlash.jpg');
$this->assertInstanceOf('\MediaVorus\Media\Image', $object);
$this->assertTrue($object->getFlashFired());
$object = $this->mediavorus->guess(__DIR__ . '/../../../files/videoFlashed.MOV');
$this->assertInstanceOf('\MediaVorus\Media\Image', $object);
$this->assertNull($object->getFlashFired());
$object = $this->mediavorus->guess(__DIR__ . '/../../../files/XMP.xmp');
$this->assertInstanceOf('\MediaVorus\Media\Image', $object);
$this->assertFalse($object->getFlashFired());
$object = $this->mediavorus->guess(__DIR__ . '/../../../files/DNG.dng');
$this->assertInstanceOf('\MediaVorus\Media\Image', $object);
$this->assertFalse($object->getFlashFired());
$object = $this->mediavorus->guess(__DIR__ . '/../../../files/Panasonic.rw2');
$this->assertInstanceOf('\MediaVorus\Media\Image', $object);
$this->assertFalse($object->getFlashFired());
}
/**
* @covers \MediaVorus\Media\Image::getAperture
*/
public function testGetAperture()
{
$this->assertInternalType('float', $this->object->getAperture());
}
/**
* @covers \MediaVorus\Media\Image::getShutterSpeed
*/
public function testGetShutterSpeed()
{
$this->assertInternalType('float', $this->object->getShutterSpeed());
}
/**
* @covers \MediaVorus\Media\Image::getOrientation
*/
public function testGetOrientation()
{
$object1 = $this->mediavorus->guess(__DIR__ . '/../../../files/photo01.JPG');
$object2 = $this->mediavorus->guess(__DIR__ . '/../../../files/photo02.JPG');
$object3 = $this->mediavorus->guess(__DIR__ . '/../../../files/photo03.JPG');
$object4 = $this->mediavorus->guess(__DIR__ . '/../../../files/Test.ogv');
$this->assertEquals(Image::ORIENTATION_0, $this->object->getOrientation());
$this->assertEquals(Image::ORIENTATION_90, $object1->getOrientation());
$this->assertEquals(Image::ORIENTATION_180, $object2->getOrientation());
$this->assertEquals(Image::ORIENTATION_270, $object3->getOrientation());
$this->assertEquals(Image::ORIENTATION_0, $object4->getOrientation());
}
/**
* @covers \MediaVorus\Media\Image::getCreationDate
*/
public function testGetCreationDate()
{
$this->assertTrue(is_string($this->object->getCreationDate()));
}
/**
* @covers \MediaVorus\Media\Image::getHyperfocalDistance
*/
public function testGetHyperfocalDistance()
{
$this->assertInternalType('float', $this->object->getHyperfocalDistance());
}
/**
* @covers \MediaVorus\Media\Image::getISO
*/
public function testGetISO()
{
$this->assertTrue(is_int($this->object->getISO()));
$this->assertEquals(100, $this->object->getISO());
}
/**
* @covers \MediaVorus\Media\Image::getLightValue
*/
public function testGetLightValue()
{
$this->assertInternalType('float', $this->object->getLightValue());
}
/**
* @covers \MediaVorus\Media\Image::getColorSpace
*/
public function testGetColorSpace()
{
$file = __DIR__ . '/../../../files/ExifTool.jpg';
$media = new Image(new File($file), $this->reader->reset()->files($file)->first(), $this->writer);
$this->assertEquals(Image::COLORSPACE_RGB, $media->getColorSpace());
$file = __DIR__ . '/../../../files/GRAYSCALE.jpg';
$media = new Image(new File($file), $this->reader->reset()->files($file)->first(), $this->writer);
$this->assertEquals(Image::COLORSPACE_GRAYSCALE, $media->getColorSpace());
$file = __DIR__ . '/../../../files/RVB.jpg';
$media = new Image(new File($file), $this->reader->reset()->files($file)->first(), $this->writer);
$this->assertEquals(Image::COLORSPACE_RGB, $media->getColorSpace());
}
public function testSerialize()
{
$json = $this->getSerializer()->serialize($this->object, 'json');
$data = json_decode($json, true);
$this->assertArrayHasKey('type', $data);
$this->assertArrayHasKey('height', $data);
$this->assertArrayHasKey('width', $data);
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace MediaVorus\Media;
use Doctrine\Common\Annotations\AnnotationRegistry;
use JMS\Serializer\SerializerBuilder;
use MediaVorus\TestCase;
class MediaTestCase extends TestCase
{
protected function getSerializer()
{
AnnotationRegistry::registerAutoloadNamespace(
'JMS\Serializer\Annotation', __DIR__ . '/../../../../vendor/jms/serializer/src'
);
return SerializerBuilder::create()
->setCacheDir(__DIR__ . '/../../../../cache')
->setDebug(true)
->build();
}
}

View File

@@ -0,0 +1,105 @@
<?php
namespace MediaVorus\Media;
use MediaVorus\MediaVorus;
use MediaVorus\Media\MediaInterface;
class VideoTest extends MediaTestCase
{
/**
* @var Video
*/
protected $object;
protected $mediavorus;
public function setUp()
{
parent::setUp();
$this->mediavorus = MediaVorus::create();
$this->file = __DIR__ . '/../../../files/videoFlashed.MOV';
$this->object = $this->mediavorus->guess($this->file);
}
/**
* @covers \MediaVorus\Media\Video::getType
*/
public function testGetType()
{
$this->assertEquals(MediaInterface::TYPE_VIDEO, $this->object->getType());
}
/**
* @covers \MediaVorus\Media\Video::getWidth
*/
public function testGetWidth()
{
$this->assertTrue(is_int($this->object->getWidth()));
$this->assertEquals(568, $this->object->getWidth());
}
/**
* @covers \MediaVorus\Media\Video::getHeight
*/
public function testGetHeight()
{
$this->assertTrue(is_int($this->object->getHeight()));
$this->assertEquals(320, $this->object->getHeight());
}
/**
* @covers \MediaVorus\Media\Video::getDuration
*/
public function testGetDuration()
{
$this->assertTrue(is_float($this->object->getDuration()));
$this->assertEquals(2, floor($this->object->getDuration()));
}
/**
* @covers \MediaVorus\Media\Video::getFrameRate
*/
public function testGetFrameRate()
{
$this->assertTrue(is_float($this->object->getFrameRate()));
$this->assertEquals(30.0, $this->object->getFrameRate());
}
/**
* @covers \MediaVorus\Media\Video::getAudioSampleRate
*/
public function testGetAudioSampleRate()
{
$this->assertTrue(is_int($this->object->getAudioSampleRate()));
$this->assertEquals(44100, $this->object->getAudioSampleRate());
}
/**
* @covers \MediaVorus\Media\Video::getVideoCodec
*/
public function testGetVideoCodec()
{
$this->assertEquals('H.264', $this->object->getVideoCodec());
}
/**
* @covers \MediaVorus\Media\Video::getAudioCodec
*/
public function testGetAudioCodec()
{
$this->assertEquals('mp4a', $this->object->getAudioCodec());
}
public function testSerialize()
{
$json = $this->getSerializer()->serialize($this->object, 'json');
$data = json_decode($json, true);
$this->assertArrayNotHasKey('ffprobe', $data);
$this->assertArrayHasKey('type', $data);
$this->assertArrayHasKey('height', $data);
$this->assertArrayHasKey('width', $data);
$this->assertArrayHasKey('duration', $data);
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace MediaVorus;
use FFMpeg\FFProbe;
use MediaVorus\Media\MediaInterface;
use MediaVorus\Filter\MediaType;
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use PHPExiftool\Writer;
use PHPExiftool\Reader;
class MediaCollectionTest extends TestCase
{
/**
* @covers MediaVorus\MediaCollection::match
*/
public function testMatch()
{
$logger = new Logger('test');
$logger->pushHandler(new NullHandler());
$mediavorus = new MediaVorus(Reader::create($logger), Writer::create($logger), FFProbe::create());
$collection = $mediavorus->inspectDirectory(__DIR__ . '/../../files/');
$audio = $collection->match(new MediaType(MediaInterface::TYPE_AUDIO));
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $audio);
$this->assertGreaterThan(0, $audio->count());
foreach ($audio as $audio) {
$this->assertEquals(MediaInterface::TYPE_AUDIO, $audio->getType());
}
$notAudio = $collection->match(new MediaType(MediaInterface::TYPE_AUDIO), true);
$this->assertGreaterThan(0, $notAudio->count());
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $notAudio);
foreach ($notAudio as $audio) {
$this->assertFalse(MediaInterface::TYPE_AUDIO === $audio->getType());
}
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace MediaVorus;
use FFMpeg\FFMpegServiceProvider;
use PHPExiftool\PHPExiftoolServiceProvider;
use Silex\Application;
class MediaVorusServiceProvideTest extends TestCase
{
private function getApplication()
{
return new Application();
}
public function testInitializationWithFFProbe()
{
$app = $this->getApplication();
$app->register(new MediaVorusServiceProvider());
$app->register(new PHPExiftoolServiceProvider());
$app->register(new FFMpegServiceProvider());
$app->boot();
$this->assertInstanceOf('\\MediaVorus\\MediaVorus', $app['mediavorus']);
$this->assertSame($app['exiftool.reader'], $app['mediavorus']->getReader());
$this->assertSame($app['exiftool.writer'], $app['mediavorus']->getWriter());
$this->assertSame($app['ffmpeg.ffprobe'], $app['mediavorus']->getFFProbe());
}
public function testInitializationWithoutFFProbe()
{
$app = $this->getApplication();
$app->register(new MediaVorusServiceProvider());
$app->register(new PHPExiftoolServiceProvider());
$app->boot();
$this->assertInstanceOf('\\MediaVorus\\MediaVorus', $app['mediavorus']);
$this->assertSame($app['exiftool.reader'], $app['mediavorus']->getReader());
$this->assertSame($app['exiftool.writer'], $app['mediavorus']->getWriter());
$this->assertNull($app['mediavorus']->getFFProbe());
}
public function testInitializationWithNonWorkingFFProbe()
{
$app = $this->getApplication();
$app->register(new MediaVorusServiceProvider());
$app->register(new PHPExiftoolServiceProvider());
$app->register(new FFMpegServiceProvider(), array(
'ffmpeg.configuration' => array(
'ffprobe.binaries' => '/path/to/nowhere',
)
));
$app->boot();
$this->assertInstanceOf('\\MediaVorus\\MediaVorus', $app['mediavorus']);
$this->assertSame($app['exiftool.reader'], $app['mediavorus']->getReader());
$this->assertSame($app['exiftool.writer'], $app['mediavorus']->getWriter());
$this->assertNull($app['mediavorus']->getFFProbe());
}
/**
* @expectedException MediaVorus\Exception\RuntimeException
* @expectedExceptionMessage MediaVorus Service Provider requires Exiftool Service Provider
*/
public function testFailOnExiftool()
{
$app = $this->getApplication();
$app->register(new MediaVorusServiceProvider());
$app->register(new FFMpegServiceProvider());
$app->boot();
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace MediaVorus;
use PHPExiftool\Reader;
use PHPExiftool\Writer;
use FFMpeg\FFProbe;
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use MediaVorus\Media\MediaInterface;
class MediaVorusTest extends TestCase
{
/**
* @var MediaVorus
*/
protected $object;
/**
* @covers MediaVorus\MediaVorus::__construct
*/
public function setUp()
{
parent::setUp();
$logger = new Logger('test');
$logger->pushHandler(new NullHandler());
$this->object = new MediaVorus(Reader::create($logger), Writer::create($logger), FFProbe::create());
}
/**
* @covers MediaVorus\MediaVorus::guess
*/
public function testGuess()
{
$media = $this->object->guess(__DIR__ . '/../../files/ExifTool.jpg');
$this->assertInstanceOf('\\MediaVorus\\Media\\MediaInterface', $media);
}
/**
* @covers MediaVorus\MediaVorus::guessFromMimeType
*/
public function testGuessFromMimeType()
{
$media = $this->object->guess(__DIR__ . '/../../files/ExifTool.jpg');
$this->assertInstanceOf('\\MediaVorus\\Media\\Image', $media);
$media = $this->object->guess(__DIR__ . '/../../files/CanonRaw.cr2');
$this->assertInstanceOf('\\MediaVorus\\Media\\Image', $media);
$media = $this->object->guess(__DIR__ . '/../../files/APE.ape');
$this->assertInstanceOf('\\MediaVorus\\Media\\Audio', $media);
$media = $this->object->guess(__DIR__ . '/../../files/PDF.pdf');
$this->assertInstanceOf('\\MediaVorus\\Media\\Document', $media);
$media = $this->object->guess(__DIR__ . '/../../files/ZIP.gz');
$this->assertInstanceOf('\\MediaVorus\\Media\\DefaultMedia', $media);
$media = $this->object->guess(__DIR__ . '/../../files/Flash.swf');
$this->assertInstanceOf('\\MediaVorus\\Media\\Flash', $media);
$media = $this->object->guess(__DIR__ . '/../../files/Test.ogv');
$this->assertInstanceOf('\\MediaVorus\\Media\\Video', $media);
$media = $this->object->guess(__DIR__ . '/../../files/Hello.odt');
$this->assertInstanceOf('\\MediaVorus\\Media\\Document', $media);
$media = $this->object->guess(__DIR__ . '/../../files/Unittestfile.indd');
$this->assertInstanceOf('\\MediaVorus\\Media\\Document', $media);
}
/**
* @covers MediaVorus\MediaVorus::inspectDirectory
*/
public function testInspectDirectory()
{
$medias = $this->object->inspectDirectory(__DIR__ . '/../../files');
$this->assertInstanceOf('\\MediaVorus\\MediaCollection', $medias);
$this->assertEquals(24, count($medias));
foreach ($medias as $media) {
if ($media->getFile()->getFilename() === 'KyoceraRaw.raw') {
continue;
}
if (in_array($media->getFile()->getFilename(), array('XMP.svg', 'Font.dfont'))) {
continue;
}
if ($media->getType() === MediaInterface::TYPE_IMAGE) {
$this->assertInternalType('integer', $media->getWidth(), sprintf('Test width of %s', $media->getFile()->getFilename()));
}
}
}
/**
* @covers MediaVorus\MediaVorus::create
*/
public function testCreate()
{
$this->assertInstanceOf('MediaVorus\\MediaVorus', MediaVorus::create());
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace MediaVorus;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser;
use MediaVorus\Utils\RawImageMimeTypeGuesser;
use MediaVorus\Utils\PostScriptMimeTypeGuesser;
use MediaVorus\Utils\AudioMimeTypeGuesser;
use MediaVorus\Utils\VideoMimeTypeGuesser;
class TestCase extends \PHPUnit_Framework_TestCase
{
public static $registered = false;
public function setUp()
{
if (!static::$registered) {
$guesser = MimeTypeGuesser::getInstance();
$guesser->register(new FileBinaryMimeTypeGuesser());
$guesser->register(new RawImageMimeTypeGuesser());
$guesser->register(new PostScriptMimeTypeGuesser());
$guesser->register(new AudioMimeTypeGuesser());
$guesser->register(new VideoMimeTypeGuesser());
static::$registered = true;
}
}
}