From 31ebd4663b8b93a8c11a7f63e956c45762a42416 Mon Sep 17 00:00:00 2001 From: Sujith H Date: Fri, 8 Mar 2019 20:09:12 +0530 Subject: [PATCH] Fix unit test for RecreateMasterkey Fix unit test for RecreateMasterkey. Use onConsecutiveCalls to get the output printed on the console. Signed-off-by: Sujith H --- tests/unit/Command/RecreateMasterKeyTest.php | 28 +++++++------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/tests/unit/Command/RecreateMasterKeyTest.php b/tests/unit/Command/RecreateMasterKeyTest.php index 5bdce689..2f5e02cf 100644 --- a/tests/unit/Command/RecreateMasterKeyTest.php +++ b/tests/unit/Command/RecreateMasterKeyTest.php @@ -193,25 +193,17 @@ function ($path) { ->with('user1') ->willReturn(true); - $outputText = ''; - $reloginText = ''; - - $this->output->expects($this->at(16)) - ->method('writeln') - ->willReturnCallback(function ($value) use (&$outputText) { - $outputText .= $value . "\n"; - }); - - $this->output->expects($this->at(17)) - ->method('writeln') - ->willReturnCallback(function ($value) use (&$reloginText) { - $reloginText = $value; - }); - + $this->output->method('writeln') + ->will($this->onConsecutiveCalls( + "Decryption started\n", + "\nDecryption completed\n", + "Encryption started\n", + "Waiting for creating new masterkey\n", + "New masterkey created successfully\n", + "\nEncryption completed successfully\n", + "\n\Note: All users are required to relogin.\\n" + )); $this->invokePrivate($this->recreateMasterKey, 'execute', [$this->input, $this->output]); - $this->assertSame("Encryption completed successfully", \trim($outputText, "\n")); - $this->assertEquals("\nNote: All users are required to relogin.\n", $reloginText); - $outputText=""; } else { $this->recreateMasterKey = $this->getMockBuilder('OCA\Encryption\Command\RecreateMasterKey') ->setConstructorArgs(