1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: namespace Jyxo\Beholder\TestCase;
15:
16: 17: 18: 19: 20: 21: 22: 23: 24:
25: class FileSystem extends \Jyxo\Beholder\TestCase
26: {
27: 28: 29: 30: 31:
32: private $dir;
33:
34: 35: 36: 37: 38: 39:
40: public function __construct($description, $dir)
41: {
42: parent::__construct($description);
43:
44: $this->dir = (string) $dir;
45: }
46:
47: 48: 49: 50: 51:
52: public function run()
53: {
54: $random = md5(uniqid(time(), true));
55: $path = $this->dir . '/beholder-' . $random . '.txt';
56: $content = $random;
57:
58:
59: if (!file_put_contents($path, $content)) {
60: return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Write error %s', $this->dir));
61: }
62:
63:
64: $readContent = file_get_contents($path);
65: if (strlen($readContent) !== strlen($content)) {
66: return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Read error %s', $this->dir));
67: }
68:
69:
70: if (!@unlink($path)) {
71: return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Delete error %s', $this->dir));
72: }
73:
74:
75: return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS, $this->dir);
76: }
77: }
78: