Passed
Push — master ( e3acee...71d19a )
by Jeroen De
02:21
created

testCallbackIsGivenArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Diff\Tests\Comparer;
6
7
use Diff\Comparer\CallbackComparer;
8
use Diff\Tests\DiffTestCase;
9
10
/**
11
 * @covers \Diff\Comparer\CallbackComparer
12
 *
13
 * @group Diff
14
 * @group Comparer
15
 *
16
 * @license BSD-3-Clause
17
 * @author Jeroen De Dauw < [email protected] >
18
 */
19
class CallbackComparerTest extends DiffTestCase {
20
21
	public function testWhenCallbackReturnsTrue_valuesAreEqual() {
22
		$comparer = new CallbackComparer( function() {
23
			return true;
24
		} );
25
26
		$this->assertTrue( $comparer->valuesAreEqual( null, null ) );
27
	}
28
29
	public function testWhenCallbackReturnsFalse_valuesAreNotEqual() {
30
		$comparer = new CallbackComparer( function() {
31
			return false;
32
		} );
33
34
		$this->assertFalse( $comparer->valuesAreEqual( null, null ) );
35
	}
36
37
	public function testWhenCallbackReturnsNonBoolean_exceptionIsThrown() {
38
		$comparer = new CallbackComparer( function() {
39
			return null;
40
		} );
41
42
		$this->expectException( \RuntimeException::class );
43
		$comparer->valuesAreEqual( null, null );
44
	}
45
46
	public function testCallbackIsGivenArguments() {
47
		$firstArgument = null;
48
		$secondArgument = null;
49
50
		$comparer = new CallbackComparer( function( $a, $b ) use ( &$firstArgument, &$secondArgument ) {
51
			$firstArgument = $a;
52
			$secondArgument = $b;
53
			return true;
54
		} );
55
56
		$comparer->valuesAreEqual( 42, 23 );
57
58
		$this->assertSame( 42, $firstArgument );
59
		$this->assertSame( 23, $secondArgument );
60
	}
61
62
}
63