From 7a7c211539af8278d729eeb3612dc0548e6761c6 Mon Sep 17 00:00:00 2001 From: Ka Date: Mon, 28 Aug 2017 17:36:43 +0200 Subject: [PATCH 01/10] some better tests - We do not need hard coded cursor anymore to test getCursor - We better test getCurrentAccount, which should return a json string, we check that in testGetCurrentAccount now --- tests/DropboxHelperTest.php | 39 ++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/tests/DropboxHelperTest.php b/tests/DropboxHelperTest.php index 36fbae8..27a459c 100644 --- a/tests/DropboxHelperTest.php +++ b/tests/DropboxHelperTest.php @@ -9,9 +9,6 @@ class DropboxHelperTest extends TestCase /** @var string $sFolderPath: Path of folder on Dropbox */ protected $sFolderPath = '/PathToTest/OnYourDropbox'; - /** @var string : Cursor of the $sFodlerPath. We'll get only delta */ - protected $sCursor = 'AAHeJvp9Yce1wS7YPADH7A-----'; - /** @var DropboxHelper */ protected $dropboxHelper = null; @@ -20,7 +17,6 @@ public function setUp() $env = array_merge($_ENV, $_SERVER); $this->sFolderPath = (isset($env['DROPBOX_FOLDER_PATH'])) ? $env['DROPBOX_FOLDER_PATH'] : null; - $this->sCursor = (isset($env['DROPBOX_FOLDER_CURSOR'])) ? $env['DROPBOX_FOLDER_CURSOR'] : null; if (isset($env['DROPBOX_TOKEN'])) { $this->dropboxHelper = new DropboxHelper($env['DROPBOX_TOKEN']); @@ -34,8 +30,17 @@ public function setUp() */ public function testGetCurrentAccount() { - $result = $this->dropboxHelper->getCurrentAccount(); - self::assertNotNull($result, 'Cannot get account information.'); + $sResult = $this->dropboxHelper->getCurrentAccount(); + self::assertNotNull($sResult, 'Cannot get account information.'); + + // $sResult should be a json string, let's assert it below + + $this->assertInternalType('string', $sResult); + $aResult = json_decode($sResult, true); + $this->assertInternalType('array', $aResult); + + // You shall be informed about the account you are playing with. Maybe only when --verbose or --debug ? + echo $sResult; } public function testWriteReadDeleteFile() @@ -79,10 +84,10 @@ public function testGetCursor() return; } - $oFolder = $this->dropboxHelper->loadFolderPath($this->sFolderPath); - $sCursor = $oFolder->getCursor(); + $sCursor = $this->getCursorFromFolderPath($this->sFolderPath); self::assertNotEmpty($sCursor, 'Failed to get cursor on a loaded folder'); + $this->assertInternalType('string', $sCursor); } /** @@ -186,14 +191,10 @@ public function testListFolderFromCursor() return; } - if (empty($this->sCursor)) { - trigger_error('WARNING: Cannot run ' . __FUNCTION__ . ', Dropbox folder cursor is empty.', E_USER_WARNING); - return; - } - - $oFolder = $this->dropboxHelper->loadFolderCursor($this->sCursor); + $sCursor = $this->getCursorFromFolderPath($this->sFolderPath); + $oFolder = $this->dropboxHelper->loadFolderCursor($sCursor); - self::assertNotNull($oFolder, "Cannot load a folder from cursor: {$this->sCursor}"); + self::assertNotNull($oFolder, sprintf("Cannot load a folder from cursor: `%s`", $sCursor)); while (($aFolder = $oFolder->next())) { } @@ -207,4 +208,10 @@ public function testFolder() 'Folder is not an instance of Folder()' ); } -} \ No newline at end of file + + private function getCursorFromFolderPath(string $sFolderPath): string + { + $oFolder = $this->dropboxHelper->loadFolderPath($sFolderPath); + return $oFolder->getCursor(); + } +} From 02bb1127dd4726040793b72e1e7f6dfeb142189b Mon Sep 17 00:00:00 2001 From: Ka Date: Mon, 28 Aug 2017 17:48:06 +0200 Subject: [PATCH 02/10] should work in php 5.6 --- tests/DropboxHelperTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/DropboxHelperTest.php b/tests/DropboxHelperTest.php index 27a459c..c2addbd 100644 --- a/tests/DropboxHelperTest.php +++ b/tests/DropboxHelperTest.php @@ -209,7 +209,7 @@ public function testFolder() ); } - private function getCursorFromFolderPath(string $sFolderPath): string + private function getCursorFromFolderPath($sFolderPath) { $oFolder = $this->dropboxHelper->loadFolderPath($sFolderPath); return $oFolder->getCursor(); From 3949db1855044159e590ef99203c63b9252266b7 Mon Sep 17 00:00:00 2001 From: Ka Date: Mon, 28 Aug 2017 17:52:14 +0200 Subject: [PATCH 03/10] should pass 5.4.4 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 66ca39a..891d8c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: php php: + - '5.4.4' - '5.6' - '7.0' - '7.1' From 5d97983ff7195e2ea84fbf5fecde4d74925cc2cb Mon Sep 17 00:00:00 2001 From: Ka Date: Mon, 28 Aug 2017 17:55:53 +0200 Subject: [PATCH 04/10] php 5.4 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 891d8c4..f0e0a2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: php php: - - '5.4.4' + - '5.4' - '5.6' - '7.0' - '7.1' From b714ee4b78b492c0f3ad980fd9fa07272a08d7f2 Mon Sep 17 00:00:00 2001 From: Ka Date: Tue, 29 Aug 2017 09:59:46 +0200 Subject: [PATCH 05/10] 5.4 not OK with alorel/dropbox-v2-php dependencies (guzzle) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f0e0a2e..e581cf3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: php php: - - '5.4' + - '5.5' - '5.6' - '7.0' - '7.1' From 5c2b17ffb281d3c59df32257416caf1c94ac851f Mon Sep 17 00:00:00 2001 From: Ka Date: Tue, 29 Aug 2017 11:09:35 +0200 Subject: [PATCH 06/10] 5.5 not ok for phpunit --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e581cf3..66ca39a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - '5.5' - '5.6' - '7.0' - '7.1' From e9a3bfb0894cc22c0b75105cacb8e157c76eaa80 Mon Sep 17 00:00:00 2001 From: Ka Date: Tue, 29 Aug 2017 11:17:09 +0200 Subject: [PATCH 07/10] let's clearly specify php version minimum requirement --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index e1eb215..a7cc825 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ } ], "require": { + "php": ">=5.6", "alorel/dropbox-v2-php": "^0.4.2" }, "autoload": { From e2a7acbc4b48d1490fdb70159601d1bee6730602 Mon Sep 17 00:00:00 2001 From: Ka Date: Tue, 29 Aug 2017 12:09:11 +0200 Subject: [PATCH 08/10] After discussion, we do not require php >=5.6 --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index a7cc825..e1eb215 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,6 @@ } ], "require": { - "php": ">=5.6", "alorel/dropbox-v2-php": "^0.4.2" }, "autoload": { From 91ab6261c420660f59a22c5e99cb53d61d88b172 Mon Sep 17 00:00:00 2001 From: Ka Date: Tue, 29 Aug 2017 12:50:08 +0200 Subject: [PATCH 09/10] we test Folder::next in 3 different situations - when nothing has changed - after write - after delete --- tests/DropboxHelperTest.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/DropboxHelperTest.php b/tests/DropboxHelperTest.php index c2addbd..ed10255 100644 --- a/tests/DropboxHelperTest.php +++ b/tests/DropboxHelperTest.php @@ -196,8 +196,24 @@ public function testListFolderFromCursor() self::assertNotNull($oFolder, sprintf("Cannot load a folder from cursor: `%s`", $sCursor)); - while (($aFolder = $oFolder->next())) { - } + $oFolder = $this->dropboxHelper->loadFolderCursor($sCursor); + + # This is the last cursor so Folder::next should return null + $this->assertNull($oFolder->next()); + + # Test Folder::next after write + $sTestFilePath = $this->sFolderPath . '/DropboxHelper-test-file-' . uniqid() . '.txt'; + $sContent = "PHP Unit Test of DropboxHelper:\n" . (new \DateTime())->format(DATE_ATOM); + $bResult = $this->dropboxHelper->write($sTestFilePath, $sContent); + + $oFolder = $this->dropboxHelper->loadFolderCursor($sCursor); + $this->assertInternalType('array', $oFolder->next()); + + # Test Folder::next after delete + $bResult = $this->dropboxHelper->delete($sTestFilePath); + + $oFolder = $this->dropboxHelper->loadFolderCursor($sCursor); + $this->assertInternalType('array', $oFolder->next()); } public function testFolder() From 45f46027f0c03413430e3b6faa1fbcb957605965 Mon Sep 17 00:00:00 2001 From: Ka Date: Tue, 29 Aug 2017 13:06:59 +0200 Subject: [PATCH 10/10] due to race condition, I do not test Folder::next should return null --- tests/DropboxHelperTest.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/DropboxHelperTest.php b/tests/DropboxHelperTest.php index ed10255..107bec5 100644 --- a/tests/DropboxHelperTest.php +++ b/tests/DropboxHelperTest.php @@ -198,9 +198,6 @@ public function testListFolderFromCursor() $oFolder = $this->dropboxHelper->loadFolderCursor($sCursor); - # This is the last cursor so Folder::next should return null - $this->assertNull($oFolder->next()); - # Test Folder::next after write $sTestFilePath = $this->sFolderPath . '/DropboxHelper-test-file-' . uniqid() . '.txt'; $sContent = "PHP Unit Test of DropboxHelper:\n" . (new \DateTime())->format(DATE_ATOM); @@ -209,11 +206,21 @@ public function testListFolderFromCursor() $oFolder = $this->dropboxHelper->loadFolderCursor($sCursor); $this->assertInternalType('array', $oFolder->next()); + # Race condition: there may be other items to test + while (($aFolder = $oFolder->next())) { + $this->assertInternalType('array', $aFolder); + } + # Test Folder::next after delete $bResult = $this->dropboxHelper->delete($sTestFilePath); $oFolder = $this->dropboxHelper->loadFolderCursor($sCursor); $this->assertInternalType('array', $oFolder->next()); + + # Race condition: there may be other items to test + while (($aFolder = $oFolder->next())) { + $this->assertInternalType('array', $aFolder); + } } public function testFolder()