6 * @covers WatchedItemStore
8 class WatchedItemStoreTest
extends PHPUnit_Framework_TestCase
{
11 * @return PHPUnit_Framework_MockObject_MockObject|IDatabase
13 private function getMockDb() {
14 return $this->getMock( 'IDatabase' );
18 * @return PHPUnit_Framework_MockObject_MockObject|LoadBalancer
20 private function getMockLoadBalancer( $mockDb ) {
21 $mock = $this->getMockBuilder( 'LoadBalancer' )
22 ->disableOriginalConstructor()
24 $mock->expects( $this->any() )
25 ->method( 'getConnection' )
26 ->will( $this->returnValue( $mockDb ) );
30 private function getFakeRow( $userId, $timestamp ) {
31 $fakeRow = new stdClass();
32 $fakeRow->wl_user
= $userId;
33 $fakeRow->wl_notificationtimestamp
= $timestamp;
37 public function testDuplicateEntry_nothingToDuplicate() {
38 $mockDb = $this->getMockDb();
39 $mockDb->expects( $this->exactly( 1 ) )
41 ->will( $this->returnValue( new FakeResultWrapper( [] ) ) );
43 $store = new WatchedItemStore( $this->getMockLoadBalancer( $mockDb ) );
45 $store->duplicateEntry(
46 Title
::newFromText( 'Old_Title' ),
47 Title
::newFromText( 'New_Title' )
51 public function testDuplicateEntry_somethingToDuplicate() {
53 $this->getFakeRow( 1, '20151212010101' ),
54 $this->getFakeRow( 2, null ),
57 $mockDb = $this->getMockDb();
58 $mockDb->expects( $this->at( 0 ) )
60 ->will( $this->returnValue( new FakeResultWrapper( $fakeRows ) ) );
61 $mockDb->expects( $this->at( 1 ) )
65 [ [ 'wl_user', 'wl_namespace', 'wl_title' ] ],
70 'wl_title' => 'New_Title',
71 'wl_notificationtimestamp' => '20151212010101',
76 'wl_title' => 'New_Title',
77 'wl_notificationtimestamp' => null,
80 $this->isType( 'string' )
83 $store = new WatchedItemStore( $this->getMockLoadBalancer( $mockDb ) );
85 $store->duplicateEntry(
86 Title
::newFromText( 'Old_Title' ),
87 Title
::newFromText( 'New_Title' )