Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added more tests to check and make sure things were working.

  • Loading branch information...
commit 0cd3bb8811ee2dd3789ee854dd589fd69419af1e 1 parent 5185d25
Jacob Mather jmather authored
2  .gitignore
... ... @@ -1,2 +1,4 @@
1 1 composer.lock
2 2 vendor
  3 +.idea
  4 +*.iml
8 Tests/AcceptHeaderRoutingTest.php → Tests/MultipleControllerRoutingTest.php
@@ -12,7 +12,7 @@
12 12 use Silex\RedirectableUrlMatcher;
13 13 use Pff\ServiceProvider\AcceptHeaderServiceProvider as AcceptHeader;
14 14
15   -class RoutingTest extends WebTestCase
  15 +class MultipleControllerRoutingTest extends WebTestCase
16 16 {
17 17 /**
18 18 * Creates the application.
@@ -23,10 +23,10 @@ public function createApplication()
23 23 {
24 24 $app = new \Silex\Application();
25 25
26   - $app->register(new AcceptHeader\AcceptHeaderServiceProvider());
  26 + $app->register(new AcceptHeader\AcceptHeaderServiceProvider());
27 27
28 28
29   - /** @var $controllers1 VersionedRestControllerCollection */
  29 + /** @var $controllers1 ControllerCollection */
30 30 $controllers1 = $app['controllers_factory'];
31 31
32 32 $controllers1->get('/test', function($accept_header) use ($app) {
@@ -39,7 +39,7 @@ public function createApplication()
39 39 })->accept(array('application/ven.test.v1+json', 'application/ven.test.v1+xml'));
40 40
41 41
42   - /** @var $controllers1 VersionedRestControllerCollection */
  42 + /** @var $controllers1 ControllerCollection */
43 43 $controllers2 = $app['controllers_factory'];
44 44
45 45 $controllers1->get('/test', function($accept_header) use ($app) {
88 Tests/SingleControllerRoutingTest.php
... ... @@ -0,0 +1,88 @@
  1 +<?php
  2 +
  3 +namespace Pff\ServiceProvider\AcceptHeaderServiceProvider\Tests;
  4 +
  5 +use Silex\WebTestCase;
  6 +use Symfony\Component\HttpKernel\HttpKernel;
  7 +use Silex\Controller;
  8 +use Silex\ControllerCollection;
  9 +use Symfony\Component\HttpFoundation\Response;
  10 +use Symfony\Component\HttpFoundation\Request;
  11 +use Symfony\Component\HttpKernel\KernelEvents;
  12 +use Silex\RedirectableUrlMatcher;
  13 +use Pff\ServiceProvider\AcceptHeaderServiceProvider as AcceptHeader;
  14 +
  15 +class SingleControllerRoutingTest extends WebTestCase
  16 +{
  17 + /**
  18 + * Creates the application.
  19 + *
  20 + * @return HttpKernel
  21 + */
  22 + public function createApplication()
  23 + {
  24 + $app = new \Silex\Application();
  25 +
  26 + $app->register(new AcceptHeader\AcceptHeaderServiceProvider());
  27 +
  28 +
  29 + /** @var $controllers1 ControllerCollection */
  30 + $controllers1 = $app['controllers_factory'];
  31 +
  32 + $controllers1->get('/test', function($accept_header) use ($app) {
  33 + if ($accept_header == 'application/ven.test.v1+json')
  34 + $cont = json_encode(array('content' => 'hello'));
  35 + else
  36 + $cont = '<content>hello</content>';
  37 +
  38 + return new Response($cont, 200, array('Content-Type' => $accept_header));
  39 + })->accept(array('application/ven.test.v1+json', 'application/ven.test.v1+xml'));
  40 +
  41 +
  42 + $app->mount('/', $controllers1);
  43 +
  44 +
  45 + $app['debug'] = true;
  46 + unset($app['exception_handler']);
  47 +
  48 + return $app;
  49 + }
  50 +
  51 + public function testValidV1XMLCall()
  52 + {
  53 + $client = $this->createClient();
  54 +
  55 + $crawler = $client->request('GET', '/test', array(), array(), array('HTTP_ACCEPT' => 'application/ven.test.v1+xml'));
  56 +
  57 + $this->assertEquals(200, $client->getResponse()->getStatusCode());
  58 +
  59 + $result = $client->getResponse()->getContent();
  60 +
  61 + $this->assertEquals('<content>hello</content>', $result, 'response is correct');
  62 + }
  63 +
  64 + public function testValidV1JSONCall()
  65 + {
  66 + $client = $this->createClient();
  67 +
  68 + $crawler = $client->request('GET', '/test', array(), array(), array('HTTP_ACCEPT' => 'application/ven.test.v1+json'));
  69 +
  70 + $this->assertEquals(200, $client->getResponse()->getStatusCode());
  71 +
  72 + $result = $client->getResponse()->getContent();
  73 +
  74 + $this->assertEquals('{"content":"hello"}', $result, 'response is correct');
  75 + }
  76 +
  77 + /**
  78 + * @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  79 + */
  80 + public function testInvalidV3Call()
  81 + {
  82 + $client = $this->createClient();
  83 +
  84 + $crawler = $client->request('GET', '/test', array(), array(), array('HTTP_ACCEPT' => 'application/ven.test.v3+xml'));
  85 +
  86 + $this->assertEquals(404, $client->getResponse()->getStatusCode());
  87 + }
  88 +}

0 comments on commit 0cd3bb8

Please sign in to comment.
Something went wrong with that request. Please try again.