LinuxTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace League\CLImate\Tests\Util\System;
  3. use League\CLImate\Tests\TestBase;
  4. use League\CLImate\Util\System\Linux;
  5. use Mockery;
  6. class LinuxTest extends TestBase
  7. {
  8. /** @test */
  9. public function it_can_get_the_width()
  10. {
  11. $system = Mockery::mock(Linux::class)
  12. ->makePartial()
  13. ->shouldAllowMockingProtectedMethods();
  14. $system->shouldReceive('exec')->with('tput cols 2>/dev/null')->andReturn(100);
  15. $this->assertSame(100, $system->width());
  16. }
  17. /** @test */
  18. public function it_will_return_null_if_width_is_not_numeric()
  19. {
  20. $system = Mockery::mock(Linux::class)
  21. ->makePartial()
  22. ->shouldAllowMockingProtectedMethods();
  23. $system->shouldReceive('exec')->with('tput cols 2>/dev/null')->andReturn('error');
  24. $this->assertNull($system->width());
  25. }
  26. /** @test */
  27. public function it_can_get_the_height()
  28. {
  29. $system = Mockery::mock(Linux::class)
  30. ->makePartial()
  31. ->shouldAllowMockingProtectedMethods();
  32. $system->shouldReceive('exec')->with('tput lines 2>/dev/null')->andReturn(100);
  33. $this->assertSame(100, $system->height());
  34. }
  35. /** @test */
  36. public function it_will_return_null_if_height_is_not_numeric()
  37. {
  38. $system = Mockery::mock(Linux::class)
  39. ->makePartial()
  40. ->shouldAllowMockingProtectedMethods();
  41. $system->shouldReceive('exec')->with('tput lines 2>/dev/null')->andReturn('error');
  42. $this->assertNull($system->height());
  43. }
  44. }