DatabaseOracleTest.php 1.3 KB

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