Skip to content

Commit 1212641

Browse files
committed
Adopt to PSR-2
1 parent b4bc8ba commit 1212641

File tree

10 files changed

+446
-449
lines changed

10 files changed

+446
-449
lines changed
+61-60
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,68 @@
1-
<?php namespace spec\KiaKing\LaravelLocale;
1+
<?php
2+
3+
namespace spec\KiaKing\LaravelLocale;
24

35
use PhpSpec\ObjectBehavior;
46
use Prophecy\Argument;
57
use Illuminate\Contracts\Config\Repository as Config;
68
use Illuminate\Contracts\Routing\Registrar as Router;
79

8-
class LocaleRouterSpec extends ObjectBehavior {
9-
10-
public function loopTest(Config $config, Router $router, $method)
11-
{
12-
$router->{$method}('home', 'HomeController@index')->shouldBeCalled();
13-
$router->{$method}('en/home', 'HomeController@index')->shouldBeCalled();
14-
$router->{$method}('fr/home', 'HomeController@index')->shouldBeCalled();
15-
16-
$router->{$method}('home', ['as' => 'home', 'uses' => 'HomeController@index'])
17-
->shouldBeCalled();
18-
19-
$router->{$method}('en/home', ['as' => 'en.home', 'uses' => 'HomeController@index'])
20-
->shouldBeCalled();
21-
22-
$router->{$method}('fr/home', ['as' => 'fr.home', 'uses' => 'HomeController@index'])
23-
->shouldBeCalled();
24-
25-
$this->{$method}('home', 'HomeController@index');
26-
$this->{$method}('home', ['as' => 'home', 'uses' => 'HomeController@index']);
27-
}
28-
29-
function let(Config $config, Router $router)
30-
{
31-
$this->beConstructedWith($config, $router);
32-
33-
$config->get('locale.available_locales')->willReturn(['ja', 'en', 'fr']);
34-
$config->get('app.fallback_locale')->willReturn('ja');
35-
}
36-
37-
function it_is_initializable()
38-
{
39-
$this->shouldHaveType('KiaKing\LaravelLocale\LocaleRouter');
40-
}
41-
42-
function it_can_generate_get_routes(Config $config, Router $router)
43-
{
44-
$this->loopTest($config, $router, 'get');
45-
}
46-
47-
function it_can_generate_post_routes(Config $config, Router $router)
48-
{
49-
$this->loopTest($config, $router, 'post');
50-
}
51-
52-
function it_can_generate_put_routes(Config $config, Router $router)
53-
{
54-
$this->loopTest($config, $router, 'put');
55-
}
56-
57-
function it_can_generate_patch_routes(Config $config, Router $router)
58-
{
59-
$this->loopTest($config, $router, 'patch');
60-
}
61-
62-
function it_can_generate_delete_routes(Config $config, Router $router)
63-
{
64-
$this->loopTest($config, $router, 'delete');
65-
}
66-
10+
class LocaleRouterSpec extends ObjectBehavior
11+
{
12+
public function loopTest(Config $config, Router $router, $method)
13+
{
14+
$router->{$method}('home', 'HomeController@index')->shouldBeCalled();
15+
$router->{$method}('en/home', 'HomeController@index')->shouldBeCalled();
16+
$router->{$method}('fr/home', 'HomeController@index')->shouldBeCalled();
17+
18+
$router->{$method}('home', ['as' => 'home', 'uses' => 'HomeController@index'])
19+
->shouldBeCalled();
20+
21+
$router->{$method}('en/home', ['as' => 'en.home', 'uses' => 'HomeController@index'])
22+
->shouldBeCalled();
23+
24+
$router->{$method}('fr/home', ['as' => 'fr.home', 'uses' => 'HomeController@index'])
25+
->shouldBeCalled();
26+
27+
$this->{$method}('home', 'HomeController@index');
28+
$this->{$method}('home', ['as' => 'home', 'uses' => 'HomeController@index']);
29+
}
30+
31+
function let(Config $config, Router $router)
32+
{
33+
$this->beConstructedWith($config, $router);
34+
35+
$config->get('locale.available_locales')->willReturn(['ja', 'en', 'fr']);
36+
$config->get('app.fallback_locale')->willReturn('ja');
37+
}
38+
39+
function it_is_initializable()
40+
{
41+
$this->shouldHaveType('KiaKing\LaravelLocale\LocaleRouter');
42+
}
43+
44+
function it_can_generate_get_routes(Config $config, Router $router)
45+
{
46+
$this->loopTest($config, $router, 'get');
47+
}
48+
49+
function it_can_generate_post_routes(Config $config, Router $router)
50+
{
51+
$this->loopTest($config, $router, 'post');
52+
}
53+
54+
function it_can_generate_put_routes(Config $config, Router $router)
55+
{
56+
$this->loopTest($config, $router, 'put');
57+
}
58+
59+
function it_can_generate_patch_routes(Config $config, Router $router)
60+
{
61+
$this->loopTest($config, $router, 'patch');
62+
}
63+
64+
function it_can_generate_delete_routes(Config $config, Router $router)
65+
{
66+
$this->loopTest($config, $router, 'delete');
67+
}
6768
}
+82-81
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,90 @@
1-
<?php namespace spec\KiaKing\LaravelLocale;
1+
<?php
2+
3+
namespace spec\KiaKing\LaravelLocale;
24

35
use PhpSpec\ObjectBehavior;
46
use Prophecy\Argument;
57
use Illuminate\Contracts\Config\Repository as Config;
68
use Illuminate\Http\Request;
79
use Illuminate\Contracts\Routing\UrlGenerator;
810

9-
class LocaleUrlGeneratorSpec extends ObjectBehavior {
10-
11-
function let(Config $config, Request $request, UrlGenerator $url)
12-
{
13-
$this->beConstructedWith($config, $request, $url);
14-
15-
$config->get('locale.available_locales')->willReturn(['ja', 'en', 'fr']);
16-
$config->get('app.fallback_locale')->willReturn('ja');
17-
}
18-
19-
function it_is_initializable()
20-
{
21-
$this->shouldHaveType('KiaKing\LaravelLocale\LocaleUrlGenerator');
22-
}
23-
24-
function it_passes_non_prefixed_url_to_url_when_locale_is_default(Config $config, UrlGenerator $url)
25-
{
26-
$config->get('app.locale')->willReturn('ja');
27-
$url->to('home', [], null)->shouldBeCalled();
28-
29-
$this->url('home');
30-
}
31-
32-
function it_passes_prefixed_url_to_url_when_locale_is_not_default(Config $config, UrlGenerator $url)
33-
{
34-
$config->get('app.locale')->willReturn('en');
35-
$url->to('en/home', [], null)->shouldBeCalled();
36-
37-
$this->url('home');
38-
}
39-
40-
function it_passes_non_prefixed_named_route_to_url_when_locale_is_default(Config $config, UrlGenerator $url)
41-
{
42-
$config->get('app.locale')->willReturn('ja');
43-
$url->route('home', [], true)->shouldBeCalled();
44-
45-
$this->route('home');
46-
}
47-
48-
function it_passes_prefixed_named_route_to_url_when_locale_is_not_default(Config $config, UrlGenerator $url)
49-
{
50-
$config->get('app.locale')->willReturn('en');
51-
$url->route('en.home', [], true)->shouldBeCalled();
52-
53-
$this->route('home');
54-
}
55-
56-
function it_can_change_url_to_same_locale(Config $config, Request $request)
57-
{
58-
$config->get('app.locale')->willReturn('ja');
59-
$request->fullUrl()->willReturn('http://example.com/?query=value');
60-
61-
$this->change('ja')->shouldReturn('http://example.com/?query=value');
62-
}
63-
64-
function it_can_change_url_to_other_locale_from_default(Config $config, Request $request)
65-
{
66-
$config->get('app.locale')->willReturn('ja');
67-
$request->root()->willReturn('http://example.com');
68-
$request->fullUrl()->willReturn('http://example.com/?query=value');
69-
70-
$this->change('en')->shouldReturn('http://example.com/en/?query=value');
71-
}
72-
73-
function it_can_change_url_to_default_locale_from_non_default_locale(Config $config, Request $request)
74-
{
75-
$config->get('app.locale')->willReturn('en');
76-
$request->fullUrl()->willReturn('http://example.com/en/?query=value');
77-
78-
$this->change('ja')->shouldReturn('http://example.com/?query=value');
79-
}
80-
81-
function it_can_change_url_to_other_locale_from_non_default_locale(Config $config, Request $request)
82-
{
83-
$config->get('app.locale')->willReturn('en');
84-
$request->fullUrl()->willReturn('http://example.com/en/?query=value');
85-
86-
$this->change('fr')->shouldReturn('http://example.com/fr/?query=value');
87-
}
88-
11+
class LocaleUrlGeneratorSpec extends ObjectBehavior
12+
{
13+
function let(Config $config, Request $request, UrlGenerator $url)
14+
{
15+
$this->beConstructedWith($config, $request, $url);
16+
17+
$config->get('locale.available_locales')->willReturn(['ja', 'en', 'fr']);
18+
$config->get('app.fallback_locale')->willReturn('ja');
19+
}
20+
21+
function it_is_initializable()
22+
{
23+
$this->shouldHaveType('KiaKing\LaravelLocale\LocaleUrlGenerator');
24+
}
25+
26+
function it_passes_non_prefixed_url_to_url_when_locale_is_default(Config $config, UrlGenerator $url)
27+
{
28+
$config->get('app.locale')->willReturn('ja');
29+
$url->to('home', [], null)->shouldBeCalled();
30+
31+
$this->url('home');
32+
}
33+
34+
function it_passes_prefixed_url_to_url_when_locale_is_not_default(Config $config, UrlGenerator $url)
35+
{
36+
$config->get('app.locale')->willReturn('en');
37+
$url->to('en/home', [], null)->shouldBeCalled();
38+
39+
$this->url('home');
40+
}
41+
42+
function it_passes_non_prefixed_named_route_to_url_when_locale_is_default(Config $config, UrlGenerator $url)
43+
{
44+
$config->get('app.locale')->willReturn('ja');
45+
$url->route('home', [], true)->shouldBeCalled();
46+
47+
$this->route('home');
48+
}
49+
50+
function it_passes_prefixed_named_route_to_url_when_locale_is_not_default(Config $config, UrlGenerator $url)
51+
{
52+
$config->get('app.locale')->willReturn('en');
53+
$url->route('en.home', [], true)->shouldBeCalled();
54+
55+
$this->route('home');
56+
}
57+
58+
function it_can_change_url_to_same_locale(Config $config, Request $request)
59+
{
60+
$config->get('app.locale')->willReturn('ja');
61+
$request->fullUrl()->willReturn('http://example.com/?query=value');
62+
63+
$this->change('ja')->shouldReturn('http://example.com/?query=value');
64+
}
65+
66+
function it_can_change_url_to_other_locale_from_default(Config $config, Request $request)
67+
{
68+
$config->get('app.locale')->willReturn('ja');
69+
$request->root()->willReturn('http://example.com');
70+
$request->fullUrl()->willReturn('http://example.com/?query=value');
71+
72+
$this->change('en')->shouldReturn('http://example.com/en/?query=value');
73+
}
74+
75+
function it_can_change_url_to_default_locale_from_non_default_locale(Config $config, Request $request)
76+
{
77+
$config->get('app.locale')->willReturn('en');
78+
$request->fullUrl()->willReturn('http://example.com/en/?query=value');
79+
80+
$this->change('ja')->shouldReturn('http://example.com/?query=value');
81+
}
82+
83+
function it_can_change_url_to_other_locale_from_non_default_locale(Config $config, Request $request)
84+
{
85+
$config->get('app.locale')->willReturn('en');
86+
$request->fullUrl()->willReturn('http://example.com/en/?query=value');
87+
88+
$this->change('fr')->shouldReturn('http://example.com/fr/?query=value');
89+
}
8990
}
+11-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
<?php namespace KiaKing\LaravelLocale\Facades;
1+
<?php
22

3-
use Illuminate\Support\Facades\Facade;
4-
5-
class LocaleRouter extends Facade {
3+
namespace KiaKing\LaravelLocale\Facades;
64

7-
/**
8-
* Get the registered name of the component.
9-
*
10-
* @return string
11-
*/
12-
protected static function getFacadeAccessor() { return 'locale'; }
5+
use Illuminate\Support\Facades\Facade;
136

7+
class LocaleRouter extends Facade
8+
{
9+
/**
10+
* Get the registered name of the component.
11+
*
12+
* @return string
13+
*/
14+
protected static function getFacadeAccessor() { return 'locale'; }
1415
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
<?php namespace KiaKing\LaravelLocale\Facades;
1+
<?php
22

3-
use Illuminate\Support\Facades\Facade;
4-
5-
class LocaleUrlGenerator extends Facade {
3+
namespace KiaKing\LaravelLocale\Facades;
64

7-
/**
8-
* Get the registered name of the component.
9-
*
10-
* @return string
11-
*/
12-
protected static function getFacadeAccessor() { return 'locale.url'; }
5+
use Illuminate\Support\Facades\Facade;
136

7+
class LocaleUrlGenerator extends Facade
8+
{
9+
/**
10+
* Get the registered name of the component.
11+
*
12+
* @return string
13+
*/
14+
protected static function getFacadeAccessor() { return 'locale.url'; }
1415
}

src/LaravelLocale/LocaleFacade.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
<?php namespace KiaKing\LaravelLocale;
1+
<?php
22

3-
use Illuminate\Support\Facades\Facade;
4-
5-
class LocaleFacade extends Facade {
3+
namespace KiaKing\LaravelLocale;
64

7-
/**
8-
* Get the registered name of the component.
9-
*
10-
* @return string
11-
*/
12-
protected static function getFacadeAccessor() { return 'locale'; }
5+
use Illuminate\Support\Facades\Facade;
136

7+
class LocaleFacade extends Facade
8+
{
9+
/**
10+
* Get the registered name of the component.
11+
*
12+
* @return string
13+
*/
14+
protected static function getFacadeAccessor() { return 'locale'; }
1415
}

0 commit comments

Comments
 (0)