Skip to content
This repository has been archived by the owner on Apr 17, 2021. It is now read-only.
/ lock Public archive

Commit

Permalink
Don't truncate lockfiles, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BenConstable committed Jan 7, 2015
1 parent 5bd0d9e commit 40b86cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/BenConstable/Lock/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __destruct()
public function acquire()
{
if (!$this->locked) {
$this->fp = @fopen($this->filePath, 'w');
$this->fp = @fopen($this->filePath, 'a');

if (!$this->fp || !flock($this->fp, LOCK_EX | LOCK_NB)) {
throw new LockException("Could not get lock on {$this->filePath}");
Expand Down
21 changes: 12 additions & 9 deletions tests/spec/BenConstable/Lock/LockSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ function it_acquires_a_lock_on_an_existing_file()
$this->release();
}

function it_acquires_a_lock_on_a_non_existing_file()
{
$this->beConstructedWith($this->lockTestPath . '/test-lock-not-exists.txt');

$this->acquire()
->shouldBe($this);

$this->release();

unlink($this->lockTestPath . '/test-lock-not-exists.txt');
}

function it_returns_the_same_lock_when_locking_more_than_once()
{
$this->beConstructedWith($this->lockTestPath . '/test-lock.txt');
Expand All @@ -52,15 +64,6 @@ function it_fails_to_aquire_a_lock_on_an_already_locked_file()
->during('acquire');
}

function it_fails_to_acquire_a_lock_on_a_non_existing_file()
{
$this->beConstructedWith($this->lockTestPath . '/test-lock-not-exists.txt');

$this
->shouldThrow('BenConstable\Lock\Exception\LockException')
->during('acquire');
}

function it_releases_a_lock_so_it_can_be_locked_by_something_else()
{
$this->beConstructedWith($this->lockTestPath . '/test-lock.txt');
Expand Down

0 comments on commit 40b86cf

Please sign in to comment.