Skip to content

Commit

Permalink
Merge 7b925ec into 1a91bfb
Browse files Browse the repository at this point in the history
  • Loading branch information
agoalofalife committed Dec 10, 2017
2 parents 1a91bfb + 7b925ec commit 087f845
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/CustomObject/StdinFake.php
@@ -0,0 +1,20 @@
<?php
namespace League\CLImate\Tests\CustomObject;

use League\CLImate\Util\Reader\Stdin;

class StdinFake extends Stdin
{
public function callSetSdinFake()
{
$this->setStdIn();
}
public function callGetStdIn()
{
$this->getStdIn();
}
public function changeStdin($value)
{
$this->stdIn = $value;
}
}
16 changes: 16 additions & 0 deletions tests/CustomObject/StdinFakeSetStdin.php
@@ -0,0 +1,16 @@
<?php
namespace League\CLImate\Tests\CustomObject;

use Error;

class StdinFakeSetStdin extends StdinFake
{
/**
* Generate error exception
* @throws \Error
*/
protected function setStdIn()
{
throw new Error("error exception");
}
}
57 changes: 57 additions & 0 deletions tests/StdinTest.php
Expand Up @@ -2,6 +2,8 @@

namespace League\CLImate\Tests;

use League\CLImate\Tests\CustomObject\StdinFake;
use League\CLImate\Tests\CustomObject\StdinFakeSetStdin;
use League\CLImate\Util\Reader\Stdin;

require_once 'StdinGlobalMock.php';
Expand Down Expand Up @@ -67,4 +69,59 @@ public function it_can_several_characters_from_stdin()

$this->assertSame('I hear', $response);
}

/** @test */
public function it_can_read_but_hide_typing_user()
{
$stdin = new Stdin;
$mock = \Mockery::mock('alias:Seld\CliPrompt\CliPrompt');
$mock->shouldReceive('hiddenPrompt')->once();
$stdin->hidden();
}

/** @test */
public function it_set_stdin_expect_exception()
{
$stdin = new Stdin;
$this->expectException(\Exception::class);
self::$functions->shouldReceive('fopen')
->once()
->with('php://stdin', 'r')
->andReturn(false);
$stdin->line();
}

/** @test */
public function it_close_stdin()
{
$stdin = new StdinFake;
self::$functions->shouldReceive('fopen')
->andReturn('resource');

$stdin->changeStdin(fopen('php://memory', 'r'));
$stdin->callSetSdinFake();
}

/** @test */
public function it_get_stdIn_return_if_feof_false()
{
$stdin = new StdinFake;
self::$functions->shouldReceive('fopen')
->andReturn('resource');

self::$functions->shouldReceive('feof')
->andReturn(false);

$stdin->changeStdin(fopen('php://memory', 'r'));
$stdin->callGetStdIn();
}

/** @test */
public function it_get_stdin_exception()
{
$stdin = new StdinFakeSetStdin;
$this->expectException(\Exception::class);
$stdin->callGetStdIn();
}
}

0 comments on commit 087f845

Please sign in to comment.