Skip to content

Commit b014f81

Browse files
committed
fix touch test, set skipped for php < 5.4
1 parent 26884a6 commit b014f81

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/Brainbits/Blocking/Adapter/FilesystemAdapter.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ public function __construct($root)
4141
*/
4242
public function write(BlockInterface $block)
4343
{
44-
file_put_contents(
45-
$this->getFilename($block->getIdentifier()),
46-
serialize($block)
47-
);
44+
$filename = $this->getFilename($block->getIdentifier());
45+
46+
if (false === file_put_contents($filename, serialize($block))) {
47+
throw new \Exception('Write failed');
48+
}
4849

4950
return true;
5051
}
@@ -55,7 +56,11 @@ public function write(BlockInterface $block)
5556
public function touch(BlockInterface $block)
5657
{
5758
$filename = $this->getFilename($block->getIdentifier());
58-
touch($filename);
59+
60+
if (false === touch($filename)) {
61+
throw new \Exception('Touch failed');
62+
}
63+
5964
$updatedAt = new \DateTime();
6065
$updatedAt->setTimestamp(filemtime($filename));
6166
$block->setUpdatedAt($updatedAt);
@@ -72,7 +77,10 @@ public function remove(BlockInterface $block)
7277
return false;
7378
}
7479

75-
unlink($this->getFilename($block->getIdentifier()));
80+
$filename = $this->getFilename($block->getIdentifier());
81+
if (false === unlink($filename)) {
82+
throw new \Exception('Unlink failed');
83+
}
7684

7785
return true;
7886
}
@@ -82,7 +90,8 @@ public function remove(BlockInterface $block)
8290
*/
8391
public function exists(IdentifierInterface $identifier)
8492
{
85-
return file_exists($this->getFilename($identifier));
93+
$filename = $this->getFilename($identifier);
94+
return file_exists($filename);
8695
}
8796

8897
/**

tests/Brainbits/Block/Adapter/FilesystemAdapterTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ public function testWriteFailsOnNonWritableDirectory()
9696
$adapter->write($block);
9797
}
9898

99+
/**
100+
* @requires PHP 5.4
101+
* in PHP 5.3 and before, vfsstream had no support for touch
102+
*/
99103
public function testTouchSucceedesOnExistingFile()
100104
{
101105
$identifier = new Identifier('test', 'lock');

0 commit comments

Comments
 (0)