|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Stinger Media Parser package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Oliver Kotte <[email protected]> |
|
7
|
|
|
* (c) Florian Meyer <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace StingerSoft\MediaParsingBundle\Tests\Parser; |
|
14
|
|
|
|
|
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
|
16
|
|
|
use StingerSoft\MediaParsingBundle\Tests\TestCase; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\File\File; |
|
18
|
|
|
use StingerSoft\MediaParsingBundle\Parser\ParserChainInterface; |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
class ParserChainTest extends TestCase { |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* |
|
25
|
|
|
* @var IParserChain |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $parserChain; |
|
28
|
|
|
|
|
29
|
|
|
public function setUp(){ |
|
30
|
|
|
$this->parserChain = $this->createContainer()->get(ParserChainInterface::SERVICE_ID); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testAddParser(){ |
|
34
|
|
|
$this->assertGreaterThanOrEqual(1, count($this->parserChain->getAllParser()), 'No media parser found!'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testFindFileParser(){ |
|
38
|
|
|
$file = new File(__DIR__.'/../Fixtures/test.mp3'); |
|
39
|
|
|
$parser = $this->parserChain->getParser($file); |
|
40
|
|
|
$this->assertInstanceOf('StingerSoft\MediaParsingBundle\Parser\Types\Mp3Parser', $parser, 'No mp3 media parser found!'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testFindNoFileParser(){ |
|
44
|
|
|
$file = new File(__DIR__.'/../Fixtures/notparsable.ddd'); |
|
45
|
|
|
$parser = $this->parserChain->getParser($file); |
|
46
|
|
|
$this->assertNull($parser); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testParseNull(){ |
|
50
|
|
|
$this->setExpectedException('Exception'); |
|
51
|
|
|
$this->parserChain->parseFile(null); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testParseDirectory(){ |
|
55
|
|
|
$this->setExpectedException('Exception'); |
|
56
|
|
|
$this->parserChain->parseFile(__DIR__); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testMp3Parsing(){ |
|
60
|
|
|
$file = new File(__DIR__.'/../Fixtures/test.mp3'); |
|
61
|
|
|
$info = $this->parserChain->parseFile($file); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertInstanceOf('StingerSoft\MediaParsingBundle\Parser\Information\SongInformationInterface', $info); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testParseTheUnparsable(){ |
|
67
|
|
|
$file = new File(__DIR__.'/../Fixtures/notparsable.ddd'); |
|
68
|
|
|
$parser = $this->parserChain->parseFile($file); |
|
69
|
|
|
$this->assertFalse($parser); |
|
70
|
|
|
} |
|
71
|
|
|
} |