GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

NamesEnumTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 84
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testNonExistingEnumValue() 0 4 1
A testEnumCoverage() 0 7 1
A provideEnumClasses() 0 7 1
A testMapping() 0 15 1
A provideMappings() 0 19 1
1
<?php
2
3
namespace prgTW\BaseCRM\Tests\Utils;
4
5
use prgTW\BaseCRM\Service\Enum\Currency;
6
use prgTW\BaseCRM\Service\Enum\NamedEnum;
7
use prgTW\BaseCRM\Service\Enum\TagAppId;
8
9
class NamesEnumTest extends \PHPUnit_Framework_TestCase
10
{
11
	/**
12
	 * @dataProvider provideEnumClasses
13
	 * @expectedException \InvalidArgumentException
14
	 *
15
	 * @param string $enumClass
16
	 */
17
	public function testNonExistingEnumValue($enumClass)
18
	{
19
		call_user_func_array(sprintf('%s::fromName', $enumClass), ['non_existing']);
20
	}
21
22
	/**
23
	 * @dataProvider provideEnumClasses
24
	 *
25
	 * @param string $enumClass
26
	 */
27
	public function testEnumCoverage($enumClass)
28
	{
29
		$values = call_user_func_array(sprintf('%s::toArray', $enumClass), []);
30
		$names  = call_user_func_array(sprintf('%s::getNames', $enumClass), []);
31
		$this->assertEquals(count($values), count($names));
32
		$this->assertEquals(array_values($values), array_keys($names));
33
	}
34
35
	/**
36
	 * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
37
	 */
38
	public function provideEnumClasses()
39
	{
40
		return [
41
			[Currency::class],
42
			[TagAppId::class],
43
		];
44
	}
45
46
	/**
47
	 * @dataProvider provideMappings
48
	 *
49
	 * @param string $enumClass
50
	 * @param mixed  $value
51
	 * @param string $abbr
52
	 * @param mixed  $name
53
	 */
54
	public function testMapping($enumClass, $value, $abbr, $name)
55
	{
56
		/** @var NamedEnum $namedEnum */
57
		$namedEnum = call_user_func_array(sprintf('%s::%s', $enumClass, $abbr), []);
58
		$this->assertEquals($name, $namedEnum->getName());
59
		$this->assertEquals($value, $namedEnum->getValue());
60
61
		/** @var NamedEnum $namedEnum */
62
		$namedEnum = new $enumClass($value);
63
		$this->assertEquals($value, $namedEnum->getValue());
64
65
		/** @var NamedEnum $enum */
66
		$namedEnum = call_user_func_array(sprintf('%s::fromName', $enumClass), [$name]);
67
		$this->assertEquals($value, $namedEnum->getValue());
68
	}
69
70
	/**
71
	 * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<integer|string>[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
72
	 */
73
	public function provideMappings()
74
	{
75
		return [
76
			[Currency::class, 1, 'USD', 'US Dollar'],
77
			[Currency::class, 2, 'GBP', 'British Pound'],
78
			[Currency::class, 3, 'EUR', 'Euro'],
79
			[Currency::class, 4, 'JPY', 'Yen'],
80
			[Currency::class, 5, 'CAD', 'Canadian Dollar'],
81
			[Currency::class, 6, 'AUD', 'Australian Dollar'],
82
			[Currency::class, 7, 'ZAR', 'South African Rand'],
83
			[Currency::class, 8, 'PLN', 'Polish złoty'],
84
			[Currency::class, 9, 'DKK', 'Danish Kroner'],
85
			[Currency::class, 10, 'NZD', 'New Zealand Dollar'],
86
			[Currency::class, 11, 'INR', 'Indian Rupee'],
87
			[TagAppId::class, 1, 'DEALS', 'Deal'],
88
			[TagAppId::class, 4, 'CONTACTS', 'Contact'],
89
			[TagAppId::class, 5, 'LEADS', 'Lead'],
90
		];
91
	}
92
}
93