Skip to content

Commit 4eafa0b

Browse files
test(integrity): fix file_get_contents mock expectations for mimetype test
Signed-off-by: Josh <[email protected]>
1 parent 05f0f17 commit 4eafa0b

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

tests/lib/IntegrityCheck/CheckerTest.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ protected function setUp(): void {
4444
$this->fixtureDir = __DIR__ . '/../../data/integritycheck/';
4545

4646
/*
47-
* Dependencies
47+
* Dependencies
4848
*/
49-
49+
5050
// Stubs (Pre-defined Answers + Matching Criteria)
5151
$this->serverVersionStub = $this->createStub(ServerVersion::class);
5252
$this->environmentHelperStub = $this->createStub(EnvironmentHelper::class);
@@ -67,7 +67,7 @@ protected function setUp(): void {
6767
/*
6868
* System under test
6969
*/
70-
70+
7171
$this->checker = new Checker(
7272
$this->serverVersionStub,
7373
$this->environmentHelperStub,
@@ -99,8 +99,8 @@ private function createRsaAndX509(string $certFile = 'SomeApp.crt', string $keyF
9999
$rsa = new RSA();
100100
$rsa->loadKey($rsaPrivateKey);
101101
$x509 = new X509();
102-
$x509->loadX509($keyBundle);
103-
return [$x509, $rsa];
102+
$x509->loadX509($keyBundle);
103+
return [$x509, $rsa];
104104
}
105105

106106
private function expectSignaturePutContents(string $targetPath, string $expectedJson): void {
@@ -114,7 +114,7 @@ private function expectSignaturePutContents(string $targetPath, string $expected
114114
})
115115
);
116116
}
117-
117+
118118
/*
119119
* Tests
120120
*/
@@ -573,14 +573,20 @@ public function testVerifyCoreSignatureWithModifiedMimetypelistSignatureData():
573573

574574
$this->environmentHelperStub->method('getServerRoot')
575575
->willReturn(\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified');
576-
577576
$signatureDataFile = file_get_contents(__DIR__ . '/../../data/integritycheck/mimetypeListModified/core/signature.json');
578-
$this->fileAccessHelperMock->expects($this->exactly(2))
577+
$map = [
578+
\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/core/signature.json' => $signatureDataFile,
579+
\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/resources/codesigning/root.crt' => file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt'),
580+
\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/core/js/mimetypelist.js' => file_get_contents(__DIR__ . '/../../data/integritycheck/mimetypeListModified/core/js/mimetypelist.js'),
581+
];
582+
$this->fileAccessHelperMock->expects($this->exactly(3))
579583
->method('file_get_contents')
580-
->willReturnMap([
581-
[\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/core/signature.json', $signatureDataFile],
582-
[\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
583-
]);
584+
->willReturnCallback(function ($path) use ($map) {
585+
if (array_key_exists($path, $map)) {
586+
return $map[$path];
587+
}
588+
throw new \RuntimeException('Unexpected file_get_contents call for: ' . $path);
589+
});
584590

585591
$this->assertSame([], $this->checker->verifyCoreSignature());
586592
}
@@ -837,7 +843,7 @@ public function testIsCodeCheckEnforced($channel, $isCodeSigningEnforced): void
837843
$this->configStub->method('getSystemValueBool')
838844
->with('integrity.check.disabled', false)
839845
->willReturn(false);
840-
846+
841847
$this->assertSame($isCodeSigningEnforced, $this->checker->isCodeCheckEnforced());
842848
}
843849

0 commit comments

Comments
 (0)