From d1c6e82d7752e7430ca2ccb79dd608233b91a6d1 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 21 Jan 2022 14:09:45 +0100 Subject: test: improve notify tests for smb Signed-off-by: Robin Appelman --- apps/files_external/tests/Storage/SmbTest.php | 29 ++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'apps') diff --git a/apps/files_external/tests/Storage/SmbTest.php b/apps/files_external/tests/Storage/SmbTest.php index 30040e499c8..6d21f696683 100644 --- a/apps/files_external/tests/Storage/SmbTest.php +++ b/apps/files_external/tests/Storage/SmbTest.php @@ -105,6 +105,7 @@ class SmbTest extends \Test\Files\Storage\Storage { $this->instance->unlink('/renamed.txt'); sleep(1); //time for all changes to be processed + /** @var IChange[] $changes */ $changes = []; $count = 0; // wait up to 10 seconds for incoming changes @@ -115,14 +116,23 @@ class SmbTest extends \Test\Files\Storage\Storage { } $notifyHandler->stop(); - $expected = [ - new Change(IChange::ADDED, 'newfile.txt'), - new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'), - new Change(IChange::REMOVED, 'renamed.txt') - ]; + // depending on the server environment, the initial create might be detected as a change instead + if ($changes[0]->getType() === IChange::MODIFIED) { + $expected = [ + new Change(IChange::MODIFIED, 'newfile.txt'), + new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'), + new Change(IChange::REMOVED, 'renamed.txt') + ]; + } else { + $expected = [ + new Change(IChange::ADDED, 'newfile.txt'), + new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'), + new Change(IChange::REMOVED, 'renamed.txt') + ]; + } foreach ($expected as $expectedChange) { - $this->assertTrue(in_array($expectedChange, $changes), 'Actual changes are:' . PHP_EOL . print_r($changes, true) . PHP_EOL . 'Expected to find: ' . PHP_EOL . print_r($expectedChange, true)); + $this->assertTrue(in_array($expectedChange, $changes), "Expected changes are:\n" . print_r($expected, true) . PHP_EOL . 'Expected to find: ' . PHP_EOL . print_r($expectedChange, true) . "\nGot:\n" . print_r($changes, true)); } } @@ -141,7 +151,12 @@ class SmbTest extends \Test\Files\Storage\Storage { return false;//stop listening }); - $this->assertEquals(new Change(IChange::ADDED, 'newfile.txt'), $result); + // depending on the server environment, the initial create might be detected as a change instead + if ($result->getType() === IChange::ADDED) { + $this->assertEquals(new Change(IChange::ADDED, 'newfile.txt'), $result); + } else { + $this->assertEquals(new Change(IChange::MODIFIED, 'newfile.txt'), $result); + } } public function testRenameRoot() { -- cgit v1.2.3