Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Sep 6, 2019
1 parent e7b2b08 commit a33c05e
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 68 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
composer.phar
composer.lock
.php_cs.cache
.phpunit.result.cache
.DS_Store
.mix-manifest.json
Thumbs.db
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
language: php

php:
- 5.5.9
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
Expand All @@ -21,7 +18,7 @@ matrix:
- php: hhvm
fast_finish: true
include:
- php: 5.5.9
- php: 7.0
env: setup=lowest
- php: hhvm
dist: trusty
Expand Down
8 changes: 4 additions & 4 deletions tests/Console/Commands/ArtisanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Recca0120\Terminal\Tests\Console\Commands;

use Mockery as m;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Recca0120\Terminal\ProcessUtils;
use Recca0120\Terminal\Console\Commands\Artisan;
Expand Down Expand Up @@ -67,13 +68,12 @@ public function testHandleVendorPublishCommand()
$command->handle();
}

/**
* @expectedException InvalidArgumentException
*/
public function testHandleNotSupportCommand()
{
$this->expectException(InvalidArgumentException::class);

$command = new Artisan(
$kernel = m::mock('Illuminate\Contracts\Console\Kernel')
m::mock('Illuminate\Contracts\Console\Kernel')
);
$this->mockProperty($command, 'input', $input = m::mock('Symfony\Component\Console\Input\InputInterface'));
$this->mockProperty($command, 'output', $output = new BufferedOutput);
Expand Down
11 changes: 4 additions & 7 deletions tests/Console/Commands/ArtisanTinkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\BufferedOutput;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Recca0120\Terminal\Console\Commands\ArtisanTinker;

class ArtisanTinkerTest extends TestCase
{
protected function tearDown()
{
parent::tearDown();
m::close();
}
use MockeryPHPUnitIntegration;

public function testHandleEcho()
{
Expand All @@ -24,7 +21,7 @@ public function testHandleEcho()
$input->shouldReceive('getOption')->once()->with('command')->andReturn($cmd = 'echo 123');
$command->handle();

$this->assertContains('123', $this->lf($output->fetch()));
$this->assertStringContainsString('123', $this->lf($output->fetch()));
}

public function testHandleVarDump()
Expand All @@ -36,7 +33,7 @@ public function testHandleVarDump()
$input->shouldReceive('getOption')->once()->with('command')->andReturn($cmd = 'var_dump(123)');
$this->assertNull($command->handle());

$this->assertContains('int(123)', $this->lf($output->fetch()));
$this->assertStringContainsString('int(123)', $this->lf($output->fetch()));
}

public function testHandleObject()
Expand Down
15 changes: 6 additions & 9 deletions tests/Console/Commands/CleanupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
use Recca0120\Terminal\Console\Commands\Cleanup;
use Symfony\Component\Console\Output\BufferedOutput;
use org\bovigo\vfs\visitor\vfsStreamStructureVisitor;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;

class CleanupTest extends TestCase
{
protected function tearDown()
{
parent::tearDown();
m::close();
}
use MockeryPHPUnitIntegration;

public function testHandle()
{
Expand Down Expand Up @@ -130,14 +127,14 @@ public function testHandle()
Container::setInstance($container);

$command = new Cleanup(
$files = m::mock(new Filesystem)
m::mock(new Filesystem)
);

$this->mockProperty($command, 'input', $input = m::mock('Symfony\Component\Console\Input\InputInterface'));
$this->mockProperty($command, 'output', $output = new BufferedOutput);
$this->mockProperty($command, 'input', m::mock('Symfony\Component\Console\Input\InputInterface'));
$this->mockProperty($command, 'output', new BufferedOutput);

$command->setLaravel(
$laravel = m::mock('Illuminate\Contracts\Foundation\Application')
m::mock('Illuminate\Contracts\Foundation\Application')
);
$command->handle();

Expand Down
31 changes: 14 additions & 17 deletions tests/Console/Commands/FindTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
use Recca0120\Terminal\Console\Commands\Find;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;

class FindTest extends TestCase
{
protected function setUp()
use MockeryPHPUnitIntegration;

protected function setUp(): void
{
parent::setUp();
$structure = [
Expand All @@ -30,17 +33,11 @@ protected function setUp()
Container::setInstance($container);
}

protected function tearDown()
{
parent::tearDown();
m::close();
}

public function testHandleFindName()
{
$command = new Find(
$finder = m::mock('Symfony\Component\Finder\Finder'),
$files = m::mock(new Filesystem)
m::mock(new Filesystem)
);

$this->mockProperty($command, 'input', $input = m::mock('Symfony\Component\Console\Input\InputInterface'));
Expand All @@ -53,7 +50,7 @@ public function testHandleFindName()
$input->shouldReceive('getOption')->once()->with('delete')->andReturn(null);

$command->setLaravel(
$laravel = m::mock('Illuminate\Contracts\Foundation\Application')
m::mock('Illuminate\Contracts\Foundation\Application')
);
$basePath = $this->root->url();

Expand All @@ -74,7 +71,7 @@ public function testHandleFindNameByDirectory()
{
$command = new Find(
$finder = m::mock('Symfony\Component\Finder\Finder'),
$files = m::mock(new Filesystem)
m::mock(new Filesystem)
);

$this->mockProperty($command, 'input', $input = m::mock('Symfony\Component\Console\Input\InputInterface'));
Expand All @@ -87,7 +84,7 @@ public function testHandleFindNameByDirectory()
$input->shouldReceive('getOption')->once()->with('delete')->andReturn(null);

$command->setLaravel(
$laravel = m::mock('Illuminate\Contracts\Foundation\Application')
m::mock('Illuminate\Contracts\Foundation\Application')
);
$basePath = $this->root->url();

Expand All @@ -109,7 +106,7 @@ public function testHandleFindNameByFile()
{
$command = new Find(
$finder = m::mock('Symfony\Component\Finder\Finder'),
$files = m::mock(new Filesystem)
m::mock(new Filesystem)
);

$this->mockProperty($command, 'input', $input = m::mock('Symfony\Component\Console\Input\InputInterface'));
Expand All @@ -122,7 +119,7 @@ public function testHandleFindNameByFile()
$input->shouldReceive('getOption')->once()->with('delete')->andReturn(null);

$command->setLaravel(
$laravel = m::mock('Illuminate\Contracts\Foundation\Application')
m::mock('Illuminate\Contracts\Foundation\Application')
);
$basePath = $this->root->url();

Expand All @@ -144,7 +141,7 @@ public function testHandleFindMaxDepthIsZero()
{
$command = new Find(
$finder = m::mock('Symfony\Component\Finder\Finder'),
$files = m::mock(new Filesystem)
m::mock(new Filesystem)
);

$this->mockProperty($command, 'input', $input = m::mock('Symfony\Component\Console\Input\InputInterface'));
Expand All @@ -157,7 +154,7 @@ public function testHandleFindMaxDepthIsZero()
$input->shouldReceive('getOption')->once()->with('delete')->andReturn(null);

$command->setLaravel(
$laravel = m::mock('Illuminate\Contracts\Foundation\Application')
m::mock('Illuminate\Contracts\Foundation\Application')
);
$basePath = $this->root->url();

Expand All @@ -171,7 +168,7 @@ public function testHandleFindMaxDepthBiggerZero()
{
$command = new Find(
$finder = m::mock('Symfony\Component\Finder\Finder'),
$files = m::mock(new Filesystem)
m::mock(new Filesystem)
);

$this->mockProperty($command, 'input', $input = m::mock('Symfony\Component\Console\Input\InputInterface'));
Expand All @@ -184,7 +181,7 @@ public function testHandleFindMaxDepthBiggerZero()
$input->shouldReceive('getOption')->once()->with('delete')->andReturn(null);

$command->setLaravel(
$laravel = m::mock('Illuminate\Contracts\Foundation\Application')
m::mock('Illuminate\Contracts\Foundation\Application')
);
$basePath = $this->root->url();

Expand Down
9 changes: 3 additions & 6 deletions tests/Console/Commands/MysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
use PHPUnit\Framework\TestCase;
use Recca0120\Terminal\Console\Commands\Mysql;
use Symfony\Component\Console\Output\BufferedOutput;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;

class MysqlTest extends TestCase
{
protected function tearDown()
{
parent::tearDown();
m::close();
}
use MockeryPHPUnitIntegration;

public function testHandle()
{
Expand All @@ -33,7 +30,7 @@ public function testHandle()
]);

$command->handle();
$this->assertContains('email', $output->fetch());
$this->assertStringContainsString('email', $output->fetch());
}

protected function mockProperty($object, $propertyName, $value)
Expand Down
21 changes: 9 additions & 12 deletions tests/Console/Commands/TailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
use Illuminate\Filesystem\Filesystem;
use Recca0120\Terminal\Console\Commands\Tail;
use Symfony\Component\Console\Output\BufferedOutput;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;

class TailTest extends TestCase
{
protected function setUp()
use MockeryPHPUnitIntegration;

protected function setUp(): void
{
parent::setUp();
$structure = [
Expand Down Expand Up @@ -95,12 +98,6 @@ protected function setUp()
Container::setInstance($container);
}

protected function tearDown()
{
parent::tearDown();
m::close();
}

public function testHandle()
{
$command = new Tail(
Expand All @@ -112,7 +109,7 @@ public function testHandle()
$input->shouldReceive('getArgument')->once()->with('path')->andReturn(null);
$input->shouldReceive('getOption')->once()->with('lines')->andReturn($lines = 5);
$command->setLaravel(
$laravel = m::mock('Illuminate\Contracts\Foundation\Application')
m::mock('Illuminate\Contracts\Foundation\Application')
);
$storagePath = $this->root->url();
$files->shouldReceive('glob')->once()->with($storagePath.'/logs/*.log')->andReturnUsing(function ($path) {
Expand All @@ -121,27 +118,27 @@ public function testHandle()

$command->handle();

$this->assertContains('5.log', $output->fetch());
$this->assertStringContainsString('5.log', $output->fetch());
}

public function testHandlePath()
{
$command = new Tail(
$files = m::mock('Illuminate\Filesystem\Filesystem')
m::mock('Illuminate\Filesystem\Filesystem')
);
$this->mockProperty($command, 'input', $input = m::mock('Symfony\Component\Console\Input\InputInterface'));
$this->mockProperty($command, 'output', $output = new BufferedOutput);

$command->setLaravel(
$laravel = m::mock('Illuminate\Contracts\Foundation\Application')
m::mock('Illuminate\Contracts\Foundation\Application')
);

$input->shouldReceive('getArgument')->once()->with('path')->andReturn($path = 'logs/1.log');
$input->shouldReceive('getOption')->once()->with('lines')->andReturn($lines = 5);

$command->handle();

$this->assertContains('1.log', $output->fetch());
$this->assertStringContainsString('1.log', $output->fetch());
}

protected function mockProperty($object, $propertyName, $value)
Expand Down
13 changes: 5 additions & 8 deletions tests/Console/Commands/ViTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@
use Illuminate\Container\Container;
use Recca0120\Terminal\Console\Commands\Vi;
use Symfony\Component\Console\Output\BufferedOutput;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;

class ViTest extends TestCase
{
protected function setUp()
use MockeryPHPUnitIntegration;

protected function setUp():void
{
parent::setUp();
$container = m::mock(new Container);
$container->shouldReceive('basePath')->andReturn('foo/');
Container::setInstance($container);
}

protected function tearDown()
{
parent::tearDown();
m::close();
}

public function testHandleRead()
{
$command = new Vi(
Expand All @@ -44,7 +41,7 @@ public function testHandleRead()

$command->handle();

$this->assertContains($text, $output->fetch());
$this->assertStringContainsString($text, $output->fetch());
}

public function testHandleWrite()
Expand Down
4 changes: 3 additions & 1 deletion tests/TerminalServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TerminalServiceProviderTest extends TestCase
{
use MockeryPHPUnitIntegration;

protected function setUp()
protected function setUp():void
{
parent::setUp();
$container = m::mock(new Container);
Expand All @@ -36,6 +36,8 @@ public function testRegister()
$config->shouldReceive('get')->once()->with('terminal', [])->andReturn([]);
$config->shouldReceive('set')->once()->with('terminal', m::type('array'));

$app->shouldReceive('configurationIsCached')->andReturn(false);

$app->shouldReceive('singleton')->once()->with(
'Recca0120\Terminal\Application', m::on(function ($closure) use ($app) {
$app->shouldReceive('offsetGet')->once()->with('config')->andReturn(
Expand Down

0 comments on commit a33c05e

Please sign in to comment.