Skip to content

Commit

Permalink
(tests) Replace assertEquals() with more strict assertSame()
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardspec committed Jan 7, 2025
1 parent 24114e6 commit 7a495ee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions tests/phpunit/AmazonS3FileBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ public function testCreate() {
public function testGetFileStat( array $params ) {
$info = $this->getBackend()->doGetFileStat( [ 'src' => $params['dst'] ] );

$this->assertEquals( $info['size'], strlen( $params['content'] ),
$this->assertSame( $info['size'], strlen( $params['content'] ),
'GetFileStat(): incorrect filesize after doCreateInternal()' );

$expectedSHA1 = Wikimedia\base_convert( sha1( $params['content'] ), 16, 36, 31 );
$this->assertEquals( $expectedSHA1, $info['sha1'],
$this->assertSame( $expectedSHA1, $info['sha1'],
'GetFileStat(): incorrect SHA1 after doCreateInternal()' );
}

Expand All @@ -155,7 +155,7 @@ public function testFileHttpUrl( array $params ) {
$this->assertNotNull( $url, 'No URL returned by getFileHttpUrl()' );

$content = $this->httpGet( $url );
$this->assertEquals( $params['content'], $content,
$this->assertSame( $params['content'], $content,
'Content downloaded from FileHttpUrl is different from expected' );
}

Expand Down Expand Up @@ -272,15 +272,15 @@ public function testList( $method, $directory, $params, $expectedResult ) {
$params
);
if ( $method == 'doDirectoryExists' ) {
$this->assertEquals( $expectedResult, $result );
$this->assertSame( $expectedResult, $result );
return;
}

$foundFilenames = iterator_to_array( $result );

sort( $expectedResult );
sort( $foundFilenames );
$this->assertEquals( $expectedResult, $foundFilenames,
$this->assertSame( $expectedResult, $foundFilenames,
"Directory listing doesn't match expected."
);
}
Expand Down Expand Up @@ -308,7 +308,7 @@ public function testGetLocalCopyMulti() {
foreach ( $src as $filename => $virtualPath ) {
$this->assertArrayHasKey( $virtualPath, $result,
"URL $virtualPath not found() in array returned by doGetLocalCopyMulti()" );
$this->assertEquals(
$this->assertSame(
$this->getTestContent( $filename ),
file_get_contents( $result[$virtualPath]->getPath() ),
"Incorrect contents of $virtualPath returned by doGetLocalCopyMulti()"
Expand Down Expand Up @@ -401,7 +401,7 @@ public function testStoreInternal() {
$this->assertNotNull( $url, 'No URL returned by getFileHttpUrl()' );

$content = $this->httpGet( $url );
$this->assertEquals( $expectedContent, $content,
$this->assertSame( $expectedContent, $content,
'Content downloaded from FileHttpUrl is different from expected' );
}

Expand Down Expand Up @@ -483,7 +483,7 @@ public function testSecureAndPublish() {
$url = $this->getClient()->getObjectUrl( $bucket, $prefix . $key );
$securityAfterTest = ( $this->httpGet( $url ) === false );

$this->assertEquals( $expectedSecurity, $securityAfterTest,
$this->assertSame( $expectedSecurity, $securityAfterTest,
"Incorrect ACL: S3 Object uploaded after $method() is " .
( $expectedSecurity ? "publicly accessible" : "restricted for reading" ) );
}
Expand Down Expand Up @@ -538,10 +538,10 @@ public function testContentType( $method, $filename, $expectedContentType, $expe
'Key' => $key
] );
$this->assertArrayHasKey( 'ContentType', $response );
$this->assertEquals( $expectedContentType, $response['ContentType'] );
$this->assertSame( $expectedContentType, $response['ContentType'] );

$this->assertArrayHasKey( 'sha1base36', $response['Metadata'] );
$this->assertEquals( $expectedSha1Base36, $response['Metadata']['sha1base36'] );
$this->assertSame( $expectedSha1Base36, $response['Metadata']['sha1base36'] );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/AmazonS3HooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function testConfig( array $opt ) {

$this->assertArrayHasKey( 's3', $wgFileBackends,
"\$wgFileBackends array doesn't have 's3' key" );
$this->assertEquals( $expectedBackend, $wgFileBackends['s3'],
$this->assertSame( $expectedBackend, $wgFileBackends['s3'],
"Unexpected value of \$wgFileBackends['s3']" );

// Step 2. Check $wgLocalFileRepo.
Expand Down Expand Up @@ -163,7 +163,7 @@ public function testConfig( array $opt ) {
];
}

$this->assertEquals( $expectedRepo, $wgLocalFileRepo, "Unexpected \$wgLocalFileRepo" );
$this->assertSame( $expectedRepo, $wgLocalFileRepo, "Unexpected \$wgLocalFileRepo" );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/AmazonS3LocalCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function testEnabledLocalCache() {
$this->assertNotInstanceOf( TempFSFile::class, $testFile );
$this->assertTrue( $testFile->exists() );
$this->assertNotRegExpTemp( $expectedTemporaryPathRegex, $testFile->getPath() );
$this->assertEquals( $largeFileContents, file_get_contents( $testFile->getPath() ) );
$this->assertSame( $largeFileContents, file_get_contents( $testFile->getPath() ) );
};

AmazonS3LocalCache::postDownloadLogic( $file );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/MWAWSFSFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testFSFile( $methodName, $mustExist ) {
$methodExists = false;
}

$this->assertEquals( $mustExist, $methodExists,
$this->assertSame( $mustExist, $methodExists,
"Is method \"$methodName\" provided by " . get_class( $fsFile ) . "?"
);
}
Expand Down

0 comments on commit 7a495ee

Please sign in to comment.