-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make source code compatible with PHP 5.4
* Use PHPUnit mock instead of Mockery * Add more unit-tests to coverage all source code
- Loading branch information
Showing
11 changed files
with
221 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php namespace Bllim\Laravalid; | ||
|
||
use Illuminate\Html\HtmlBuilder; | ||
|
||
class ServiceProviderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testDeferred() | ||
{ | ||
$provider = new LaravalidServiceProvider(null); | ||
|
||
$this->assertAttributeSame(null, 'app', $provider); | ||
$this->assertFalse($provider->isDeferred()); | ||
} | ||
|
||
public function testProvides() | ||
{ | ||
$provider = new LaravalidServiceProvider(null); | ||
$this->assertEquals(array('laravalid'), $provider->provides()); | ||
} | ||
|
||
public function testRegister() | ||
{ | ||
$app = $this->getMock('Illuminate\Container\Container', array('bound', 'bind', 'make')); | ||
|
||
$app->expects($this->once())->method('bound')->with('html')->willReturn(false); | ||
$app->expects($this->exactly(2))->method('bind') | ||
->withConsecutive( | ||
array('html', $this->callback(function ($closure) use ($app, &$html) { | ||
$html = $closure($app); | ||
return ($html instanceof HtmlBuilder); | ||
}), $this->isTrue()), | ||
array('laravalid', $this->callback(function ($closure) use ($app) { | ||
$form = $closure($app); | ||
return ($form instanceof FormBuilder); | ||
}), $this->isTrue()) | ||
); | ||
|
||
$url = $this->getMock('Illuminate\Routing\UrlGenerator', array('to'), array(), '', false); | ||
$config = $this->getMock('Illuminate\Config\Repository', array('get'), array(), '', false); | ||
$session = $this->getMock('Illuminate\Session\Store', array('getToken'), array(), '', false); | ||
|
||
$app->expects($this->atLeast(4))->method('make')->withConsecutive(['url'], ['config'])->willReturnMap(array( | ||
array('url', array(), $url), | ||
array('config', array(), $config), | ||
array('session.store', array(), $session), | ||
array('html', array(), &$html), | ||
)); | ||
|
||
$config->expects($this->once())->method('get')->with('laravalid::plugin')->willReturn('\MyTestPlugin'); | ||
$session->expects($this->once())->method('getToken')->willReturn(uniqid()); | ||
|
||
if (!class_exists('MyTestPlugin\Converter')) | ||
eval('namespace MyTestPlugin { class Converter extends \\' . __NAMESPACE__ . '\Converter\Base\Converter { public function __construct() { echo __CLASS__; } } }'); | ||
|
||
$this->expectOutputString('MyTestPlugin\Converter'); | ||
/** @noinspection PhpParamsInspection */ | ||
$provider = new LaravalidServiceProvider($app); | ||
$provider->register(); | ||
} | ||
|
||
public function testBoot() | ||
{ | ||
$app = $this->getMock('Illuminate\Container\Container', array('make')); | ||
|
||
$files = $this->getMock('Illuminate\Filesystem\Filesystem', null); | ||
$config = $this->getMock('Illuminate\Config\Repository', array('get', 'package'), array(), '', false); | ||
$router = $this->getMock('Illuminate\Routing\Router', array('any'), array(), '', false); | ||
$route = $this->getMock('Illuminate\Routing\Route', array('where'), array(), '', false); | ||
|
||
$form = $this->getMock(__NAMESPACE__ . '\FormBuilder', array('converter'), array(), '', false); | ||
$converter = $this->getMock(__NAMESPACE__ . '\Converter\Base\Converter', array('route'), array(), '', false); | ||
$valid = $this->getMock(__NAMESPACE__ . '\Converter\Base\Route', array('convert'), array(), '', false); | ||
$request = $this->getMock('Illuminate\Http\Request', array('all'), array(), '', false); | ||
|
||
$app->expects($this->atLeast(5))->method('make')->withConsecutive(['files'], ['config'])->willReturnMap(array( | ||
array('files', array(), $files), | ||
array('config', array(), $config), | ||
array('router', array(), $router), | ||
array('laravalid', array(), $form), | ||
array('request', array(), $request), | ||
)); | ||
|
||
$path = realpath(__DIR__ . '/../../../src'); | ||
$config->expects($this->once())->method('package')->with('bllim/laravalid', $path . '/config', 'laravalid'); | ||
$config->expects($this->once())->method('get')->with('laravalid::route', 'laravalid')->willReturnArgument(1); | ||
|
||
$router->expects($this->once())->method('any')->willReturnCallback(function ($url, $action) use ($route) { | ||
static::assertEquals('laravalid/{rule}', $url); | ||
static::assertEquals('["exists",[{"params":"~"}]]', $action('exists')); | ||
return $route; | ||
}); | ||
$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 () { | ||
return json_encode(func_get_args()); | ||
}); | ||
$request->expects($this->once())->method('all')->willReturn(array('params' => '~')); | ||
|
||
/** @noinspection PhpParamsInspection */ | ||
$provider = new LaravalidServiceProvider($app); | ||
$provider->boot(); | ||
} | ||
} |
Oops, something went wrong.