Skip to content

Commit

Permalink
Format PHP tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eightyfive committed Sep 15, 2022
1 parent e8f31cb commit d3472e3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 53 deletions.
86 changes: 43 additions & 43 deletions tests/AutorouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,109 +25,109 @@ public function testCreatesRoutes(): void
{
$autoroute = $this->getAutoroute();
$autoroute->create([
'users' => [
'get' => [
'uses' => 'UserController@get',
"users" => [
"get" => [
"uses" => "UserController@get",
],
'post' => [
'uses' => 'UserController@store',
"post" => [
"uses" => "UserController@store",
],
],
'users/{id}' => [
'where' => [
'id' => '[0-9]+',
"users/{id}" => [
"where" => [
"id" => "[0-9]+",
],
'get' => [
'uses' => 'UserController@find',
"get" => [
"uses" => "UserController@find",
],
'put' => [
'uses' => 'UserController@update',
"put" => [
"uses" => "UserController@update",
],
],
]);

$this->assertRoutes([
'user.get',
'user.store',
'user.find',
'user.update',
"user.get",
"user.store",
"user.find",
"user.update",
]);

$this->assertMethods([
'GET' => 2,
'HEAD' => 2,
'POST' => 1,
'PUT' => 1,
"GET" => 2,
"HEAD" => 2,
"POST" => 1,
"PUT" => 1,
]);
}

public function testCreatesGroup(): void
{
$autoroute = $this->getAutoroute();
$autoroute->create([
'group' => [
'namespace' => 'App\\Http\\Controllers\\Api',
'paths' => [
'users' => [
'get' => [
'uses' => 'UserController@get',
"group" => [
"namespace" => "App\\Http\\Controllers\\Api",
"paths" => [
"users" => [
"get" => [
"uses" => "UserController@get",
],
],
],
],
]);

$this->assertEquals($this->getRoute('user.get'), null);
$this->assertNotEquals($this->getRoute('api.user.get'), null);
$this->assertEquals($this->getRoute("user.get"), null);
$this->assertNotEquals($this->getRoute("api.user.get"), null);
}

public function testAddsConstraints(): void
{
$autoroute = $this->getAutoroute();
$autoroute->create([
'users/{id}' => [
'where' => [
'id' => '[0-9]+',
"users/{id}" => [
"where" => [
"id" => "[0-9]+",
],
'get' => [
'uses' => 'UserController@get',
"get" => [
"uses" => "UserController@get",
],
],
]);

$route = $this->getRoute('user.get');
$route = $this->getRoute("user.get");

$this->assertNotEquals($route, null);
$this->assertEquals($route->wheres['id'], '[0-9]+');
$this->assertEquals($route->wheres["id"], "[0-9]+");
}

public function testLoadsFile(): void
{
$autoroute = $this->getAutoroute();
$autoroute->load(__DIR__ . '/web.yaml');
$autoroute->load(__DIR__ . "/web.yaml");

$this->assertRoutes(['post.store']);
$this->assertRoutes(["post.store"]);
}

public function testLoadsFiles(): void
{
$autoroute = $this->getAutoroute(__DIR__);
$autoroute->load('api.yaml', 'web.yaml');
$autoroute->load("api.yaml", "web.yaml");

$this->assertRoutes(['user.get', 'user.store', 'post.store']);
$this->assertRoutes(["user.get", "user.store", "post.store"]);
}

public function testCompact(): void
{
$autoroute = $this->getAutoroute();
$autoroute->create([
'users' => [
'get' => 'user.get',
'post' => 'api.user.store',
"users" => [
"get" => "user.get",
"post" => "api.user.store",
],
]);

$this->assertRoutes(['user.get', 'api.user.store']);
$this->assertRoutes(["user.get", "api.user.store"]);
}

protected function getRoutes()
Expand Down
20 changes: 10 additions & 10 deletions tests/RouteNamerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,38 @@ final class RouteNamerTest extends TestCase
public function testName(): void
{
$namer = new RouteNamer();
$name = $namer->getRouteName('FooBarController@getUsers');
$name = $namer->getRouteName("FooBarController@getUsers");

$this->assertEquals($name, 'foo_bar.get_users');
$this->assertEquals($name, "foo_bar.get_users");
}

public function testNamespace(): void
{
$namer = new RouteNamer();
$name = $namer->getRouteName(
'UserController@find',
'App\\Http\\Controllers\\Admin\\Api'
"UserController@find",
"App\\Http\\Controllers\\Admin\\Api"
);

$this->assertEquals($name, 'admin.api.user.find');
$this->assertEquals($name, "admin.api.user.find");
}

public function testSubNamespace(): void
{
$namer = new RouteNamer();
$name = $namer->getRouteName(
'Api\\UserController@find',
'App\\Http\\Controllers\\Admin'
"Api\\UserController@find",
"App\\Http\\Controllers\\Admin"
);

$this->assertEquals($name, 'admin.api.user.find');
$this->assertEquals($name, "admin.api.user.find");
}

public function testUses(): void
{
$namer = new RouteNamer();
$uses = $namer->getUses('api.foo.bar.user.find');
$uses = $namer->getUses("api.foo.bar.user.find");

$this->assertEquals($uses, 'Api\\Foo\\Bar\\UserController@find');
$this->assertEquals($uses, "Api\\Foo\\Bar\\UserController@find");
}
}

0 comments on commit d3472e3

Please sign in to comment.