TransientTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2018 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->assertSame(['foo'], $readline->listHistory());
  20. $readline->addHistory('bar');
  21. $this->assertSame(['foo', 'bar'], $readline->listHistory());
  22. $readline->addHistory('baz');
  23. $this->assertSame(['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->assertSame(['foo', 'bar'], $readline->listHistory());
  37. $readline->addHistory('baz');
  38. $this->assertSame(['bar', 'baz'], $readline->listHistory());
  39. $readline->addHistory('w00t');
  40. $this->assertSame(['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->assertSame(['bar', 'foo'], $readline->listHistory());
  55. $readline->addHistory('baz');
  56. $readline->addHistory('w00t');
  57. $readline->addHistory('baz');
  58. $this->assertSame(['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. }