Skip to content

Commit

Permalink
Formatting for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzap committed Feb 12, 2016
1 parent ad3fbf9 commit 3c2186b
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 84 deletions.
7 changes: 3 additions & 4 deletions tests/src/Functional/CortexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
*/
class CortexTest extends TestCaseFunctional
{

public function testBootOnce()
{
$boot1 = Cortex::boot();
Expand Down Expand Up @@ -254,7 +253,7 @@ public function testCortexNotMatchBecauseUrlChangedViaFilter()
}));
});

Filters::expectApplied('cortex.uri.instance')->once()->andReturnUsing(function() {
Filters::expectApplied('cortex.uri.instance')->once()->andReturnUsing(function () {
$uri = \Mockery::mock(Cortex\Uri\UriInterface::class);
$uri->shouldReceive('scheme')->andReturn('http');
$uri->shouldReceive('host')->andReturn('example.com');
Expand Down Expand Up @@ -288,7 +287,7 @@ public function testCortexMatchWhenUrlChangedViaFilterIsInvalid()
}));
});

Filters::expectApplied('cortex.uri.instance')->once()->andReturnUsing(function() {
Filters::expectApplied('cortex.uri.instance')->once()->andReturnUsing(function () {
return 'http://example.com/foo/bar/baz';
});

Expand All @@ -302,4 +301,4 @@ public function testCortexMatchWhenUrlChangedViaFilterIsInvalid()
assertSame(['post_type' => 'products'], $wp->query_vars);
assertFalse($do);
}
}
}
19 changes: 9 additions & 10 deletions tests/src/Functional/RoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,26 @@ public function testAddRoutesAndGroups()

$routeAdders = $groupAdders = [];

Actions::expectAdded('cortex.routes')->twice()->whenHappen(function($add) use(&$routeAdders) {
Actions::expectAdded('cortex.routes')->twice()->whenHappen(function ($add) use (&$routeAdders) {
$routeAdders[] = $add;
});

Actions::expectAdded('cortex.groups')->once()->whenHappen(function($add) use(&$groupAdders) {
Actions::expectAdded('cortex.groups')->once()->whenHappen(function ($add) use (&$groupAdders) {
$groupAdders[] = $add;
});

Actions::expectFired('cortex.routes')
->once()
->whenHappen(function (RouteCollectionInterface $routes) use(&$routeAdders) {
foreach($routeAdders as $routeAdder) {
->whenHappen(function (RouteCollectionInterface $routes) use (&$routeAdders) {
foreach ($routeAdders as $routeAdder) {
$routeAdder($routes);
}
});

Actions::expectFired('cortex.groups')
->once()
->whenHappen(function (GroupCollectionInterface $groups) use(&$groupAdders) {
foreach($groupAdders as $groupAdder) {
->whenHappen(function (GroupCollectionInterface $groups) use (&$groupAdders) {
foreach ($groupAdders as $groupAdder) {
$groupAdder($groups);
}
});
Expand All @@ -100,11 +100,11 @@ public function testMatchRedirectRoute()
/** @var callable|null $factory */
$factory = null;

Actions::expectAdded('cortex.routes')->once()->whenHappen(function($cb) use(&$factory) {
Actions::expectAdded('cortex.routes')->once()->whenHappen(function ($cb) use (&$factory) {
$factory = $cb;
});

Actions::expectFired('cortex.routes')->once()->whenHappen(function ($routes) use(&$factory) {
Actions::expectFired('cortex.routes')->once()->whenHappen(function ($routes) use (&$factory) {
$factory($routes);
});

Expand All @@ -121,5 +121,4 @@ public function testMatchRedirectRoute()

assertTrue($do);
}

}
}
1 change: 0 additions & 1 deletion tests/src/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
class TestCase extends \PHPUnit_Framework_TestCase
{

protected function setUp()
{
parent::setUp();
Expand Down
1 change: 0 additions & 1 deletion tests/src/TestCaseFunctional.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/
class TestCaseFunctional extends TestCase
{

protected static function buildPsrRequest($url, $method = 'GET')
{
$parts = parse_url($url);
Expand Down
3 changes: 1 addition & 2 deletions tests/src/Unit/Controller/QueryVarsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
class QueryVarsControllerTest extends TestCase
{

public function testRun()
{
$wp = \Mockery::mock('WP');
Expand All @@ -31,4 +30,4 @@ public function testRun()
assertFalse($result);
assertSame(['foo' => 'bar'], $wp->query_vars);
}
}
}
5 changes: 2 additions & 3 deletions tests/src/Unit/Controller/RedirectControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/
class RedirectControllerTest extends TestCase
{

public function testRunDoNothingIfRedirectToIsInvalid()
{
Actions::expectAdded('cortex.exit.redirect')->never();
Expand Down Expand Up @@ -60,7 +59,7 @@ public function testRunAllStatusSettings()
$data = [
'redirect_to' => 'https://example.com',
'redirect_status' => 307,
'redirect_external' => true
'redirect_external' => true,
];

$wp = \Mockery::mock('WP');
Expand All @@ -69,4 +68,4 @@ public function testRunAllStatusSettings()

assertTrue($controller->run($data, $wp));
}
}
}
17 changes: 8 additions & 9 deletions tests/src/Unit/Group/GroupCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/
class GroupCollectionTest extends TestCase
{

public function testAddGroup()
{
$group = \Mockery::mock(GroupInterface::class);
Expand All @@ -47,27 +46,27 @@ public function testMergeGroup()
'id' => 'my_route',
'group' => 'test_group',
'vars' => [
'foo' => 'bar'
]
'foo' => 'bar',
],
]);

$group = new Group([
'id' => 'test_group',
'handler' => 'my_handler',
'host' => 'example.com',
'vars' => [
'meh' => 'meh'
]
'meh' => 'meh',
],
]);

$expected = [
'id' => 'my_route',
'group' => 'test_group',
'vars' => [
'foo' => 'bar'
'foo' => 'bar',
],
'handler' => 'my_handler',
'host' => 'example.com'
'host' => 'example.com',
];

$collection = new GroupCollection();
Expand Down Expand Up @@ -104,7 +103,7 @@ public function testMergeMultipleGroups()
$group2 = new Group([
'id' => 'group_2',
'paged' => false,
'merge_query_string' => true
'merge_query_string' => true,
]);

$expected = [
Expand All @@ -130,4 +129,4 @@ public function testMergeMultipleGroups()

assertSame($expected, $actual);
}
}
}
10 changes: 4 additions & 6 deletions tests/src/Unit/Group/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
class GroupTest extends TestCase
{

public function testIdWhenGiven()
{
$group = new Group(['id' => 'test_me']);
Expand All @@ -46,15 +45,15 @@ public function testToArrayStripsInvalid()
'handler' => '__return_true',
'meh' => 'meh',
'priority' => 0,
'id' => 'test_me'
'id' => 'test_me',
]);

$expected = [
'vars' => [],
'path' => '/',
'handler' => '__return_true',
'priority' => 0,
'id' => 'test_me'
'id' => 'test_me',
];

assertSame($expected, $group->toArray());
Expand All @@ -69,7 +68,7 @@ public function testArrayAccess()
'path' => '/',
'handler' => '__return_true',
'meh' => 'meh',
'priority' => 0
'priority' => 0,
]);

assertFalse($group->offsetExists('foo'));
Expand All @@ -90,5 +89,4 @@ public function testArrayAccess()
assertFalse($group->offsetExists('vars'));
assertSame('__return_true', $group['handler']);
}

}
}
8 changes: 3 additions & 5 deletions tests/src/Unit/Route/PriorityRouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
class PriorityRouteCollectionTest extends TestCase
{

public function testAddRoute()
{
$route1 = new Route(['id' => 'r_1']);
Expand Down Expand Up @@ -72,7 +71,7 @@ public function testPagedSingle()
$route = new Route([
'id' => 'route_example',
'path' => '/foo',
'paged' => RouteInterface::PAGED_SINGLE
'paged' => RouteInterface::PAGED_SINGLE,
]);

$collection = new PriorityRouteCollection();
Expand Down Expand Up @@ -100,7 +99,7 @@ public function testPagedArchive()
'id' => 'route_example',
'path' => '/bar',
'priority' => 32,
'paged' => RouteInterface::PAGED_ARCHIVE
'paged' => RouteInterface::PAGED_ARCHIVE,
]);

$collection = new PriorityRouteCollection();
Expand All @@ -121,5 +120,4 @@ public function testPagedArchive()
$i++;
}
}

}
}
4 changes: 1 addition & 3 deletions tests/src/Unit/Route/QueryRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
class QueryRouteTest extends TestCase
{

public function testArrayAccess()
{
$vars = function (array $vars) {
Expand Down Expand Up @@ -89,5 +88,4 @@ public function testId()
assertStringMatchesFormat('route_%s', $route1->id());
assertSame('route_2', $route2->id());
}

}
}
13 changes: 6 additions & 7 deletions tests/src/Unit/Route/RedirectRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
class RedirectRouteTest extends TestCase
{

public function testAutoAbsoluteRedirectToFromString()
{
Functions::when('home_url')->alias(function ($arg = '') {
Expand Down Expand Up @@ -95,7 +94,7 @@ public function testAutoAbsoluteRedirectToFromCallback()

$route = new RedirectRoute(
'/path/from',
function(array $args) {
function (array $args) {
return $args['foo'];
},
['priority' => 2]
Expand All @@ -117,7 +116,7 @@ public function testRedirectToInternalNullIfCallbackReturnNoString()
{
$route = new RedirectRoute(
'from',
function(array $args) {
function (array $args) {
return $args['bar'];
}
);
Expand Down Expand Up @@ -149,7 +148,7 @@ public function testAbsoluteRedirectToFromCallback()
{
$route = new RedirectRoute(
'/path/from',
function(array $args) {
function (array $args) {
return 'http://example.com/'.$args['foo'];
},
['priority' => 2]
Expand All @@ -171,7 +170,7 @@ public function testRedirectToExternalFromCallback()
{
$route = new RedirectRoute(
'/path/from',
function(array $args) {
function (array $args) {
return 'https://'.$args['sub'].'.bar.it/';
},
['redirect_external' => 1]
Expand All @@ -192,7 +191,7 @@ public function testRedirectToExternalNullIfCallbackReturnNoUrl()
{
$route = new RedirectRoute(
'/path/from',
function(array $args) {
function (array $args) {
return $args['sub'].'.bar.it/';
},
['redirect_external' => 1]
Expand Down Expand Up @@ -221,4 +220,4 @@ public function testStatusTo301IfBad()

assertSame($expectedVars, $route['vars']);
}
}
}
8 changes: 3 additions & 5 deletions tests/src/Unit/Route/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
class RouteTest extends TestCase
{

public function testArrayAccess()
{
$vars = function (array $vars) {
Expand All @@ -34,7 +33,7 @@ public function testArrayAccess()
'path' => '/',
'handler' => '__return_true',
'meh' => 'meh',
'priority' => 0
'priority' => 0,
]);

assertFalse($route->offsetExists('foo'));
Expand Down Expand Up @@ -64,7 +63,7 @@ public function testToArray()
'path' => 'foo/bar',
'vars' => ['foo' => 'bar'],
'meh' => ['foo' => 'bar'],
'priority' => 0
'priority' => 0,
]);

$array = $route->toArray();
Expand All @@ -90,5 +89,4 @@ public function testId()
assertStringMatchesFormat('route_%s', $route1->id());
assertSame('route_2', $route2->id());
}

}
}
Loading

0 comments on commit 3c2186b

Please sign in to comment.