StateChangeParserTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
eloc 17
c 2
b 0
f 2
dl 0
loc 42
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A messageProvider() 0 14 1
A testParseMessage() 0 11 1
1
<?php
2
3
namespace Jalle19\StatusManager\Test\Subscription;
4
5
use Jalle19\StatusManager\Subscription\StateChange;
6
use Jalle19\StatusManager\Subscription\StateChangeParser;
7
use Jalle19\tvheadend\model\comet\LogMessageNotification;
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * Class StateChangeParserTest
12
 * @package   Jalle19\StatusManager\Test\Subscription
13
 * @copyright Copyright &copy; Sam Stenvall 2016-
14
 * @license   https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0
15
 */
16
class StateChangeParserTest extends TestCase
17
{
18
19
	/**
20
	 * @param string $message
21
	 * @param int    $expectedSubscriptionId
22
	 * @param string $expectedState
23
	 * @param string $expectedJson
24
	 *
25
	 * @dataProvider messageProvider
26
	 */
27
	public function testParseMessage($message, $expectedSubscriptionId, $expectedState, $expectedJson)
28
	{
29
		$logMessage         = new LogMessageNotification();
30
		$logMessage->logtxt = $message;
31
32
		$stateChanges = StateChangeParser::parseStateChanges([$logMessage]);
33
		$stateChange  = $stateChanges[0];
34
35
		$this->assertEquals($expectedSubscriptionId, $stateChange->getSubscriptionId());
36
		$this->assertEquals($expectedState, $stateChange->getState());
37
		$this->assertJson(json_encode($stateChange), $expectedJson);
38
	}
39
40
41
	/**
42
	 * @return array
43
	 */
44
	public function messageProvider()
45
	{
46
		return [
47
			[
48
				'2016-04-03 20:29:44.495 subscription: 296B: "HTTP" subscribing on channel "Axess TV", weight: 100, adapter: "IPTV", network: "foo", mux: "bar", provider: "Levira", service: "Axess TV", profile="pass", hostname="::ffff", client="VLC/2.2.1 LibVLC/2.2.1"',
49
				hexdec('296B'),
50
				StateChange::STATE_SUBSCRIPTION_STARTED,
51
				json_encode([hexdec('296B'), StateChange::STATE_SUBSCRIPTION_STARTED]),
52
			],
53
			[
54
				'2016-04-03 20:29:44.495 subscription: 296B: "HTTP" unsubscribing from "Axess TV", hostname="::ffff", client="VLC/2.2.1 LibVLC/2.2.1"',
55
				hexdec('296B'),
56
				StateChange::STATE_SUBSCRIPTION_STOPPED,
57
				json_encode([hexdec('296B'), StateChange::STATE_SUBSCRIPTION_STOPPED]),
58
			],
59
		];
60
	}
61
62
}
63