Skip to content

Commit

Permalink
Added some meat to context files
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelloDuarte committed Dec 11, 2012
1 parent eb974f8 commit 5af445c
Show file tree
Hide file tree
Showing 15 changed files with 367 additions and 11 deletions.
70 changes: 70 additions & 0 deletions .zfproject.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0"?>
<projectProfile type="default" version="1.11.11">
<projectDirectory>
<projectProfileFile filesystemName=".zfproject.xml"/>
<applicationDirectory classNamePrefix="Application_">
<apisDirectory enabled="false"/>
<configsDirectory>
<applicationConfigFile type="ini"/>
</configsDirectory>
<controllersDirectory>
<controllerFile controllerName="Index">
<actionMethod actionName="index"/>
</controllerFile>
<controllerFile controllerName="Error"/>
</controllersDirectory>
<formsDirectory enabled="false"/>
<layoutsDirectory enabled="false"/>
<modelsDirectory/>
<modulesDirectory enabled="false"/>
<viewsDirectory>
<viewScriptsDirectory>
<viewControllerScriptsDirectory forControllerName="Index">
<viewScriptFile forActionName="index"/>
</viewControllerScriptsDirectory>
<viewControllerScriptsDirectory forControllerName="Error">
<viewScriptFile forActionName="error"/>
</viewControllerScriptsDirectory>
</viewScriptsDirectory>
<viewHelpersDirectory/>
<viewFiltersDirectory enabled="false"/>
</viewsDirectory>
<bootstrapFile filesystemName="Bootstrap.php"/>
</applicationDirectory>
<dataDirectory enabled="false">
<cacheDirectory enabled="false"/>
<searchIndexesDirectory enabled="false"/>
<localesDirectory enabled="false"/>
<logsDirectory enabled="false"/>
<sessionsDirectory enabled="false"/>
<uploadsDirectory enabled="false"/>
</dataDirectory>
<docsDirectory>
<file filesystemName="README.txt"/>
</docsDirectory>
<libraryDirectory>
<zfStandardLibraryDirectory enabled="false"/>
</libraryDirectory>
<publicDirectory>
<publicStylesheetsDirectory enabled="false"/>
<publicScriptsDirectory enabled="false"/>
<publicImagesDirectory enabled="false"/>
<publicIndexFile filesystemName="index.php"/>
<htaccessFile filesystemName=".htaccess"/>
</publicDirectory>
<projectProvidersDirectory enabled="false"/>
<temporaryDirectory enabled="false"/>
<testsDirectory>
<testPHPUnitConfigFile filesystemName="phpunit.xml"/>
<testPHPUnitBootstrapFile filesystemName="bootstrap.php"/>
<testApplicationDirectory>
<testApplicationControllerDirectory>
<testApplicationControllerFile forControllerName="Index">
<testApplicationActionMethod forActionName="index"/>
</testApplicationControllerFile>
</testApplicationControllerDirectory>
</testApplicationDirectory>
<testLibraryDirectory/>
</testsDirectory>
</projectDirectory>
</projectProfile>
8 changes: 8 additions & 0 deletions application/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{


}

20 changes: 20 additions & 0 deletions application/configs/application.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
58 changes: 58 additions & 0 deletions application/controllers/ErrorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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;
}


}

18 changes: 18 additions & 0 deletions application/controllers/IndexController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

class IndexController extends Zend_Controller_Action
{

public function init()
{
/* Initialize action controller here */
}

public function indexAction()
{
// action body
}


}

29 changes: 29 additions & 0 deletions application/views/scripts/error/error.phtml
Original file line number Diff line number Diff line change
@@ -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>
3 changes: 3 additions & 0 deletions application/views/scripts/index/index.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<form>
<input type="submit" id="start" />
</form>
30 changes: 30 additions & 0 deletions docs/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
README
======

This directory should be used to place project specfic documentation including
but not limited to project notes, generated API/phpdoc documentation, or
manual files generated or hand written. Ideally, this directory would remain
in your development environment only and should not be deployed with your
application to it's final production location.


Setting Up Your VHOST
=====================

The following is a sample VHOST you might want to consider for your project.

<VirtualHost *:80>
DocumentRoot "/md/dev/php/tictactoe/public"
ServerName tictactoe.local

# This should be omitted in the production environment
SetEnv APPLICATION_ENV development

<Directory "/md/dev/php/tictactoe/public">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

</VirtualHost>
40 changes: 31 additions & 9 deletions features/bootstrap/PlayerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;

use Behat\MinkExtension\Context\MinkAwareInterface,
Behat\Mink\Mink;


class PlayerContext extends BehatContext implements MinkAwareInterface
{
const URL = "http://tictactoe.dev";
private $mink;
private $minkParameters;

Expand All @@ -23,14 +27,38 @@ public function setMinkParameters(array $parameters)
$this->minkParameters = $parameters;
}

/**
* @Given /^I am on the "([^"]*)"$/
*/
public function iAmOnThe($page)
{
$pages = array(
'home page' => ''
);
$this->mink->getSession()->visit(self::URL . "/$pages[$page]");
}

/**
* @Given /^I am "([^"]*)"$/
*/
public function iAm($arg1)
public function iAm($page)
{
throw new PendingException();
}

/**
* @When /^I click on "([^"]*)"$/
*/
public function iClickOn($button)
{
$buttons = array(
'start a game' => 'start'
);
$homePage = $this->mink->getSession()->getPage();
$startButton = $homePage->find('css', '#start');
$startButton->click();
}

/**
* @Given /^I Want to start a game$/
*/
Expand All @@ -44,7 +72,7 @@ public function iWantToStartAGame()
*/
public function iShouldGetANewGrid()
{
throw new PendingException();
$this->mink->assertSession()->elementExists('css', '#grid');
}

/**
Expand Down Expand Up @@ -95,13 +123,7 @@ public function isAssigned($arg1)
throw new PendingException();
}

/**
* @Given /^I am on the "([^"]*)"$/
*/
public function iAmOnThe($arg1)
{
throw new PendingException();
}


/**
* @When /^The game results in a draw$/
Expand Down
4 changes: 2 additions & 2 deletions features/grid/player_starts_a_game.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Feature: Player starts a game
I need to start a game

Scenario: "Player X" wants to start a game
Given I am "Player X"
And I Want to start a game
Given I am on the "home page"
When I click on "start a game"
Then I should get a new grid

Scenario: "Player 0" wants to start a game
Expand Down
7 changes: 7 additions & 0 deletions public/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
26 changes: 26 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
Loading

0 comments on commit 5af445c

Please sign in to comment.