Completed
Push — modernize ( 37d3ad )
by Jeroen De
05:12
created

ErrorTest::testNewError()   B

Complexity

Conditions 6
Paths 16

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.7857
c 0
b 0
f 0
cc 6
nc 16
nop 0
1
<?php
2
3
namespace ValueValidators\Tests;
4
5
use PHPUnit\Framework\TestCase;
6
use ValueValidators\Error;
7
8
/**
9
 * @covers \ValueValidators\Error
10
 *
11
 * @group ValueValidators
12
 * @group DataValueExtensions
13
 *
14
 * @license GPL-2.0+
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
class ErrorTest extends TestCase {
18
19
	public function newErrorProvider() {
20
		$argLists = [];
21
22
		$argLists[] = [];
23
24
		$argLists[] = [ '' ];
25
		$argLists[] = [ 'foo' ];
26
		$argLists[] = [ ' foo bar baz.' ];
27
28
		$argLists[] = [ ' foo bar ', null ];
29
		$argLists[] = [ ' foo bar ', 'length' ];
30
31
		$argLists[] = [ ' foo bar ', null, 'something-went-wrong' ];
32
		$argLists[] = [ ' foo bar ', null, 'something-went-wrong', [ 'foo', 'bar' ] ];
33
34
		return $argLists;
35
	}
36
37
	/**
38
	 * @dataProvider newErrorProvider
39
	 */
40
	public function testNewError() {
41
		$args = func_get_args();
42
43
		$error = call_user_func_array( [ Error::class, 'newError' ], $args );
44
45
		/**
46
		 * @var Error $error
47
		 */
48
		$this->assertInstanceOf( 'ValueValidators\Error', $error );
49
50
		$this->assertInternalType( 'string', $error->getText() );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
51
		$this->assertInternalType( 'integer', $error->getSeverity() );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
52
		$this->assertTrue( is_string( $error->getProperty() ) || is_null( $error->getProperty() ) );
53
		$this->assertInternalType( 'string', $error->getCode() );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
54
		$this->assertInternalType( 'array', $error->getParameters() );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
55
56
		if ( count( $args ) > 0 ) {
57
			$this->assertSame( $args[0], $error->getText() );
58
		}
59
60
		if ( count( $args ) > 1 ) {
61
			$this->assertSame( $args[1], $error->getProperty() );
62
		}
63
64
		if ( count( $args ) > 2 ) {
65
			$this->assertSame( $args[2], $error->getCode() );
66
		}
67
68
		if ( count( $args ) > 3 ) {
69
			$this->assertSame( $args[3], $error->getParameters() );
70
		}
71
	}
72
73
}
74