Browse Source

Fortune testcase for Symfony 2

Skamander 12 years ago
parent
commit
af2402ece7

+ 1 - 0
php-symfony2/.gitignore

@@ -2,6 +2,7 @@
 /app/logs
 /app/logs
 /bin
 /bin
 /vendors
 /vendors
+/vendor
 /build
 /build
 /dist
 /dist
 .DS_Store
 .DS_Store

+ 9 - 0
php-symfony2/README.md

@@ -14,6 +14,11 @@ Uses the Symfony 2/Doctrine 2 Entity functionality.
 * [DB test controller](src/Skamander/BenchmarkBundle/Controller/BenchController.php)
 * [DB test controller](src/Skamander/BenchmarkBundle/Controller/BenchController.php)
 * [DB test model](src/Skamander/BenchmarkBundle/Entity/World.php)
 * [DB test model](src/Skamander/BenchmarkBundle/Entity/World.php)
 
 
+### Template Test
+Uses Symfony's template engine 'Twig'
+
+* [Template test controller](src/Skamander/BenchmarkBundle/Controller/BenchController.php)
+
 
 
 ## Infrastructure Software Versions
 ## Infrastructure Software Versions
 The tests were run with:
 The tests were run with:
@@ -35,3 +40,7 @@ http://localhost/db
 ### Variable Query Test
 ### Variable Query Test
     
     
 http://localhost/db?queries=2
 http://localhost/db?queries=2
+
+### Templating Test
+
+http://localhost/fortunes

+ 0 - 1
php-symfony2/app/Resources/views/base.html.twig

@@ -4,7 +4,6 @@
         <meta charset="UTF-8" />
         <meta charset="UTF-8" />
         <title>{% block title %}Welcome!{% endblock %}</title>
         <title>{% block title %}Welcome!{% endblock %}</title>
         {% block stylesheets %}{% endblock %}
         {% block stylesheets %}{% endblock %}
-        <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
     </head>
     </head>
     <body>
     <body>
         {% block body %}{% endblock %}
         {% block body %}{% endblock %}

+ 1 - 0
php-symfony2/benchmark_config

@@ -6,6 +6,7 @@
       "json_url": "/json",
       "json_url": "/json",
       "db_url": "/db",
       "db_url": "/db",
       "query_url": "/db?queries=",
       "query_url": "/db?queries=",
+      "fortune_url": "/fortunes",
       "port": 8080,
       "port": 8080,
       "sort": 51
       "sort": 51
     }
     }

+ 31 - 0
php-symfony2/src/Skamander/BenchmarkBundle/Controller/BenchController.php

@@ -4,8 +4,10 @@ namespace Skamander\BenchmarkBundle\Controller;
 
 
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
 use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Request;
+use Skamander\BenchmarkBundle\Entity\Fortune;
 
 
 class BenchController extends Controller
 class BenchController extends Controller
 {
 {
@@ -37,4 +39,33 @@ class BenchController extends Controller
 
 
         return new JsonResponse($worlds);
         return new JsonResponse($worlds);
     }
     }
+
+    /**
+     * @Route("/fortunes", name="_fortunes")
+     * @Template
+     */
+    public function fortunesAction()
+    {
+        $repo = $this->getDoctrine()
+            ->getRepository('SkamanderBenchmarkBundle:Fortune');
+        $fortunes = $repo->findAll();
+
+        $runtimeFortune = new Fortune();
+        $runtimeFortune->setId(0)
+            ->setMessage('Additional fortune added at request time.');
+
+        $fortunes[] = $runtimeFortune;
+
+        usort($fortunes, function($left, $right) {
+            if ($left->message === $right->message) {
+                return 0;
+            } else if ($left->message > $right->message) {
+                return 1;
+            } else {
+                return -1;
+            }
+        });
+
+        return ['fortunes' => $fortunes];
+    }
 }
 }

+ 69 - 0
php-symfony2/src/Skamander/BenchmarkBundle/Entity/Fortune.php

@@ -0,0 +1,69 @@
+<?php
+
+namespace Skamander\BenchmarkBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Entity
+ * @ORM\Table(name="Fortune")
+ */
+class Fortune
+{
+    /**
+     * @ORM\Id
+     * @ORM\Column(type="integer")
+     */
+    public $id;
+
+    /**
+     * @ORM\Column(type="string")
+     */
+    public $message;
+
+    /**
+     * Set id
+     *
+     * @param integer $id
+     * @return Fortune
+     */
+    public function setId($id)
+    {
+        $this->id = $id;
+
+        return $this;
+    }
+
+    /**
+     * Get id
+     *
+     * @return integer
+     */
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    /**
+     * Set message
+     *
+     * @param string $message
+     * @return Fortune
+     */
+    public function setMessage($message)
+    {
+        $this->message = $message;
+
+        return $this;
+    }
+
+    /**
+     * Get message
+     *
+     * @return string
+     */
+    public function getMessage()
+    {
+        return $this->message;
+    }
+}

+ 20 - 0
php-symfony2/src/Skamander/BenchmarkBundle/Resources/views/Bench/fortunes.html.twig

@@ -0,0 +1,20 @@
+{% extends "SkamanderBenchmarkBundle::layout.html.twig" %}
+
+{% block title "Fortunes" %}
+
+{% block content %}
+    <table>
+        <tr>
+            <th>id</th>
+            <th>message</th>
+        </tr>
+
+        {% for fortune in fortunes %}
+            <tr>
+                <td>{{ fortune.id }}</td>
+                <td>{{ fortune.message }}</td>
+            </tr>
+        {% endfor %}
+
+    </table>
+{% endblock %}

+ 9 - 0
php-symfony2/src/Skamander/BenchmarkBundle/Resources/views/layout.html.twig

@@ -0,0 +1,9 @@
+{% extends '::base.html.twig' %}
+
+{% block title 'Benchmark Bundle' %}
+
+{% block body %}
+    <div class="block">
+        {% block content %}{% endblock %}
+    </div>
+{% endblock %}