TransientTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2017 Justin Hileman
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Psy\Test\Readline;
  11. use Psy\Readline\Transient;
  12. class TransientTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testHistory()
  15. {
  16. $readline = new Transient();
  17. $this->assertEmpty($readline->listHistory());
  18. $readline->addHistory('foo');
  19. $this->assertEquals(array('foo'), $readline->listHistory());
  20. $readline->addHistory('bar');
  21. $this->assertEquals(array('foo', 'bar'), $readline->listHistory());
  22. $readline->addHistory('baz');
  23. $this->assertEquals(array('foo', 'bar', 'baz'), $readline->listHistory());
  24. $readline->clearHistory();
  25. $this->assertEmpty($readline->listHistory());
  26. }
  27. /**
  28. * @depends testHistory
  29. */
  30. public function testHistorySize()
  31. {
  32. $readline = new Transient(null, 2);
  33. $this->assertEmpty($readline->listHistory());
  34. $readline->addHistory('foo');
  35. $readline->addHistory('bar');
  36. $this->assertEquals(array('foo', 'bar'), $readline->listHistory());
  37. $readline->addHistory('baz');
  38. $this->assertEquals(array('bar', 'baz'), $readline->listHistory());
  39. $readline->addHistory('w00t');
  40. $this->assertEquals(array('baz', 'w00t'), $readline->listHistory());
  41. $readline->clearHistory();
  42. $this->assertEmpty($readline->listHistory());
  43. }
  44. /**
  45. * @depends testHistory
  46. */
  47. public function testHistoryEraseDups()
  48. {
  49. $readline = new Transient(null, 0, true);
  50. $this->assertEmpty($readline->listHistory());
  51. $readline->addHistory('foo');
  52. $readline->addHistory('bar');
  53. $readline->addHistory('foo');
  54. $this->assertEquals(array('bar', 'foo'), $readline->listHistory());
  55. $readline->addHistory('baz');
  56. $readline->addHistory('w00t');
  57. $readline->addHistory('baz');
  58. $this->assertEquals(array('bar', 'foo', 'w00t', 'baz'), $readline->listHistory());
  59. $readline->clearHistory();
  60. $this->assertEmpty($readline->listHistory());
  61. }
  62. public function testSomeThingsAreAlwaysTrue()
  63. {
  64. $readline = new Transient();
  65. $this->assertTrue(Transient::isSupported());
  66. $this->assertTrue($readline->readHistory());
  67. $this->assertTrue($readline->writeHistory());
  68. }
  69. }