4 * This file is part of Psy Shell.
6 * (c) 2012-2018 Justin Hileman
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Psy\Test\Readline;
14 use Psy\Readline\GNUReadline;
16 class GNUReadlineTest extends \PHPUnit\Framework\TestCase
20 public function setUp()
22 if (!GNUReadline::isSupported()) {
23 $this->markTestSkipped('GNUReadline not enabled');
26 $this->historyFile = tempnam(sys_get_temp_dir(), 'psysh_test_history');
27 file_put_contents($this->historyFile, "_HiStOrY_V2_\n");
30 public function testHistory()
32 $readline = new GNUReadline($this->historyFile);
33 $this->assertEmpty($readline->listHistory());
34 $readline->addHistory('foo');
35 $this->assertSame(['foo'], $readline->listHistory());
36 $readline->addHistory('bar');
37 $this->assertSame(['foo', 'bar'], $readline->listHistory());
38 $readline->addHistory('baz');
39 $this->assertSame(['foo', 'bar', 'baz'], $readline->listHistory());
40 $readline->clearHistory();
41 $this->assertEmpty($readline->listHistory());
45 * @depends testHistory
47 public function testHistorySize()
49 $readline = new GNUReadline($this->historyFile, 2);
50 $this->assertEmpty($readline->listHistory());
51 $readline->addHistory('foo');
52 $readline->addHistory('bar');
53 $this->assertSame(['foo', 'bar'], $readline->listHistory());
54 $readline->addHistory('baz');
55 $this->assertSame(['bar', 'baz'], $readline->listHistory());
56 $readline->addHistory('w00t');
57 $this->assertSame(['baz', 'w00t'], $readline->listHistory());
58 $readline->clearHistory();
59 $this->assertEmpty($readline->listHistory());
63 * @depends testHistory
65 public function testHistoryEraseDups()
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->assertSame(['bar', 'foo'], $readline->listHistory());
73 $readline->addHistory('baz');
74 $readline->addHistory('w00t');
75 $readline->addHistory('baz');
76 $this->assertSame(['bar', 'foo', 'w00t', 'baz'], $readline->listHistory());
77 $readline->clearHistory();
78 $this->assertEmpty($readline->listHistory());