From ae1f7897b10b393a963c5187de007a6cd7476964 Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Sun, 28 Oct 2018 00:28:05 +0300 Subject: [PATCH 01/16] unit test added Run this script for testing FileLock module. Algorithm is follow: 1) script created file in current folder 2) trying to lock file 3) checking that file is locked 4) trying to read 5) checking that file is locked 6) trying to write 7) checking that file is locked 8) try to unlock file 9) checking that file is not locked 10) trying to read 11) checking that file is not locked 12) trying to write 13) checking that file is not locked echo 'done' and exit --- unit-test.php | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 unit-test.php diff --git a/unit-test.php b/unit-test.php new file mode 100644 index 0000000..0da6530 --- /dev/null +++ b/unit-test.php @@ -0,0 +1,107 @@ +'; + +// create lock object +$lock = new \Dorantor\FileLock($fname); + +echo 'try to lock file
'; +if (!$lock->acquire()) { //fopen('a') + // failed with lock + echo 'ERROR[1]: file "'.$fname.'" not locked!'; + exit(); +} else { + echo 'OK[0]: file locked!
'; +} + +//try to read write +$handle = fopen($fname, 'r+'); + +if ($handle === false) { + echo 'ERROR[2]: file "'.$fname.'" can not be opened!'; + exit(); +} else { + echo 'try to read
'; + if (($buffer = fgets($handle, 4096)) !== false) { + echo 'ERROR[3]: file "'.$fname.'" not locked! File content: '.$buffer; + exit(); + } else { + echo 'OK[1]: file locked! Reading fail.
'; + } + + if (!feof($handle)) { + echo 'ERROR[4]: fgets() fail
'; + $lock->release(); //unlock file + exit(); + } + + echo 'try to write
'; + $fwrite_res = fwrite($handle, 'test'); + if ($fwrite === false) { + echo 'OK[2]: file locked! Writing fail.
'; + } else { + if ($fwrite_res != 0) { + echo 'ERROR[5]: writed '.$fwrite_res.' bytes.
'; + } else { + echo 'OK[3]: file locked! Writing fail.
'; + } + } + fclose($handle); +} + +echo 'try to unlock file
'; +if (!$lock->release()) { //unlock file -> fclose() + // failed with lock + echo 'ERROR[6]: file "'.$fname.'" still locked!'; + exit(); +} else { + echo 'OK[4]: file unlocked!
'; +} + + +$handle = fopen($fname, 'r+'); + +if ($handle === false) { + echo 'ERROR[7]: file "'.$fname.'" can not be opened!'; + exit(); +} else { + + echo 'try to read
'; + if (($buffer = fgets($handle, 4096)) !== false) { + echo 'OK[5]: file "'.$fname.'" not locked! File content: '.$buffer.'
'; + } else { + echo 'ERROR[8]: file locked! Reading fail.
'; + exit(); + } + + if (!feof($handle)) { + echo 'ERROR[9]: fgets() fail
'; + exit(); + } + + echo 'try to write
'; + $fwrite_res = fwrite($handle, 'test'); + if ($fwrite === false) { + echo 'ERROR[10]: file locked! Writing fail.
'; + } else { + if ($fwrite_res != 0) { + echo 'OK[6]: writed '.$fwrite_res.' bytes.
'; + } else { + echo 'ERROR[11]: file locked! Writing fail.
'; + } + } + + fclose($handle); + + echo 'done'; +} +?> \ No newline at end of file From 14cf835a9edf264b798482b20fcb366420f5ba37 Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Wed, 31 Oct 2018 09:59:51 +0300 Subject: [PATCH 02/16] Create 1.txt --- tests/1.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/1.txt diff --git a/tests/1.txt b/tests/1.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/1.txt @@ -0,0 +1 @@ +1 From ae58cdc693204532cae65c5ed15be7849fc1cd8e Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Wed, 31 Oct 2018 10:01:51 +0300 Subject: [PATCH 03/16] Add files via upload --- tests/FileLockTest.php | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/FileLockTest.php diff --git a/tests/FileLockTest.php b/tests/FileLockTest.php new file mode 100644 index 0000000..41a9765 --- /dev/null +++ b/tests/FileLockTest.php @@ -0,0 +1,50 @@ +assertEquals(true, $lock->acquire(),'ERROR[1]: Result of function acquire() not correct!'. PHP_EOL); + + //try to read write + $handle = fopen($fname, 'r+'); + $this->assertTrue(($handle != false),'ERROR[2]: file "'.$fname.'" can not be opened!'. PHP_EOL); + + //try to read + $buffer = fgets($handle, 4096); + $this->assertFalse($buffer,'ERROR[3]: file "'.$fname.'" not locked! File content: '.$buffer. PHP_EOL); + + //try to write + $fwrite_res = fwrite($handle, 'test'); + $this->assertEquals(0, $fwrite_res,'ERROR[5]: writed '.$fwrite_res.' bytes.'. PHP_EOL); + + fclose($handle); + + //try to unlock file + $this->assertEquals(true, $lock->release(),'ERROR[6]: Result of function release() not correct!'. PHP_EOL); + + $handle = fopen($fname, 'r+'); + + //try to write + $fwrite_res = (fwrite($handle, 'test') != 0); + $this->assertTrue($fwrite_res,'ERROR[7]: File "'.$fname.'" locked! Writing fail.'. PHP_EOL); + + fclose($handle); + + } +} \ No newline at end of file From a6e48e46957d98fe07a33d83fbf1c6009a468bac Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Wed, 31 Oct 2018 10:02:13 +0300 Subject: [PATCH 04/16] Add files via upload --- tests/lock-test.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/lock-test.txt diff --git a/tests/lock-test.txt b/tests/lock-test.txt new file mode 100644 index 0000000..495a59c --- /dev/null +++ b/tests/lock-test.txt @@ -0,0 +1 @@ +test0.2018 10:00:26 \ No newline at end of file From 635e58cc477fbbe1a2cf31dcd0ff4d321d1844be Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Wed, 31 Oct 2018 10:02:39 +0300 Subject: [PATCH 05/16] Delete 1.txt --- tests/1.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tests/1.txt diff --git a/tests/1.txt b/tests/1.txt deleted file mode 100644 index d00491f..0000000 --- a/tests/1.txt +++ /dev/null @@ -1 +0,0 @@ -1 From 6d7feec5571d11059a76110d28931a12c1d695bb Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Thu, 1 Nov 2018 17:22:53 +0300 Subject: [PATCH 06/16] Add files via upload update unit test --- tests/FileLockTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/FileLockTest.php b/tests/FileLockTest.php index 41a9765..13b7417 100644 --- a/tests/FileLockTest.php +++ b/tests/FileLockTest.php @@ -1,5 +1,7 @@ Date: Thu, 1 Nov 2018 17:33:02 +0300 Subject: [PATCH 07/16] Add files via upload --- travis.yml | 990 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 990 insertions(+) create mode 100644 travis.yml diff --git a/travis.yml b/travis.yml new file mode 100644 index 0000000..3ac5714 --- /dev/null +++ b/travis.yml @@ -0,0 +1,990 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + filelock/.travis.yml at master · dorantor/filelock + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content +
+ + + + + + + + + + + + +
+ +
+ +
+ + +
+ + + +
+
+
+ + + + + + + + +
+
+ +
    +
  • +
    + +
    + + + + Watch + + + +
    + Notifications +
    +
    + + + + + +
    +
    +
    + +
    +
  • + +
  • + +
    +
    + + + +
    +
    + + + +
    + +
  • + +
  • +
    + +
    + +
  • +
+ +

+ + /filelock + +

+ +
+ + + + +
+ +
+
+ + + + + Permalink + + + + + +
+ +
+ + +
+ +
+
+ + Switch branches/tags +
+ +
+
+ +
+
+ +
+
+ + + +
+ + +
Nothing to show
+
+ +
+
+
+ +
+ + Find file + + + Copy path + +
+ +
+ + + +
+ + + 20dd541 + + Oct 29, 2018 + + + +
+ +
+ + + 1 contributor + + +
+ +

Users who have contributed to this file

+
+ + + +
+
+ +
+
+ + + +
+
+
+ +
+ Raw + Blame + History +
+ + + + + +
+ +
+
+ +
+ +
+ 32 lines (24 sloc) + + 346 Bytes +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sudo: false
+
dist: trusty
+
language: php
+
php:
- nightly
- 7.2
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
+
matrix:
allow_failures:
- php: nightly
include:
- php: "5.3"
dist: precise
+
before_script:
- composer install --no-interaction
+
script:
- composer cover
- composer check-style
+
after_script:
- composer coveralls
+ + + +
+ +
+ + + +
+ + +
+ + +
+
+ + +
+ +
+ +
+
+ +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + +
+ + You signed in with another tab or window. Reload to refresh your session. + You signed out in another tab or window. Reload to refresh your session. +
+ + + + + + +
+ Press h to open a hovercard with more details. +
+ + + + + From 1b90ba9803501d71a0270c093e5e2a4402469160 Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Thu, 1 Nov 2018 17:36:24 +0300 Subject: [PATCH 08/16] Add files via upload From 0e7b8d7d52358e480217cfb8206fd7d958c48397 Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Thu, 1 Nov 2018 17:54:56 +0300 Subject: [PATCH 09/16] Delete travis.yml --- travis.yml | 990 ----------------------------------------------------- 1 file changed, 990 deletions(-) delete mode 100644 travis.yml diff --git a/travis.yml b/travis.yml deleted file mode 100644 index 3ac5714..0000000 --- a/travis.yml +++ /dev/null @@ -1,990 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - filelock/.travis.yml at master · dorantor/filelock - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Skip to content -
- - - - - - - - - - - - -
- -
- -
- - -
- - - -
-
-
- - - - - - - - -
-
- -
    -
  • -
    - -
    - - - - Watch - - - -
    - Notifications -
    -
    - - - - - -
    -
    -
    - -
    -
  • - -
  • - -
    -
    - - - -
    -
    - - - -
    - -
  • - -
  • -
    - -
    - -
  • -
- -

- - /filelock - -

- -
- - - - -
- -
-
- - - - - Permalink - - - - - -
- -
- - -
- -
-
- - Switch branches/tags -
- -
-
- -
-
- -
-
- - - -
- - -
Nothing to show
-
- -
-
-
- -
- - Find file - - - Copy path - -
- -
- - - -
- - - 20dd541 - - Oct 29, 2018 - - - -
- -
- - - 1 contributor - - -
- -

Users who have contributed to this file

-
- - - -
-
- -
-
- - - -
-
-
- -
- Raw - Blame - History -
- - - - - -
- -
-
- -
- -
- 32 lines (24 sloc) - - 346 Bytes -
-
- - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sudo: false
-
dist: trusty
-
language: php
-
php:
- nightly
- 7.2
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
-
matrix:
allow_failures:
- php: nightly
include:
- php: "5.3"
dist: precise
-
before_script:
- composer install --no-interaction
-
script:
- composer cover
- composer check-style
-
after_script:
- composer coveralls
- - - -
- -
- - - -
- - -
- - -
-
- - -
- -
- -
-
- -
- - - - - - -
- - - You can’t perform that action at this time. -
- - - - - - - - - -
- - You signed in with another tab or window. Reload to refresh your session. - You signed out in another tab or window. Reload to refresh your session. -
- - - - - - -
- Press h to open a hovercard with more details. -
- - - - - From 206436d610d96a6d812086bd508935175cd0baec Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Thu, 1 Nov 2018 17:55:55 +0300 Subject: [PATCH 10/16] Create .travis.yml --- .travis.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..53235e5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +sudo: false + +dist: trusty + +language: php + +php: + - nightly + - 7.2 + - 7.1 + - 7.0 + - 5.6 + - 5.5 + - 5.4 + +matrix: + allow_failures: + - php: nightly + include: + - php: "5.3" + dist: precise + +before_script: + - composer install --no-interaction + +script: + - composer cover + - composer check-style + +after_script: + - composer coveralls From a8cb31164fa8cf1264fd64542b844fa46ba9119f Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Thu, 1 Nov 2018 18:03:39 +0300 Subject: [PATCH 11/16] Update composer.json --- composer.json | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c00ca5a..94423b4 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,21 @@ "require": { "php": "^5.3|^7.0" }, + "require-dev": { + "phpunit/phpunit": "^4.8 | ^6.5", + "satooshi/php-coveralls": ">=0.7.1 <2.0", + "squizlabs/php_codesniffer": "^2.3" + }, "autoload": { "psr-4": { - "Dorantor\\" : "src" + "Dorantor\\" : ["src/", "tests/"] } + }, + "scripts": { + "test": "./vendor/bin/phpunit -c ./tests/phpunit.xml", + "cover": "./vendor/bin/phpunit -c ./tests/phpunit.xml --coverage-clover build/logs/clover.xml", + "coveralls": "coveralls -v", + "check-style": "./vendor/bin/phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src", + "fix-style": "./vendor/bin/phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src" } -} \ No newline at end of file +} From 9905a4eaab70ab59c839a1835ab665cfcfab4dea Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Thu, 1 Nov 2018 18:05:19 +0300 Subject: [PATCH 12/16] Create phpunit.xml --- tests/phpunit.xml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/phpunit.xml diff --git a/tests/phpunit.xml b/tests/phpunit.xml new file mode 100644 index 0000000..3031c23 --- /dev/null +++ b/tests/phpunit.xml @@ -0,0 +1,21 @@ + + + + + + ./ + + + + + + ../src + + + From a7c92793ec9b61b0e51e80fb213b59ef0a3a796e Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Thu, 1 Nov 2018 18:16:38 +0300 Subject: [PATCH 13/16] Add files via upload --- tests/FileLockTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/FileLockTest.php b/tests/FileLockTest.php index 13b7417..9ac2553 100644 --- a/tests/FileLockTest.php +++ b/tests/FileLockTest.php @@ -28,8 +28,8 @@ public function testCanBeLocked() { $this->assertTrue(($handle != false),'ERROR[2]: file "'.$fname.'" can not be opened!'. PHP_EOL); //try to read - $buffer = fgets($handle, 4096); - $this->assertFalse($buffer,'ERROR[3]: file "'.$fname.'" not locked! File content: '.$buffer. PHP_EOL); + //$buffer = fgets($handle, 4096); + //$this->assertFalse($buffer,'ERROR[3]: file "'.$fname.'" not locked! File content: '.$buffer. PHP_EOL); //try to write $fwrite_res = fwrite($handle, 'test'); From d8a03e2a98c36f8696a89f05395a16ef3da21838 Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Thu, 1 Nov 2018 19:58:32 +0300 Subject: [PATCH 14/16] Add files via upload --- tests/FileLockTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/FileLockTest.php b/tests/FileLockTest.php index 9ac2553..563c169 100644 --- a/tests/FileLockTest.php +++ b/tests/FileLockTest.php @@ -22,7 +22,7 @@ public function testCanBeLocked() { //try to lock file $this->assertEquals(true, $lock->acquire(),'ERROR[1]: Result of function acquire() not correct!'. PHP_EOL); - +/* //try to read write $handle = fopen($fname, 'r+'); $this->assertTrue(($handle != false),'ERROR[2]: file "'.$fname.'" can not be opened!'. PHP_EOL); @@ -36,10 +36,10 @@ public function testCanBeLocked() { $this->assertEquals(0, $fwrite_res,'ERROR[5]: writed '.$fwrite_res.' bytes.'. PHP_EOL); fclose($handle); - +*/ //try to unlock file $this->assertEquals(true, $lock->release(),'ERROR[6]: Result of function release() not correct!'. PHP_EOL); - +/* $handle = fopen($fname, 'r+'); //try to write @@ -47,6 +47,6 @@ public function testCanBeLocked() { $this->assertTrue($fwrite_res,'ERROR[7]: File "'.$fname.'" locked! Writing fail.'. PHP_EOL); fclose($handle); - +*/ } } \ No newline at end of file From dab45d2b0fd0b4f4f54ff8ed726e8ef174b25624 Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Sun, 4 Nov 2018 12:10:48 +0300 Subject: [PATCH 15/16] Add files via upload --- tests/FileLockTest.php | 92 +++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 38 deletions(-) diff --git a/tests/FileLockTest.php b/tests/FileLockTest.php index 563c169..8b9ff52 100644 --- a/tests/FileLockTest.php +++ b/tests/FileLockTest.php @@ -2,51 +2,67 @@ use PHPUnit\Framework\TestCase; -$fname = 'tests/lock-test.txt'; +class FileLockTest extends TestCase { -//create file -$handle = fopen($fname, 'w') or die('ERROR[0]: Unable to open/create file "'.$fname.'"!'); -$txt = date('d.m.Y H:i:s'); -fwrite($handle, $txt); -fclose($handle); -echo PHP_EOL .'Test file "'.$fname.'" created ['.date('d.m.Y H:i:s').']. FileSize: '.filesize($fname).' bytes.'. PHP_EOL . PHP_EOL; + private $fname; + + protected function setUp() + { + parent::setUp(); + $this->fname = 'tests/lock-test.txt'; + } + public function testInvalidLockId() + { + //try to catch exception from Class if the file name is incorrect + $f = new \Dorantor\FileLock(''); + self::assertFalse($f->acquire()); + } + + public function testLock() + { + $lock = new \Dorantor\FileLock($this->fname); -class FileLockTest extends TestCase { + //try to lock file + self::assertTrue($lock->acquire(),'ERROR[0]: Result of function acquire() not correct!'. PHP_EOL); + return $lock; + + } - public function testCanBeLocked() { + /** + * @depends testLock + * @param Dorantor\FileLock $lock + */ + public function testLockLockedFile() + { + //try to lock locked file - wait false result + $f = new \Dorantor\FileLock($this->fname); + self::assertFalse($f->acquire()); + } - global $fname; - //create lock object - $lock = new \Dorantor\FileLock($fname); - - //try to lock file - $this->assertEquals(true, $lock->acquire(),'ERROR[1]: Result of function acquire() not correct!'. PHP_EOL); -/* - //try to read write - $handle = fopen($fname, 'r+'); - $this->assertTrue(($handle != false),'ERROR[2]: file "'.$fname.'" can not be opened!'. PHP_EOL); - - //try to read - //$buffer = fgets($handle, 4096); - //$this->assertFalse($buffer,'ERROR[3]: file "'.$fname.'" not locked! File content: '.$buffer. PHP_EOL); - - //try to write - $fwrite_res = fwrite($handle, 'test'); - $this->assertEquals(0, $fwrite_res,'ERROR[5]: writed '.$fwrite_res.' bytes.'. PHP_EOL); - - fclose($handle); -*/ + /** + * @depends testLock + * @param Dorantor\FileLock $lock + */ + public function testUnlock(Dorantor\FileLock $lock) + { //try to unlock file - $this->assertEquals(true, $lock->release(),'ERROR[6]: Result of function release() not correct!'. PHP_EOL); -/* - $handle = fopen($fname, 'r+'); + self::assertTrue($lock->release(),'ERROR[2]: Result of function release() not correct!'. PHP_EOL); + } + + public function testFileUnLocked() + { + //try to read/write file after UnLocking + $handle = fopen($this->fname, 'a+'); + self::assertTrue(($handle !== false),'ERROR[3]: file "'.$this->fname.'" can not be opened!'. PHP_EOL); //try to write - $fwrite_res = (fwrite($handle, 'test') != 0); - $this->assertTrue($fwrite_res,'ERROR[7]: File "'.$fname.'" locked! Writing fail.'. PHP_EOL); - - fclose($handle); -*/ + $fwrite_res = fwrite($handle, ''.date('d.m.Y H:i:s'). PHP_EOL); + self::assertNotEquals(0, $fwrite_res,'ERROR[4]: can not write to file '.$this->fname.''. PHP_EOL); + + fclose($handle); + + $read_res = file_get_contents($this->fname, FALSE, NULL, 0, 1024); + self::assertNotEquals(0, strlen($read_res),'ERROR[5]: file still locked'. PHP_EOL); } } \ No newline at end of file From 0d7cb300b3ec543234256530196677942e8efaae Mon Sep 17 00:00:00 2001 From: ivancoff <44445575+ivancoff@users.noreply.github.com> Date: Wed, 21 Nov 2018 21:50:43 +0300 Subject: [PATCH 16/16] Delete unit-test.php --- unit-test.php | 107 -------------------------------------------------- 1 file changed, 107 deletions(-) delete mode 100644 unit-test.php diff --git a/unit-test.php b/unit-test.php deleted file mode 100644 index 0da6530..0000000 --- a/unit-test.php +++ /dev/null @@ -1,107 +0,0 @@ -'; - -// create lock object -$lock = new \Dorantor\FileLock($fname); - -echo 'try to lock file
'; -if (!$lock->acquire()) { //fopen('a') - // failed with lock - echo 'ERROR[1]: file "'.$fname.'" not locked!'; - exit(); -} else { - echo 'OK[0]: file locked!
'; -} - -//try to read write -$handle = fopen($fname, 'r+'); - -if ($handle === false) { - echo 'ERROR[2]: file "'.$fname.'" can not be opened!'; - exit(); -} else { - echo 'try to read
'; - if (($buffer = fgets($handle, 4096)) !== false) { - echo 'ERROR[3]: file "'.$fname.'" not locked! File content: '.$buffer; - exit(); - } else { - echo 'OK[1]: file locked! Reading fail.
'; - } - - if (!feof($handle)) { - echo 'ERROR[4]: fgets() fail
'; - $lock->release(); //unlock file - exit(); - } - - echo 'try to write
'; - $fwrite_res = fwrite($handle, 'test'); - if ($fwrite === false) { - echo 'OK[2]: file locked! Writing fail.
'; - } else { - if ($fwrite_res != 0) { - echo 'ERROR[5]: writed '.$fwrite_res.' bytes.
'; - } else { - echo 'OK[3]: file locked! Writing fail.
'; - } - } - fclose($handle); -} - -echo 'try to unlock file
'; -if (!$lock->release()) { //unlock file -> fclose() - // failed with lock - echo 'ERROR[6]: file "'.$fname.'" still locked!'; - exit(); -} else { - echo 'OK[4]: file unlocked!
'; -} - - -$handle = fopen($fname, 'r+'); - -if ($handle === false) { - echo 'ERROR[7]: file "'.$fname.'" can not be opened!'; - exit(); -} else { - - echo 'try to read
'; - if (($buffer = fgets($handle, 4096)) !== false) { - echo 'OK[5]: file "'.$fname.'" not locked! File content: '.$buffer.'
'; - } else { - echo 'ERROR[8]: file locked! Reading fail.
'; - exit(); - } - - if (!feof($handle)) { - echo 'ERROR[9]: fgets() fail
'; - exit(); - } - - echo 'try to write
'; - $fwrite_res = fwrite($handle, 'test'); - if ($fwrite === false) { - echo 'ERROR[10]: file locked! Writing fail.
'; - } else { - if ($fwrite_res != 0) { - echo 'OK[6]: writed '.$fwrite_res.' bytes.
'; - } else { - echo 'ERROR[11]: file locked! Writing fail.
'; - } - } - - fclose($handle); - - echo 'done'; -} -?> \ No newline at end of file