Yaffs site version 1.1
[yaffs-website] / vendor / psy / psysh / test / Psy / Test / Readline / GNUReadlineTest.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2017 Justin Hileman
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Psy\Test\Readline;
13
14 use Psy\Readline\GNUReadline;
15
16 class GNUReadlineTest extends \PHPUnit_Framework_TestCase
17 {
18     private $historyFile;
19
20     public function setUp()
21     {
22         if (!GNUReadline::isSupported()) {
23             $this->markTestSkipped('GNUReadline not enabled');
24         }
25
26         $this->historyFile = tempnam(sys_get_temp_dir(), 'psysh_test_history');
27         file_put_contents($this->historyFile, "_HiStOrY_V2_\n");
28     }
29
30     public function testHistory()
31     {
32         $readline = new GNUReadline($this->historyFile);
33         $this->assertEmpty($readline->listHistory());
34         $readline->addHistory('foo');
35         $this->assertEquals(array('foo'), $readline->listHistory());
36         $readline->addHistory('bar');
37         $this->assertEquals(array('foo', 'bar'), $readline->listHistory());
38         $readline->addHistory('baz');
39         $this->assertEquals(array('foo', 'bar', 'baz'), $readline->listHistory());
40         $readline->clearHistory();
41         $this->assertEmpty($readline->listHistory());
42     }
43
44     /**
45      * @depends testHistory
46      */
47     public function testHistorySize()
48     {
49         $readline = new GNUReadline($this->historyFile, 2);
50         $this->assertEmpty($readline->listHistory());
51         $readline->addHistory('foo');
52         $readline->addHistory('bar');
53         $this->assertEquals(array('foo', 'bar'), $readline->listHistory());
54         $readline->addHistory('baz');
55         $this->assertEquals(array('bar', 'baz'), $readline->listHistory());
56         $readline->addHistory('w00t');
57         $this->assertEquals(array('baz', 'w00t'), $readline->listHistory());
58         $readline->clearHistory();
59         $this->assertEmpty($readline->listHistory());
60     }
61
62     /**
63      * @depends testHistory
64      */
65     public function testHistoryEraseDups()
66     {
67         $readline = new GNUReadline($this->historyFile, 0, true);
68         $this->assertEmpty($readline->listHistory());
69         $readline->addHistory('foo');
70         $readline->addHistory('bar');
71         $readline->addHistory('foo');
72         $this->assertEquals(array('bar', 'foo'), $readline->listHistory());
73         $readline->addHistory('baz');
74         $readline->addHistory('w00t');
75         $readline->addHistory('baz');
76         $this->assertEquals(array('bar', 'foo', 'w00t', 'baz'), $readline->listHistory());
77         $readline->clearHistory();
78         $this->assertEmpty($readline->listHistory());
79     }
80 }