blob: 3497f40f49fa9f80bb8b3468ffbe28d9fa8a86fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
<?php
namespace SMW\Tests\SQLStore\TableBuilder\Examiner;
use SMW\SQLStore\TableBuilder\Examiner\HashField;
use SMW\Tests\TestEnvironment;
/**
* @covers \SMW\SQLStore\TableBuilder\Examiner\HashField
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 3.1
*
* @author mwjames
*/
class HashFieldTest extends \PHPUnit_Framework_TestCase {
private $spyMessageReporter;
private $store;
private $populateHashField;
protected function setUp() {
parent::setUp();
$this->spyMessageReporter = TestEnvironment::getUtilityFactory()->newSpyMessageReporter();
$this->store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' )
->disableOriginalConstructor()
->getMock();
$this->populateHashField = $this->getMockBuilder( '\SMW\Maintenance\PopulateHashField' )
->disableOriginalConstructor()
->getMock();
}
public function testCanConstruct() {
$this->assertInstanceOf(
HashField::class,
new HashField( $this->store )
);
}
public function testCheck_Populate() {
$resultWrapper = $this->getMockBuilder( '\ResultWrapper' )
->disableOriginalConstructor()
->getMock();
$resultWrapper->expects( $this->once() )
->method( 'numRows' )
->will( $this->returnValue( HashField::threshold() - 1 ) );
$this->populateHashField->expects( $this->atLeastOnce() )
->method( 'populate' );
$this->populateHashField->expects( $this->once() )
->method( 'fetchRows' )
->will( $this->returnValue( $resultWrapper ) );
$instance = new HashField(
$this->store,
$this->populateHashField
);
$instance->setMessageReporter( $this->spyMessageReporter );
$instance->check();
$this->assertContains(
'Checking smw_hash field consistency',
$this->spyMessageReporter->getMessagesAsString()
);
}
public function testCheck_Incomplete() {
$resultWrapper = $this->getMockBuilder( '\ResultWrapper' )
->disableOriginalConstructor()
->getMock();
$resultWrapper->expects( $this->once() )
->method( 'numRows' )
->will( $this->returnValue( HashField::threshold() + 1 ) );
$this->populateHashField->expects( $this->atLeastOnce() )
->method( 'setComplete' );
$this->populateHashField->expects( $this->once() )
->method( 'fetchRows' )
->will( $this->returnValue( $resultWrapper ) );
$instance = new HashField(
$this->store,
$this->populateHashField
);
$instance->setMessageReporter( $this->spyMessageReporter );
$instance->check();
$this->assertContains(
'Checking smw_hash field consistency',
$this->spyMessageReporter->getMessagesAsString()
);
}
}
|