+
+
+ 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.
+
-
-
- 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