Browse Source

Merge pull request #874 from gerardroche/zend-framework-1

PHP: Add Zend framework 1
Hamilton Turner 10 years ago
parent
commit
60364eb26d
26 changed files with 704 additions and 0 deletions
  1. 1 0
      .travis.yml
  2. 41 0
      frameworks/PHP/php-zend-framework1/.gitignore
  3. 0 0
      frameworks/PHP/php-zend-framework1/__init__.py
  4. 6 0
      frameworks/PHP/php-zend-framework1/application/Bootstrap.php
  5. 19 0
      frameworks/PHP/php-zend-framework1/application/configs/application.ini
  6. 12 0
      frameworks/PHP/php-zend-framework1/application/controllers/DbController.php
  7. 20 0
      frameworks/PHP/php-zend-framework1/application/controllers/DbMultiController.php
  8. 54 0
      frameworks/PHP/php-zend-framework1/application/controllers/ErrorController.php
  9. 9 0
      frameworks/PHP/php-zend-framework1/application/controllers/JsonController.php
  10. 29 0
      frameworks/PHP/php-zend-framework1/application/views/scripts/error/error.phtml
  11. 9 0
      frameworks/PHP/php-zend-framework1/bash_profile.sh
  12. 25 0
      frameworks/PHP/php-zend-framework1/benchmark_config
  13. 6 0
      frameworks/PHP/php-zend-framework1/composer.json
  14. 133 0
      frameworks/PHP/php-zend-framework1/deploy/nginx.conf
  15. 9 0
      frameworks/PHP/php-zend-framework1/deploy/php-zend-framework
  16. 3 0
      frameworks/PHP/php-zend-framework1/install.sh
  17. 36 0
      frameworks/PHP/php-zend-framework1/lint.xml
  18. 34 0
      frameworks/PHP/php-zend-framework1/phpunit.xml.dist
  19. 16 0
      frameworks/PHP/php-zend-framework1/public/.htaccess
  20. 21 0
      frameworks/PHP/php-zend-framework1/public/index.php
  21. 26 0
      frameworks/PHP/php-zend-framework1/script/setup_dev_and_test_db.php
  22. 24 0
      frameworks/PHP/php-zend-framework1/setup.py
  23. 43 0
      frameworks/PHP/php-zend-framework1/test/application/controllers/DbControllerTest.php
  24. 76 0
      frameworks/PHP/php-zend-framework1/test/application/controllers/DbMultiControllerTest.php
  25. 30 0
      frameworks/PHP/php-zend-framework1/test/application/controllers/JsonControllerTest.php
  26. 22 0
      frameworks/PHP/php-zend-framework1/test/bootstrap.php

+ 1 - 0
.travis.yml

@@ -123,6 +123,7 @@ env:
     - "TESTDIR=PHP/php-yaf"
     - "TESTDIR=PHP/php-yaf"
     - "TESTDIR=PHP/php-yii2"
     - "TESTDIR=PHP/php-yii2"
     - "TESTDIR=PHP/php-zend-framework"
     - "TESTDIR=PHP/php-zend-framework"
+    - "TESTDIR=PHP/php-zend-framework1"
     - "TESTDIR=PHP/phreeze"
     - "TESTDIR=PHP/phreeze"
     - "TESTDIR=Python/bottle"
     - "TESTDIR=Python/bottle"
     - "TESTDIR=Python/django"
     - "TESTDIR=Python/django"

+ 41 - 0
frameworks/PHP/php-zend-framework1/.gitignore

@@ -0,0 +1,41 @@
+# See http://help.github.com/ignore-files/ for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor or
+# operating system, you probably want to add a global ignore instead:
+#   git config --global core.excludesfile ~/.gitignore_global
+
+/vendor
+/build
+/dist
+.DS_Store
+/tags
+.idea
+composer.lock
+cache.properties
+phpunit.xml
+tmp
+
+# VIM
+[._]*.s[a-w][a-z]
+[._]s[a-w][a-z]
+*.un~
+Session.vim
+.netrwhist
+*~
+
+# Sublime Text
+*.sublime-workspace
+
+# Netbeans IDE
+nbproject
+
+# Eclipse IDE
+.buildpath
+.project
+.settings/
+
+# Notepad++
+nppBackup
+
+# ctags
+tags

+ 0 - 0
frameworks/PHP/php-zend-framework1/__init__.py


+ 6 - 0
frameworks/PHP/php-zend-framework1/application/Bootstrap.php

@@ -0,0 +1,6 @@
+<?php
+
+class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
+{
+
+}

+ 19 - 0
frameworks/PHP/php-zend-framework1/application/configs/application.ini

@@ -0,0 +1,19 @@
+[production]
+phpSettings.display_startup_errors = 1
+phpSettings.display_errors = 1
+bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
+bootstrap.class = "Bootstrap"
+resources.frontcontroller.controllerDirectory = APPLICATION_PATH "/controllers"
+resources.frontcontroller.params.displayExceptions = 1
+
+resources.db.adapter = "pdo_mysql"
+resources.db.params.host = "localhost"
+resources.db.params.charset = "utf8"
+resources.db.params.dbname = "hello_world"
+resources.db.params.username = "benchmarkdbuser"
+resources.db.params.password = "benchmarkdbpass"
+
+[development : production]
+phpSettings.display_startup_errors = 1
+phpSettings.display_errors = 1
+resources.frontController.params.displayExceptions = 1

+ 12 - 0
frameworks/PHP/php-zend-framework1/application/controllers/DbController.php

@@ -0,0 +1,12 @@
+<?php
+
+class DbController extends Zend_Controller_Action
+{
+    public function indexAction()
+    {
+        $table = new Zend_Db_Table('World');
+        $result = $table->fetchRow(array('id = ?' => mt_rand(1, 10000)));
+
+        $this->_helper->json->sendJson($result->toArray());
+    }
+}

+ 20 - 0
frameworks/PHP/php-zend-framework1/application/controllers/DbMultiController.php

@@ -0,0 +1,20 @@
+<?php
+
+class DbMultiController extends Zend_Controller_Action
+{
+    public function indexAction()
+    {
+        $queries = (int) $this->getParam('queries', 1);
+        $queries = max(1, $queries);
+        $queries = min(500, $queries);
+
+        $table = new Zend_Db_Table('World');
+
+        $worlds = array();
+        for ($i = 0; $i < $queries; $i += 1) {
+            $worlds[] = $table->fetchRow(array('id = ?' => mt_rand(1,10000)))->toArray();
+        }
+
+        $this->_helper->json->sendJson($worlds);
+    }
+}

+ 54 - 0
frameworks/PHP/php-zend-framework1/application/controllers/ErrorController.php

@@ -0,0 +1,54 @@
+<?php
+
+class ErrorController extends Zend_Controller_Action
+{
+    public function errorAction()
+    {
+        $errors = $this->_getParam('error_handler');
+
+        if (!$errors || !$errors instanceof ArrayObject) {
+            $this->view->message = 'You have reached the error page';
+            return;
+        }
+
+        switch ($errors->type) {
+            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
+            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
+            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
+                // 404 error -- controller or action not found
+                $this->getResponse()->setHttpResponseCode(404);
+                $priority = Zend_Log::NOTICE;
+                $this->view->message = 'Page not found';
+                break;
+            default:
+                // application error
+                $this->getResponse()->setHttpResponseCode(500);
+                $priority = Zend_Log::CRIT;
+                $this->view->message = 'Application error';
+                break;
+        }
+
+        // Log exception, if logger available
+        if ($log = $this->getLog()) {
+            $log->log($this->view->message, $priority, $errors->exception);
+            $log->log('Request Parameters', $priority, $errors->request->getParams());
+        }
+
+        // conditionally display exceptions
+        if ($this->getInvokeArg('displayExceptions') == true) {
+            $this->view->exception = $errors->exception;
+        }
+
+        $this->view->request   = $errors->request;
+    }
+
+    public function getLog()
+    {
+        $bootstrap = $this->getInvokeArg('bootstrap');
+        if (!$bootstrap->hasResource('Log')) {
+            return false;
+        }
+        $log = $bootstrap->getResource('Log');
+        return $log;
+    }
+}

+ 9 - 0
frameworks/PHP/php-zend-framework1/application/controllers/JsonController.php

@@ -0,0 +1,9 @@
+<?php
+
+class JsonController extends Zend_Controller_Action
+{
+    public function indexAction()
+    {
+        $this->_helper->json->sendJson(array('message' => 'Hello, World!'));
+    }
+}

+ 29 - 0
frameworks/PHP/php-zend-framework1/application/views/scripts/error/error.phtml

@@ -0,0 +1,29 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+  <title>Zend Framework Default Application</title>
+</head>
+<body>
+  <h1>An error occurred</h1>
+  <h2><?php echo $this->message ?></h2>
+
+  <?php if (isset($this->exception)): ?>
+
+  <h3>Exception information:</h3>
+  <p>
+      <b>Message:</b> <?php echo $this->exception->getMessage() ?>
+  </p>
+
+  <h3>Stack trace:</h3>
+  <pre><?php echo $this->exception->getTraceAsString() ?>
+  </pre>
+
+  <h3>Request Parameters:</h3>
+  <pre><?php echo $this->escape(var_export($this->request->getParams(), true)) ?>
+  </pre>
+
+  <?php endif ?>
+
+</body>
+</html>

+ 9 - 0
frameworks/PHP/php-zend-framework1/bash_profile.sh

@@ -0,0 +1,9 @@
+#!/bin/bash
+
+export PHP_HOME=${IROOT}/php-5.5.17
+
+export PHP_FPM=$PHP_HOME/sbin/php-fpm
+
+export COMPOSER_HOME=${IROOT}/php-composer
+
+export PATH="$COMPOSER_HOME:$PHP_HOME/bin:$PHP_HOME/sbin:$PATH"

+ 25 - 0
frameworks/PHP/php-zend-framework1/benchmark_config

@@ -0,0 +1,25 @@
+{
+  "framework": "ZendFramework1",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/db-multi?queries=",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "MySQL",
+      "framework": "ZendFramework1",
+      "language": "PHP",
+      "orm": "Full",
+      "platform": "PHP-FPM",
+      "webserver": "nginx",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "ZendFramework1",
+      "notes": "",
+      "versus": "php"
+    }
+  }]
+}

+ 6 - 0
frameworks/PHP/php-zend-framework1/composer.json

@@ -0,0 +1,6 @@
+{
+    "require": {
+        "php": ">=5.2.11",
+        "zendframework/zendframework1": "~1.12"
+    }
+}

+ 133 - 0
frameworks/PHP/php-zend-framework1/deploy/nginx.conf

@@ -0,0 +1,133 @@
+#user  nobody;
+worker_processes  8;
+
+#error_log  logs/error.log;
+#error_log  logs/error.log  notice;
+#error_log  logs/error.log  info;
+error_log stderr error;
+
+#pid        logs/nginx.pid;
+
+
+events {
+    worker_connections  1024;
+}
+
+
+http {
+    include       /usr/local/nginx/conf/mime.types;
+    default_type  application/octet-stream;
+
+    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
+    #                  '$status $body_bytes_sent "$http_referer" '
+    #                  '"$http_user_agent" "$http_x_forwarded_for"';
+
+    #access_log  logs/access.log  main;
+    access_log off;
+
+    sendfile        on;
+    #tcp_nopush     on;
+
+    #keepalive_timeout  0;
+    keepalive_timeout  65;
+
+    #gzip  on;
+
+    upstream fastcgi_backend {
+        server 127.0.0.1:9001;
+        keepalive 32;
+    }
+
+    server {
+        listen       8080;
+        server_name  localhost;
+
+        #charset koi8-r;
+
+        #access_log  logs/host.access.log  main;
+
+        #location / {
+        #    root   html;
+        #    index  index.html index.htm;
+        #}
+
+        #error_page  404              /404.html;
+
+        # redirect server error pages to the static page /50x.html
+        #
+        #error_page   500 502 503 504  /50x.html;
+        #location = /50x.html {
+        #    root   html;
+        #}
+
+        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
+        #
+        #location ~ \.php$ {
+        #    proxy_pass   http://127.0.0.1;
+        #}
+
+        root /home/tfb/FrameworkBenchmarks/php-zend-framework1/public/;
+        index  index.php;
+
+        location / {
+            try_files $uri $uri/ /index.php?$uri&$args;
+        }
+
+        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
+        #
+        location ~ \.php$ {
+            try_files $uri =404;
+            fastcgi_pass   fastcgi_backend;
+            fastcgi_keep_conn on;
+            fastcgi_index  index.php;
+#            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
+            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
+            include        /usr/local/nginx/conf/fastcgi_params;
+        }
+
+        # deny access to .htaccess files, if Apache's document root
+        # concurs with nginx's one
+        #
+        #location ~ /\.ht {
+        #    deny  all;
+        #}
+    }
+
+
+    # another virtual host using mix of IP-, name-, and port-based configuration
+    #
+    #server {
+    #    listen       8000;
+    #    listen       somename:8080;
+    #    server_name  somename  alias  another.alias;
+
+    #    location / {
+    #        root   html;
+    #        index  index.html index.htm;
+    #    }
+    #}
+
+
+    # HTTPS server
+    #
+    #server {
+    #    listen       443;
+    #    server_name  localhost;
+
+    #    ssl                  on;
+    #    ssl_certificate      cert.pem;
+    #    ssl_certificate_key  cert.key;
+
+    #    ssl_session_timeout  5m;
+
+    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
+    #    ssl_ciphers  HIGH:!aNULL:!MD5;
+    #    ssl_prefer_server_ciphers   on;
+
+    #    location / {
+    #        root   html;
+    #        index  index.html index.htm;
+    #    }
+    #}
+
+}

+ 9 - 0
frameworks/PHP/php-zend-framework1/deploy/php-zend-framework

@@ -0,0 +1,9 @@
+<VirtualHost *:8080>
+  Alias /php-zend-framework1/ "/home/ubuntu/FrameworkBenchmarks/php-zend-framework1/public/"
+  <Directory /home/ubuntu/FrameworkBenchmarks/php-zend-framework1/public/>
+          Options Indexes FollowSymLinks MultiViews
+          #AllowOverride None
+          Order allow,deny
+          allow from all
+  </Directory>
+</VirtualHost>

+ 3 - 0
frameworks/PHP/php-zend-framework1/install.sh

@@ -0,0 +1,3 @@
+#!/bin/bash
+
+fw_depends php composer nginx

+ 36 - 0
frameworks/PHP/php-zend-framework1/lint.xml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project basedir="." default="lint">
+
+    <property name="src.dir" location="" />
+
+    <target name="lint" description="Run php syntax check (lint)">
+        <apply executable="php" failonerror="true">
+            <arg value="-l" />
+            <fileset dir="${src.dir}">
+
+                <include name="**/*.php" />
+                <include name="**/*.phtml" />
+
+                <!--
+
+                Zend Framework shouldn't have any syntax errors, but let's just
+                be double sure.
+
+                Excluding tests and other non-runtime stuff
+
+                -->
+                <exclude name="**/vendor/zendframework/zendframework1/bin/**" />
+                <exclude name="**/vendor/zendframework/zendframework1/demos/**" />
+                <exclude name="**/vendor/zendframework/zendframework1/documentation/**" />
+                <exclude name="**/vendor/zendframework/zendframework1/puppet/**" />
+                <exclude name="**/vendor/zendframework/zendframework1/resources/**" />
+                <exclude name="**/vendor/zendframework/zendframework1/tests/**" />
+
+                <!-- cache -->
+                <modified />
+
+            </fileset>
+        </apply>
+    </target>
+
+</project>

+ 34 - 0
frameworks/PHP/php-zend-framework1/phpunit.xml.dist

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit backupGlobals="false"
+         backupStaticAttributes="false"
+         beStrictAboutOutputDuringTests="false"
+         beStrictAboutTestsThatDoNotTestAnything="true"
+         beStrictAboutTestSize="true"
+         beStrictAboutTodoAnnotatedTests="true"
+         bootstrap="test/bootstrap.php"
+         checkForUnintentionallyCoveredCode="true"
+         colors="true"
+         convertErrorsToExceptions="true"
+         convertNoticesToExceptions="true"
+         convertWarningsToExceptions="true"
+         strict="false"
+         verbose="true"
+         >
+
+    <testsuites>
+        <testsuite name="unit">
+            <directory suffix="Test.php">test</directory>
+        </testsuite>
+    </testsuites>
+
+    <filter>
+        <whitelist processUncoveredFilesFromWhitelist="true">
+            <directory suffix=".php">application</directory>
+        </whitelist>
+    </filter>
+
+    <!-- <logging>
+        <log type="coverage-html" target="build/coverage" />
+    </logging> -->
+
+</phpunit>

+ 16 - 0
frameworks/PHP/php-zend-framework1/public/.htaccess

@@ -0,0 +1,16 @@
+RewriteEngine On
+# The following rule tells Apache that if the requested filename
+# exists, simply serve it.
+RewriteCond %{REQUEST_FILENAME} -s [OR]
+RewriteCond %{REQUEST_FILENAME} -l [OR]
+RewriteCond %{REQUEST_FILENAME} -d
+RewriteRule ^.*$ - [NC,L]
+# The following rewrites all other queries to index.php. The
+# condition ensures that if you are using Apache aliases to do
+# mass virtual hosting, the base path will be prepended to
+# allow proper resolution of the index.php file; it will work
+# in non-aliased environments as well, providing a safe, one-size
+# fits all solution.
+RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
+RewriteRule ^(.*)$ - [E=BASE:%1]
+RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

+ 21 - 0
frameworks/PHP/php-zend-framework1/public/index.php

@@ -0,0 +1,21 @@
+<?php
+
+// Define path to application directory
+defined('APPLICATION_PATH')
+    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
+
+// Define application environment
+defined('APPLICATION_ENV')
+    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
+
+set_include_path(realpath(dirname(__FILE__) . '/../vendor/zendframework/zendframework1/library'));
+
+require_once 'Zend/Application.php';
+
+// Create application, bootstrap, and run
+$application = new Zend_Application(
+    APPLICATION_ENV,
+    APPLICATION_PATH . '/configs/application.ini'
+);
+$application->bootstrap()
+            ->run();

+ 26 - 0
frameworks/PHP/php-zend-framework1/script/setup_dev_and_test_db.php

@@ -0,0 +1,26 @@
+<?php
+
+set_include_path(realpath(dirname(__FILE__) . '/../vendor/zendframework/zendframework1/library'));
+
+require_once 'Zend/Db/Adapter/Pdo/Mysql.php';
+$db = new Zend_Db_Adapter_Pdo_Mysql(array(
+    'host' => 'localhost',
+    'charset' => 'utf8',
+    'dbname'   => 'hello_world',
+    'username' => 'benchmarkdbuser',
+    'password' => 'benchmarkdbpass'
+));
+
+$db->exec('DROP TABLE IF EXISTS `World`;');
+$db->exec('CREATE TABLE `World` (
+  `id` int(11) NOT NULL,
+  `randomNumber` int(11) NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
+
+for ($i=1; $i <= 10000; $i++) {
+    $db->insert('World', array(
+        'id' => $i,
+        'randomNumber' => $i
+    ));
+}

+ 24 - 0
frameworks/PHP/php-zend-framework1/setup.py

@@ -0,0 +1,24 @@
+import subprocess
+import sys
+import setup_util
+
+def start(args, logfile, errfile):
+  setup_util.replace_text("php-zend-framework1/application/configs/application.ini", "host = \"localhost\"", "host = \"" + args.database_host + "\"")
+  setup_util.replace_text("php-zend-framework1/deploy/nginx.conf", "root .*\/FrameworkBenchmarks/php-zend-framework1", "root " + args.troot)
+
+  try:
+    subprocess.check_call("composer.phar install", shell=True, cwd="php-zend-framework1", stderr=errfile, stdout=logfile)
+    subprocess.check_call("sudo chown -R www-data:www-data php-zend-framework1", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.check_call("sudo $PHP_FPM --fpm-config $FWROOT/config/php-fpm.conf -g $TROOT/deploy/php-fpm.pid", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c $TROOT/deploy/nginx.conf", shell=True, stderr=errfile, stdout=logfile)
+    return 0
+  except subprocess.CalledProcessError:
+    return 1
+def stop(logfile, errfile):
+  try:
+    subprocess.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.call("sudo kill -QUIT $( cat $TROOT/deploy/php-fpm.pid )", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.check_call("sudo chown -R $USER:$USER php-zend-framework1", shell=True, stderr=errfile, stdout=logfile)
+    return 0
+  except subprocess.CalledProcessError:
+    return 1

+ 43 - 0
frameworks/PHP/php-zend-framework1/test/application/controllers/DbControllerTest.php

@@ -0,0 +1,43 @@
+<?php
+
+class DbControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
+{
+    protected function setUp()
+    {
+        $this->bootstrap = new Zend_Application(
+            APPLICATION_ENV,
+            APPLICATION_PATH . '/configs/application.ini'
+        );
+
+        parent::setUp();
+    }
+
+    public function testType2SingleDatabaseQuery()
+    {
+        $this->dispatch('/db');
+
+        $this->assertModule('default');
+        $this->assertController('db');
+        $this->assertAction('index');
+        $this->assertResponseCode(200);
+        $this->assertHeaderRegex('Content-Type', '#^application/json$#');
+
+        $content = $this->getResponse()->getBody();
+
+        $this->assertRegExp('#^{"id"\:"\d+","randomNumber":"\d+"}$#', $content);
+
+        $decodedContent = json_decode($content, true);
+
+        $this->assertTrue(json_last_error() === JSON_ERROR_NONE, 'Json decode failure');
+
+        $this->assertArrayHasKey('id', $decodedContent);
+        $this->assertGreaterThan(0, $decodedContent['id']);
+        $this->assertLessThan(10000, $decodedContent['id']);
+
+        $this->assertArrayHasKey('randomNumber', $decodedContent);
+        $this->assertGreaterThan(0, $decodedContent['randomNumber']);
+        $this->assertLessThan(10000, $decodedContent['randomNumber']);
+
+        $this->assertCount(2, $decodedContent);
+    }
+}

+ 76 - 0
frameworks/PHP/php-zend-framework1/test/application/controllers/DbMultiControllerTest.php

@@ -0,0 +1,76 @@
+<?php
+
+class DbMultiControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
+{
+    protected function setUp()
+    {
+        $this->bootstrap = new Zend_Application(
+            APPLICATION_ENV,
+            APPLICATION_PATH . '/configs/application.ini'
+        );
+
+        parent::setUp();
+    }
+
+    public function testType3MultipleDatabaseQueries()
+    {
+        $this->dispatch('/db-multi?queries=2');
+        $this->assertResponseResultsEquals(2, $this->getResponse()->getBody());
+    }
+
+    public function testType3MultipleDatabaseQueryLessThan1DefaultsTo1()
+    {
+        $this->dispatch('/db-multi?queries=-1');
+        $this->assertResponseResultsEquals(1, $this->getResponse()->getBody());
+    }
+
+    public function testType3MultipleDatabaseQueryMoreThan500DefaultsTo500()
+    {
+        $this->dispatch('/db-multi?queries=501');
+        $this->assertResponseResultsEquals(500, $this->getResponse()->getBody());
+    }
+
+    public function testType3MultipleDatabaseQueryNotAnIntDefaultsTo1()
+    {
+        $this->dispatch('/db-multi?queries=foobar');
+        $this->assertResponseResultsEquals(1, $this->getResponse()->getBody());
+    }
+
+    public function testType3MultipleDatabaseQueryNoQueriesParamDefaultsTo1()
+    {
+        $this->dispatch('/db-multi');
+        $this->assertResponseResultsEquals(1, $this->getResponse()->getBody());
+    }
+    /**
+     * Helper assertion
+     *
+     * @param  int $expectedCount
+     * @param  string $content
+     */
+    protected function assertResponseResultsEquals($expectedCount, $content)
+    {
+        $this->assertModule('default');
+        $this->assertController('db-multi');
+        $this->assertAction('index');
+        $this->assertResponseCode(200);
+        $this->assertHeaderRegex('Content-Type', '#^application/json$#');
+
+        $results = json_decode($content, true);
+
+        $this->assertTrue(json_last_error() === JSON_ERROR_NONE, 'Json decode failure');
+
+        $this->assertCount($expectedCount, $results);
+
+        $count = count($results);
+        for ($i = 0; $i < $count; $i++) {
+
+            $this->assertArrayHasKey('id', $results[$i]);
+            $this->assertGreaterThan(0, $results[$i]['id']);
+            $this->assertLessThan(10000, $results[$i]['id']);
+
+            $this->assertArrayHasKey('randomNumber', $results[$i]);
+            $this->assertGreaterThan(0, $results[$i]['randomNumber']);
+            $this->assertLessThan(10000, $results[$i]['randomNumber']);
+        }
+    }
+}

+ 30 - 0
frameworks/PHP/php-zend-framework1/test/application/controllers/JsonControllerTest.php

@@ -0,0 +1,30 @@
+<?php
+
+class JsonControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
+{
+    protected function setUp()
+    {
+        $this->bootstrap = new Zend_Application(
+            APPLICATION_ENV,
+            APPLICATION_PATH . '/configs/application.ini'
+        );
+
+        parent::setUp();
+    }
+
+    public function testType1JsonSerialization()
+    {
+        $this->dispatch('/json');
+
+        $this->assertModule('default');
+        $this->assertController('json');
+        $this->assertAction('index');
+        $this->assertResponseCode(200);
+        $this->assertHeaderRegex('Content-Type', '#^application/json$#');
+
+        $content = $this->getResponse()->getBody();
+
+        $this->assertSame('{"message":"Hello, World!"}', $content);
+        $this->assertEquals(27, iconv_strlen($content, 'UTF-8'));
+    }
+}

+ 22 - 0
frameworks/PHP/php-zend-framework1/test/bootstrap.php

@@ -0,0 +1,22 @@
+<?php
+
+ini_set('error_reporting', -1);
+ini_set('display_errors', 1);
+ini_set('display_startup_errors', 1);
+ini_set('log_errors', 0);
+ini_set('date.timezone', 'UTC');
+ini_set('max_execution_time', 0);
+
+// Define path to application directory
+defined('APPLICATION_PATH')
+    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
+
+// Define application environment
+defined('APPLICATION_ENV')
+    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));
+
+// Ensure library/ is on include_path
+set_include_path(realpath(dirname(__FILE__) . '/../vendor/zendframework/zendframework1/library'));
+
+require_once 'Zend/Loader/Autoloader.php';
+Zend_Loader_Autoloader::getInstance();