Skip to content

Commit

Permalink
Merge pull request #55 from nthachus/master
Browse files Browse the repository at this point in the history
Fix travis unit test issues for Laravel 5.4
  • Loading branch information
nthachus committed Feb 24, 2018
2 parents e64fa13 + c4c2cbb commit 898834e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ before_script:
- travis_retry composer self-update
- travis_retry composer install --no-interaction --no-progress

script: phpunit
script: vendor/bin/phpunit
13 changes: 6 additions & 7 deletions tests/Bllim/Laravalid/Converter/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ static function initApplicationMock(\PHPUnit_Framework_TestCase $test, $trans =
$translator = $test->getMock('Illuminate\Translation\Translator', !$trans ? ['has'] : ['has', 'get'], [$loader, 'en']);
$translator->expects($test->any())->method('has')->willReturn(false);

$view = $test->getMock('Illuminate\Contracts\View\Factory');
$mocks = compact('config', 'url', 'encrypter', 'translator', 'view');

$app = $test->getMock('Illuminate\Container\Container', ['make']);
$app->expects($test->any())->method('make')->willReturnMap([
['config', [], $config],
['url', [], $url],
['encrypter', [], $encrypter],
['translator', [], $translator],
['view', [], $test->getMock('Illuminate\Contracts\View\Factory')],
]);
$app->expects($test->any())->method('make')->willReturnCallback(function ($abstract) use ($mocks) {
return isset($mocks[$abstract]) ? $mocks[$abstract] : null;
});

return $app;
}
Expand Down
37 changes: 19 additions & 18 deletions tests/Bllim/Laravalid/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ public function testRegister()
$config = $this->getMock('ArrayAccess', ['get', 'set', 'offsetExists', 'offsetGet', 'offsetSet', 'offsetUnset']);//Illuminate\Config\Repository
$session = $this->getMock('Illuminate\Session\Store', ['token'], [], '', false);

$app->expects($this->atLeast(5))->method('make')->withConsecutive(['config'], ['config'], ['url'])->willReturnMap([
['config', [], $config],
['url', [], $url],
['session.store', [], $session],
['html', [], &$html],
['view', [], $this->getMock('Illuminate\Contracts\View\Factory')],
]);
$mocks = [
'config' => $config,
'url' => $url,
'session.store' => $session,
'html' => &$html,
'view' => $this->getMock('Illuminate\Contracts\View\Factory'),
];
$app->expects($this->atLeast(5))->method('make')->withConsecutive(['config'], ['config'], ['url'])->willReturnCallback(function ($abstract) use ($mocks) {
return isset($mocks[$abstract]) ? $mocks[$abstract] : null;
});

$config->expects($this->once())->method('get')->with('laravalid', [])->willReturnArgument(1);
$config->expects($this->once())->method('set')
Expand All @@ -70,17 +73,15 @@ public function testBoot()
$router = $this->getMock('Illuminate\Routing\Router', ['any'], [], '', false);
$route = $this->getMock('Illuminate\Routing\Route', ['where'], [], '', false);

$form = $this->getMock(__NAMESPACE__ . '\FormBuilder', ['converter'], [], '', false);
$laravalid = $this->getMock(__NAMESPACE__ . '\FormBuilder', ['converter'], [], '', false);
$converter = $this->getMock(__NAMESPACE__ . '\Converter\Base\Converter', ['route'], [], '', false);
$valid = $this->getMock(__NAMESPACE__ . '\Converter\Base\Route', ['convert'], [], '', false);
$vRoute = $this->getMock(__NAMESPACE__ . '\Converter\Base\Route', ['convert'], [], '', false);
$request = $this->getMock('Illuminate\Http\Request', ['all'], [], '', false);

$app->expects($this->atLeast(4))->method('make')->withConsecutive(['path.config'], ['path.public'])->willReturnMap([
['config', [], $config],
['router', [], $router],
['laravalid', [], $form],
['request', [], $request],
]);
$mocks = compact('config', 'router', 'laravalid', 'request');
$app->expects($this->atLeast(4))->method('make')->withConsecutive(['path.config'], ['path.public'])->willReturnCallback(function ($abstract) use ($mocks) {
return isset($mocks[$abstract]) ? $mocks[$abstract] : null;
});

$config->expects($this->once())->method('offsetGet')->with('laravalid.route')->willReturn('laravalid');

Expand All @@ -91,9 +92,9 @@ public function testBoot()
});
$route->expects($this->once())->method('where')->with('rule', '[\w-]+');

$form->expects($this->once())->method('converter')->willReturn($converter);
$converter->expects($this->once())->method('route')->willReturn($valid);
$valid->expects($this->once())->method('convert')->willReturnCallback(function () {
$laravalid->expects($this->once())->method('converter')->willReturn($converter);
$converter->expects($this->once())->method('route')->willReturn($vRoute);
$vRoute->expects($this->once())->method('convert')->willReturnCallback(function () {
return json_encode(func_get_args());
});
$request->expects($this->once())->method('all')->willReturn(['params' => '~']);
Expand Down

0 comments on commit 898834e

Please sign in to comment.