Completed
Push — master ( 3294f9...cc37b1 )
by mw
19s
created

DeferredCallableUpdateTest::testOrigin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 8
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 15
rs 9.4285
1
<?php
2
3
namespace SMW\Tests;
4
5
use SMW\DeferredCallableUpdate;
6
7
/**
8
 * @covers \SMW\DeferredCallableUpdate
9
 * @group semantic-mediawiki
10
 *
11
 * @license GNU GPL v2+
12
 * @since 2.4
13
 *
14
 * @author mwjames
15
 */
16
class DeferredCallableUpdateTest extends \PHPUnit_Framework_TestCase {
17
18
	private $testEnvironment;
19
20
	protected function setUp() {
21
		parent::setUp();
22
		$this->testEnvironment = new TestEnvironment();
23
	}
24
25
	protected function tearDown() {
26
		$this->testEnvironment->tearDown();
27
		parent::tearDown();
28
	}
29
30
	public function testCanConstruct() {
31
32
		$callback = function() {
33
			return null;
34
		};
35
36
		$this->assertInstanceOf(
37
			'\SMW\DeferredCallableUpdate',
38
			new DeferredCallableUpdate( $callback )
39
		);
40
	}
41
42
	public function testUpdate() {
43
44
		$this->testEnvironment->clearPendingDeferredUpdates();
45
46
		$test = $this->getMockBuilder( '\stdClass' )
47
			->disableOriginalConstructor()
48
			->setMethods( array( 'doTest' ) )
49
			->getMock();
50
51
		$test->expects( $this->once() )
52
			->method( 'doTest' );
53
54
		$callback = function() use ( $test ) {
55
			$test->doTest();
56
		};
57
58
		$instance = new DeferredCallableUpdate(
59
			$callback
60
		);
61
62
		$instance->pushToDeferredUpdateList();
0 ignored issues
show
Deprecated Code introduced by
The method SMW\DeferredCallableUpda...hToDeferredUpdateList() has been deprecated with message: since 2.5, use DeferredCallableUpdate::pushUpdate

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...
63
64
		$this->testEnvironment->executePendingDeferredUpdates();
65
	}
66
67
	public function testWaitableUpdate() {
68
69
		$this->testEnvironment->clearPendingDeferredUpdates();
70
71
		$test = $this->getMockBuilder( '\stdClass' )
72
			->disableOriginalConstructor()
73
			->setMethods( array( 'doTest' ) )
74
			->getMock();
75
76
		$test->expects( $this->once() )
77
			->method( 'doTest' );
78
79
		$callback = function() use ( $test ) {
80
			$test->doTest();
81
		};
82
83
		$instance = new DeferredCallableUpdate(
84
			$callback
85
		);
86
87
		$instance->markAsPending( true );
88
		$instance->pushToDeferredUpdateList();
0 ignored issues
show
Deprecated Code introduced by
The method SMW\DeferredCallableUpda...hToDeferredUpdateList() has been deprecated with message: since 2.5, use DeferredCallableUpdate::pushUpdate

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...
89
90
		$instance->releasePendingUpdates();
91
92
		$this->testEnvironment->executePendingDeferredUpdates();
93
	}
94
95
	public function testUpdateWithDisabledDeferredUpdate() {
96
97
		$test = $this->getMockBuilder( '\stdClass' )
98
			->disableOriginalConstructor()
99
			->setMethods( array( 'doTest' ) )
100
			->getMock();
101
102
		$test->expects( $this->once() )
103
			->method( 'doTest' );
104
105
		$callback = function() use ( $test ) {
106
			$test->doTest();
107
		};
108
109
		$instance = new DeferredCallableUpdate(
110
			$callback
111
		);
112
113
		$instance->enabledDeferredUpdate( false );
114
		$instance->pushUpdate();
115
	}
116
117
	public function testOrigin() {
118
119
		$callback = function() {};
120
121
		$instance = new DeferredCallableUpdate(
122
			$callback
123
		);
124
125
		$instance->setOrigin( 'Foo' );
126
127
		$this->assertEquals(
128
			'Foo',
129
			$instance->getOrigin()
130
		);
131
	}
132
133
}
134