connection = $this->getMockBuilder( '\SMW\MediaWiki\Connection\Database' ) ->disableOriginalConstructor() ->getMock(); } public function testCanConstruct() { $this->assertInstanceOf( Sequence::class, new Sequence( $this->connection ) ); } public function testConstructWithInvalidConnectionThrowsException() { $this->expectException( '\RuntimeException' ); new Sequence( 'Foo' ); } public function testMakeSequence() { $this->assertEquals( 'Foo_bar_seq', Sequence::makeSequence( 'Foo', 'bar' ) ); } public function testNonPostgres() { $this->connection->expects( $this->once() ) ->method( 'getType' ) ->willReturn( 'foo' ); $instance = new Sequence( $this->connection ); $this->assertNull( $instance->restart( 'Foo', 'bar' ) ); } public function testPostgres() { $this->connection->expects( $this->once() ) ->method( 'getType' ) ->willReturn( 'postgres' ); $this->connection->expects( $this->once() ) ->method( 'onTransactionCommitOrIdle' ) ->willReturnCallback( static function ( $callback ) { return $callback(); } ); $this->connection->expects( $this->once() ) ->method( 'query' ) ->with( 'ALTER SEQUENCE Foo_bar_seq RESTART WITH 43' ); $this->connection->expects( $this->once() ) ->method( 'selectField' ) ->willReturn( 42 ); $instance = new Sequence( $this->connection ); $this->assertEquals( 43, $instance->restart( 'Foo', 'bar' ) ); } }