|
| 1 | +<?php |
| 2 | + |
| 3 | +use Clue\React\ViewVcApi\Client; |
| 4 | +use React\EventLoop\Factory as LoopFactory; |
| 5 | +use Clue\React\Buzz\Browser; |
| 6 | +use React\Promise\PromiseInterface; |
| 7 | +use Clue\React\Block\Blocker; |
| 8 | + |
| 9 | +class FunctionalGentooClientTest extends TestCase |
| 10 | +{ |
| 11 | + private $loop; |
| 12 | + private $viewvc; |
| 13 | + private $blocker; |
| 14 | + |
| 15 | + public function setUp() |
| 16 | + { |
| 17 | + $url = 'https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/'; |
| 18 | + |
| 19 | + $this->loop = LoopFactory::create(); |
| 20 | + $this->blocker = new Blocker($this->loop); |
| 21 | + $browser = new Browser($this->loop); |
| 22 | + |
| 23 | + // check connectivity to given URL only once |
| 24 | + static $checked = null; |
| 25 | + if ($checked === null) { |
| 26 | + try { |
| 27 | + $this->waitFor($browser->head($url)); |
| 28 | + $checked = true; |
| 29 | + } catch (Exception $e) { |
| 30 | + $checked = false; |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + if (!$checked) { |
| 35 | + $this->markTestSkipped('Unable to reach Gentoo ViewVC'); |
| 36 | + } |
| 37 | + |
| 38 | + $this->viewvc = new Client($url, $browser); |
| 39 | + } |
| 40 | + |
| 41 | + public function testFetchDirectoryAttic() |
| 42 | + { |
| 43 | + $path = '/'; |
| 44 | + |
| 45 | + $promise = $this->viewvc->fetchDirectory($path, null, true); |
| 46 | + $files = $this->waitFor($promise); |
| 47 | + |
| 48 | + $this->assertEquals(array('misc/', 'src/', 'users/', 'xml/', '.frozen'), $files); |
| 49 | + } |
| 50 | + |
| 51 | + public function testFetchFileDeletedShowsLastState() |
| 52 | + { |
| 53 | + $file = '.frozen'; |
| 54 | + |
| 55 | + $promise = $this->viewvc->fetchFile($file); |
| 56 | + $contents = $this->waitFor($promise); |
| 57 | + |
| 58 | + $this->assertEquals("robbat2\n", $contents); |
| 59 | + } |
| 60 | + |
| 61 | + private function waitFor(PromiseInterface $promise) |
| 62 | + { |
| 63 | + return $this->blocker->awaitOne($promise); |
| 64 | + } |
| 65 | +} |
0 commit comments