Skip to content

Commit

Permalink
additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjgreen committed Sep 30, 2014
1 parent 513780e commit 54fea04
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions test/Dispatcher/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,42 @@ public function route()

public function anyIndex()
{
return 'testRoute';
return 'testRouteAnyIndex';
}

public function anyTest()
{
return 'testRoute';
return 'testRouteAnyTest';
}

public function getTest()
{
return 'testRoute';
return 'testRouteGetTest';
}

public function postTest()
{
return 'testRoute';
return 'testRoutePostTest';
}

public function putTest()
{
return 'testRoute';
return 'testRoutePutTest';
}

public function deleteTest()
{
return 'testRoute';
return 'testRouteDeleteTest';
}

public function headTest()
{
return 'testRoute';
return 'testRouteHeadTest';
}

public function optionsTest()
{
return 'testRoute';
return 'testRouteOptionsTest';
}

public function getCamelCaseHyphenated()
Expand Down Expand Up @@ -333,21 +333,47 @@ public function testValidMethods()
Route::OPTIONS,
), $this->router()->getValidMethods());
}

public function testAnyRespondsToDeletePutAndGet()
{
$r = $this->router();

$r->any('/user', function(){
return 'yes';
});

$this->assertEquals('yes', $this->dispatch($r, Route::GET, 'user'));
$this->assertEquals('yes', $this->dispatch($r, Route::DELETE, 'user'));
$this->assertEquals('yes', $this->dispatch($r, Route::PUT, 'user'));
$this->assertEquals('yes', $this->dispatch($r, Route::POST, 'user'));
$this->assertEquals('yes', $this->dispatch($r, Route::OPTIONS, 'user'));
$this->assertEquals('yes', $this->dispatch($r, 'MADE_UP_NON_STANDARD_METHOD', 'user'));
}

public function testRestfulControllerMethods()
{

$r = $this->router();

$r->controller('/user', __NAMESPACE__ . '\\Test');

$data = $r->getData();

$this->assertEquals($r->getValidMethods(), array_keys($data[0]['user/test']));

$this->assertEquals(array(Route::ANY), array_keys($data[0]['user']));
$this->assertEquals(array(Route::ANY), array_keys($data[0]['user/index']));

$this->assertEquals('testRouteAnyIndex', $this->dispatch($r, Route::GET, 'user'));
$this->assertEquals('testRouteAnyIndex', $this->dispatch($r, Route::POST, 'user'));
$this->assertEquals('testRouteAnyIndex', $this->dispatch($r, Route::PUT, 'user'));
$this->assertEquals('testRouteAnyIndex', $this->dispatch($r, Route::DELETE, 'user'));

$this->assertEquals('testRouteAnyIndex', $this->dispatch($r, Route::GET, 'user/index'));
$this->assertEquals('testRouteAnyIndex', $this->dispatch($r, Route::POST, 'user/index'));
$this->assertEquals('testRouteAnyIndex', $this->dispatch($r, Route::PUT, 'user/index'));
$this->assertEquals('testRouteAnyIndex', $this->dispatch($r, Route::DELETE, 'user/index'));

$this->assertEquals('hyphenated', $this->dispatch($r, Route::GET, 'user/camel-case-hyphenated'));

$this->assertEquals('joe', $this->dispatch($r, Route::GET, 'user/parameter/joe'));
Expand All @@ -357,9 +383,9 @@ public function testRestfulControllerMethods()
$this->assertEquals('default', $this->dispatch($r, Route::GET, 'user/parameter-optional'));
$this->assertEquals('joedefault', $this->dispatch($r, Route::GET, 'user/parameter-optional-required/joe'));
$this->assertEquals('joegreen', $this->dispatch($r, Route::GET, 'user/parameter-optional-required/joe/green'));

}


/**
* @expectedException \Phroute\Exception\HttpRouteNotFoundException
* @expectedExceptionMessage does not exist
Expand Down

0 comments on commit 54fea04

Please sign in to comment.