From a33c05e959458bbb7e290410e66de253e159b931 Mon Sep 17 00:00:00 2001 From: recca0120 Date: Sat, 7 Sep 2019 01:27:30 +0800 Subject: [PATCH] fix tests --- .gitignore | 1 + .travis.yml | 5 +--- tests/Console/Commands/ArtisanTest.php | 8 ++--- tests/Console/Commands/ArtisanTinkerTest.php | 11 +++---- tests/Console/Commands/CleanupTest.php | 15 ++++------ tests/Console/Commands/FindTest.php | 31 +++++++++----------- tests/Console/Commands/MysqlTest.php | 9 ++---- tests/Console/Commands/TailTest.php | 21 ++++++------- tests/Console/Commands/ViTest.php | 13 ++++---- tests/TerminalServiceProviderTest.php | 4 ++- 10 files changed, 50 insertions(+), 68 deletions(-) diff --git a/.gitignore b/.gitignore index a7e7902..73abbfe 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ composer.phar composer.lock .php_cs.cache +.phpunit.result.cache .DS_Store .mix-manifest.json Thumbs.db diff --git a/.travis.yml b/.travis.yml index 2224591..70fa95b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ language: php php: - - 5.5.9 - - 5.5 - - 5.6 - 7.0 - 7.1 - 7.2 @@ -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 diff --git a/tests/Console/Commands/ArtisanTest.php b/tests/Console/Commands/ArtisanTest.php index 95d735a..20b68c4 100644 --- a/tests/Console/Commands/ArtisanTest.php +++ b/tests/Console/Commands/ArtisanTest.php @@ -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; @@ -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); diff --git a/tests/Console/Commands/ArtisanTinkerTest.php b/tests/Console/Commands/ArtisanTinkerTest.php index d69ed2e..4bcafde 100644 --- a/tests/Console/Commands/ArtisanTinkerTest.php +++ b/tests/Console/Commands/ArtisanTinkerTest.php @@ -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() { @@ -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() @@ -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() diff --git a/tests/Console/Commands/CleanupTest.php b/tests/Console/Commands/CleanupTest.php index fd29741..0afdec2 100644 --- a/tests/Console/Commands/CleanupTest.php +++ b/tests/Console/Commands/CleanupTest.php @@ -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() { @@ -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(); diff --git a/tests/Console/Commands/FindTest.php b/tests/Console/Commands/FindTest.php index c711be8..92546cb 100644 --- a/tests/Console/Commands/FindTest.php +++ b/tests/Console/Commands/FindTest.php @@ -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 = [ @@ -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')); @@ -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(); @@ -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')); @@ -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(); @@ -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')); @@ -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(); @@ -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')); @@ -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(); @@ -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')); @@ -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(); diff --git a/tests/Console/Commands/MysqlTest.php b/tests/Console/Commands/MysqlTest.php index d0128bd..df66e24 100644 --- a/tests/Console/Commands/MysqlTest.php +++ b/tests/Console/Commands/MysqlTest.php @@ -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() { @@ -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) diff --git a/tests/Console/Commands/TailTest.php b/tests/Console/Commands/TailTest.php index 0e0883f..be4aa68 100644 --- a/tests/Console/Commands/TailTest.php +++ b/tests/Console/Commands/TailTest.php @@ -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 = [ @@ -95,12 +98,6 @@ protected function setUp() Container::setInstance($container); } - protected function tearDown() - { - parent::tearDown(); - m::close(); - } - public function testHandle() { $command = new Tail( @@ -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) { @@ -121,19 +118,19 @@ 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'); @@ -141,7 +138,7 @@ public function testHandlePath() $command->handle(); - $this->assertContains('1.log', $output->fetch()); + $this->assertStringContainsString('1.log', $output->fetch()); } protected function mockProperty($object, $propertyName, $value) diff --git a/tests/Console/Commands/ViTest.php b/tests/Console/Commands/ViTest.php index a4578ff..815bbc0 100644 --- a/tests/Console/Commands/ViTest.php +++ b/tests/Console/Commands/ViTest.php @@ -7,10 +7,13 @@ 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); @@ -18,12 +21,6 @@ protected function setUp() Container::setInstance($container); } - protected function tearDown() - { - parent::tearDown(); - m::close(); - } - public function testHandleRead() { $command = new Vi( @@ -44,7 +41,7 @@ public function testHandleRead() $command->handle(); - $this->assertContains($text, $output->fetch()); + $this->assertStringContainsString($text, $output->fetch()); } public function testHandleWrite() diff --git a/tests/TerminalServiceProviderTest.php b/tests/TerminalServiceProviderTest.php index 7f6347b..e5f6462 100644 --- a/tests/TerminalServiceProviderTest.php +++ b/tests/TerminalServiceProviderTest.php @@ -14,7 +14,7 @@ class TerminalServiceProviderTest extends TestCase { use MockeryPHPUnitIntegration; - protected function setUp() + protected function setUp():void { parent::setUp(); $container = m::mock(new Container); @@ -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(