Replace use of assertType with assertInternalType and assertInstanceOf
authoraude <aude.wiki@gmail.com>
Thu, 9 Apr 2015 04:53:37 +0000 (00:53 -0400)
committeraude <aude.wiki@gmail.com>
Thu, 9 Apr 2015 05:15:44 +0000 (01:15 -0400)
These are available in phpunit since 3.5.0, which I think
is reasonable to expect people to have at this point,
especially when we actually require 3.7.0 or higher in phpunit.php:

Use assertSame instead of assertArrayEquals in UIDGeneratorTest.
assertSame (and assertEqual) care about sortorder of the array,
and is perfectly sufficient in this case to check they array is correct.

if ( $puVersion !== '@package_version@' && version_compare( $puVersion, '3.7.0', '<' ) ) {
        die( "PHPUnit 3.7.0 or later required; you have {$puVersion}.\n" );
}

Change-Id: Ic32ab45110e4c4304ef046ae8d0e98c741255559

tests/phpunit/includes/api/query/ApiQueryTestBase.php
tests/phpunit/includes/filebackend/FileBackendTest.php
tests/phpunit/includes/json/FormatJsonTest.php
tests/phpunit/includes/utils/UIDGeneratorTest.php

index dabf72e..9e830f2 100644 (file)
@@ -56,12 +56,12 @@ STR;
         * @return array
         */
        private function validateRequestExpectedPair( $v ) {
-               $this->assertType( 'array', $v, self::PARAM_ASSERT );
+               $this->assertInternalType( 'array', $v, self::PARAM_ASSERT );
                $this->assertEquals( 2, count( $v ), self::PARAM_ASSERT );
                $this->assertArrayHasKey( 0, $v, self::PARAM_ASSERT );
                $this->assertArrayHasKey( 1, $v, self::PARAM_ASSERT );
-               $this->assertType( 'array', $v[0], self::PARAM_ASSERT );
-               $this->assertType( 'array', $v[1], self::PARAM_ASSERT );
+               $this->assertInternalType( 'array', $v[0], self::PARAM_ASSERT );
+               $this->assertInternalType( 'array', $v[1], self::PARAM_ASSERT );
 
                return $v;
        }
index bfca75a..aaa93ef 100644 (file)
@@ -2376,7 +2376,7 @@ class FileBackendTest extends MediaWikiTestCase {
 
                $status = Status::newGood();
                $sl = $this->backend->getScopedFileLocks( $paths, LockManager::LOCK_EX, $status );
-               $this->assertType( 'ScopedLock', $sl,
+               $this->assertInstanceOf( 'ScopedLock', $sl,
                        "Scoped locking of files succeeded ($backendName)." );
                $this->assertEquals( array(), $status->errors,
                        "Scoped locking of files succeeded ($backendName)." );
index f0ac6ac..8bca333 100644 (file)
@@ -159,12 +159,12 @@ class FormatJsonTest extends MediaWikiTestCase {
                $this->assertJson( $json );
 
                $st = FormatJson::parse( $json );
-               $this->assertType( 'Status', $st );
+               $this->assertInstanceOf( 'Status', $st );
                $this->assertTrue( $st->isGood() );
                $this->assertEquals( $expected, $st->getValue() );
 
                $st = FormatJson::parse( $json, FormatJson::FORCE_ASSOC );
-               $this->assertType( 'Status', $st );
+               $this->assertInstanceOf( 'Status', $st );
                $this->assertTrue( $st->isGood() );
                $this->assertEquals( $value, $st->getValue() );
        }
@@ -230,7 +230,7 @@ class FormatJsonTest extends MediaWikiTestCase {
                }
 
                $st = FormatJson::parse( $value, FormatJson::TRY_FIXING );
-               $this->assertType( 'Status', $st );
+               $this->assertInstanceOf( 'Status', $st );
                if ( $expected === false ) {
                        $this->assertFalse( $st->isOK(), 'Expected isOK() == false' );
                } else {
@@ -256,7 +256,7 @@ class FormatJsonTest extends MediaWikiTestCase {
         */
        public function testParseErrors( $value ) {
                $st = FormatJson::parse( $value );
-               $this->assertType( 'Status', $st );
+               $this->assertInstanceOf( 'Status', $st );
                $this->assertFalse( $st->isOK() );
        }
 
@@ -313,7 +313,7 @@ class FormatJsonTest extends MediaWikiTestCase {
         */
        public function testParseStripComments( $json, $expect ) {
                $st = FormatJson::parse( $json, FormatJson::STRIP_COMMENTS );
-               $this->assertType( 'Status', $st );
+               $this->assertInstanceOf( 'Status', $st );
                $this->assertTrue( $st->isGood() );
                $this->assertEquals( $expect, $st->getValue() );
        }
index 0e11cca..fedcc76 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-class UIDGeneratorTest extends MediaWikiTestCase {
+class UIDGeneratorTest extends PHPUnit_Framework_TestCase {
 
        protected function tearDown() {
                // Bug: 44850
@@ -28,7 +28,7 @@ class UIDGeneratorTest extends MediaWikiTestCase {
 
                $lastId = array_shift( $ids );
 
-               $this->assertArrayEquals( array_unique( $ids ), $ids, "All generated IDs are unique." );
+               $this->assertSame( array_unique( $ids ), $ids, "All generated IDs are unique." );
 
                foreach ( $ids as $id ) {
                        $id_bin = wfBaseConvert( $id, 10, 2 );
@@ -105,8 +105,8 @@ class UIDGeneratorTest extends MediaWikiTestCase {
                $id1 = UIDGenerator::newSequentialPerNodeID( 'test', 32 );
                $id2 = UIDGenerator::newSequentialPerNodeID( 'test', 32 );
 
-               $this->assertType( 'float', $id1, "ID returned as float" );
-               $this->assertType( 'float', $id2, "ID returned as float" );
+               $this->assertInternalType( 'float', $id1, "ID returned as float" );
+               $this->assertInternalType( 'float', $id2, "ID returned as float" );
                $this->assertGreaterThan( 0, $id1, "ID greater than 1" );
                $this->assertGreaterThan( $id1, $id2, "IDs increasing in value" );
        }
@@ -118,7 +118,7 @@ class UIDGeneratorTest extends MediaWikiTestCase {
                $ids = UIDGenerator::newSequentialPerNodeIDs( 'test', 32, 5 );
                $lastId = null;
                foreach ( $ids as $id ) {
-                       $this->assertType( 'float', $id, "ID returned as float" );
+                       $this->assertInternalType( 'float', $id, "ID returned as float" );
                        $this->assertGreaterThan( 0, $id, "ID greater than 1" );
                        if ( $lastId ) {
                                $this->assertGreaterThan( $lastId, $id, "IDs increasing in value" );