View
@@ -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>
View
@@ -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>
View
@@ -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]
View
@@ -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();
View
@@ -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
));
}
View
@@ -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
View
@@ -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);
}
}
View
@@ -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']);
}
}
}
View
@@ -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'));
}
}
View
@@ -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();