1<?php
2
3namespace Sabre\DAV;
4
5use Sabre\HTTP;
6
7abstract class AbstractServer extends \PHPUnit_Framework_TestCase {
8
9    /**
10     * @var Sabre\HTTP\ResponseMock
11     */
12    protected $response;
13    protected $request;
14    /**
15     * @var Sabre\DAV\Server
16     */
17    protected $server;
18    protected $tempDir = SABRE_TEMPDIR;
19
20    function setUp() {
21
22        $this->response = new HTTP\ResponseMock();
23        $this->server = new Server($this->getRootNode());
24        $this->server->sapi = new HTTP\SapiMock();
25        $this->server->httpResponse = $this->response;
26        $this->server->debugExceptions = true;
27        $this->deleteTree(SABRE_TEMPDIR,false);
28        file_put_contents(SABRE_TEMPDIR . '/test.txt', 'Test contents');
29        mkdir(SABRE_TEMPDIR . '/dir');
30        file_put_contents(SABRE_TEMPDIR . '/dir/child.txt', 'Child contents');
31
32
33    }
34
35    function tearDown() {
36
37        $this->deleteTree(SABRE_TEMPDIR,false);
38
39    }
40
41    protected function getRootNode() {
42
43        return new FS\Directory(SABRE_TEMPDIR);
44
45    }
46
47    private function deleteTree($path,$deleteRoot = true) {
48
49        foreach(scandir($path) as $node) {
50
51            if ($node=='.' || $node=='.svn' || $node=='..') continue;
52            $myPath = $path.'/'. $node;
53            if (is_file($myPath)) {
54                unlink($myPath);
55            } else {
56                $this->deleteTree($myPath);
57            }
58
59        }
60        if ($deleteRoot) rmdir($path);
61
62    }
63
64}
65