Yaffs site version 1.1
[yaffs-website] / vendor / psy / psysh / test / Psy / Test / Readline / TransientTest.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\Transient;
15
16 class TransientTest extends \PHPUnit_Framework_TestCase
17 {
18     public function testHistory()
19     {
20         $readline = new Transient();
21         $this->assertEmpty($readline->listHistory());
22         $readline->addHistory('foo');
23         $this->assertEquals(array('foo'), $readline->listHistory());
24         $readline->addHistory('bar');
25         $this->assertEquals(array('foo', 'bar'), $readline->listHistory());
26         $readline->addHistory('baz');
27         $this->assertEquals(array('foo', 'bar', 'baz'), $readline->listHistory());
28         $readline->clearHistory();
29         $this->assertEmpty($readline->listHistory());
30     }
31
32     /**
33      * @depends testHistory
34      */
35     public function testHistorySize()
36     {
37         $readline = new Transient(null, 2);
38         $this->assertEmpty($readline->listHistory());
39         $readline->addHistory('foo');
40         $readline->addHistory('bar');
41         $this->assertEquals(array('foo', 'bar'), $readline->listHistory());
42         $readline->addHistory('baz');
43         $this->assertEquals(array('bar', 'baz'), $readline->listHistory());
44         $readline->addHistory('w00t');
45         $this->assertEquals(array('baz', 'w00t'), $readline->listHistory());
46         $readline->clearHistory();
47         $this->assertEmpty($readline->listHistory());
48     }
49
50     /**
51      * @depends testHistory
52      */
53     public function testHistoryEraseDups()
54     {
55         $readline = new Transient(null, 0, true);
56         $this->assertEmpty($readline->listHistory());
57         $readline->addHistory('foo');
58         $readline->addHistory('bar');
59         $readline->addHistory('foo');
60         $this->assertEquals(array('bar', 'foo'), $readline->listHistory());
61         $readline->addHistory('baz');
62         $readline->addHistory('w00t');
63         $readline->addHistory('baz');
64         $this->assertEquals(array('bar', 'foo', 'w00t', 'baz'), $readline->listHistory());
65         $readline->clearHistory();
66         $this->assertEmpty($readline->listHistory());
67     }
68
69     public function testSomeThingsAreAlwaysTrue()
70     {
71         $readline = new Transient();
72         $this->assertTrue(Transient::isSupported());
73         $this->assertTrue($readline->readHistory());
74         $this->assertTrue($readline->writeHistory());
75     }
76 }