b03734e8bd8e7e2186d312276bb478a97c834d38
[lhc/web/wiklou.git] / tests / phpunit / includes / db / DatabaseOracleTest.php
1 <?php
2
3 class DatabaseOracleTest extends PHPUnit\Framework\TestCase {
4
5 use MediaWikiCoversValidator;
6
7 /**
8 * @return PHPUnit_Framework_MockObject_MockObject|DatabaseOracle
9 */
10 private function getMockDb() {
11 return $this->getMockBuilder( DatabaseOracle::class )
12 ->disableOriginalConstructor()
13 ->setMethods( null )
14 ->getMock();
15 }
16
17 public function provideBuildSubstring() {
18 yield [ 'someField', 1, 2, 'SUBSTR(someField,1,2)' ];
19 yield [ 'someField', 1, null, 'SUBSTR(someField,1)' ];
20 }
21
22 /**
23 * @covers DatabaseOracle::buildSubstring
24 * @dataProvider provideBuildSubstring
25 */
26 public function testBuildSubstring( $input, $start, $length, $expected ) {
27 $mockDb = $this->getMockDb();
28 $output = $mockDb->buildSubstring( $input, $start, $length );
29 $this->assertSame( $expected, $output );
30 }
31
32 public function provideBuildSubstring_invalidParams() {
33 yield [ -1, 1 ];
34 yield [ 1, -1 ];
35 yield [ 1, 'foo' ];
36 yield [ 'foo', 1 ];
37 yield [ null, 1 ];
38 yield [ 0, 1 ];
39 }
40
41 /**
42 * @covers DatabaseOracle::buildSubstring
43 * @dataProvider provideBuildSubstring_invalidParams
44 */
45 public function testBuildSubstring_invalidParams( $start, $length ) {
46 $mockDb = $this->getMockDb();
47 $this->setExpectedException( InvalidArgumentException::class );
48 $mockDb->buildSubstring( 'foo', $start, $length );
49 }
50
51 }