1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-04 16:10:08 +01:00

add more tests for new methods and bits of clean up

This commit is contained in:
James Barnard
2019-01-19 23:31:57 +00:00
committed by Matt Stauffer
parent 25c4fab2b4
commit 6158e5129b
5 changed files with 121 additions and 27 deletions

View File

@@ -6,6 +6,7 @@
use function Valet\user;
use function Valet\resolve;
use function Valet\swap;
use Illuminate\Support\Collection;
use Illuminate\Container\Container;
class BrewTest extends PHPUnit_Framework_TestCase
@@ -337,9 +338,70 @@ public function test_unlink_will_pass_formula_to_run_as_user()
$this->assertSame('Some output', resolve(Brew::class)->unlink('aformula'));
}
// TODO: search will pass to brew search
// TODO: search will pass into grep if passed
// TODO: search will throw if fails
// TODO: getRunningServices will return array of services currently started
// TODO: getRunningServices can pass grep to filter result
public function test_search_will_pass_to_brew_search_and_return_array()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->withArgs([
'brew search term',
Mockery::type('callable')
])->andReturn('==> Formulae' . PHP_EOL . 'found' . PHP_EOL . '==> Casks' . PHP_EOL . 'another found' . PHP_EOL);
swap(CommandLine::class, $cli);
$result = resolve(Brew::class)->search('term');
$this->assertInstanceOf(Collection::class, $result);
$this->assertSame([
'found',
'another found',
], array_values($result->all()));
}
/**
* @expectedException DomainException
*/
public function test_search_will_throw_exception_on_failure()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->withArgs([
'brew search term',
Mockery::type('callable'),
])->andReturnUsing(function ($command, $onError) {
$onError(1, 'test error output');
});
swap(CommandLine::class, $cli);
resolve(Brew::class)->search('term');
}
/**
* @expectedException DomainException
*/
public function test_getRunningServices_will_throw_exception_on_failure()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->withArgs([
'brew services list | grep started | awk \'{ print $1; }\'',
Mockery::type('callable'),
])->andReturnUsing(function ($command, $onError) {
$onError(1, 'test error output');
});
swap(CommandLine::class, $cli);
resolve(Brew::class)->getRunningServices();
}
public function test_getRunningServices_will_pass_to_brew_services_list_and_return_array()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->withArgs([
'brew services list | grep started | awk \'{ print $1; }\'',
Mockery::type('callable')
])->andReturn('service1' . PHP_EOL . 'service2' . PHP_EOL . PHP_EOL . 'service3' . PHP_EOL);
swap(CommandLine::class, $cli);
$result = resolve(Brew::class)->getRunningServices('term');
$this->assertInstanceOf(Collection::class, $result);
$this->assertSame([
'service1',
'service2',
'service3',
], array_values($result->all()));
}
}