Skip to content

Commit

Permalink
Added structure for integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Oct 17, 2014
1 parent c21c0d8 commit 5c191c5
Show file tree
Hide file tree
Showing 18 changed files with 2,052 additions and 54 deletions.
10 changes: 6 additions & 4 deletions codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ settings:
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
dsn: 'mysql:host=localhost;dbname=phalcon_test'
user: 'root'
password: '1234'
populate: true
cleanup: false
dump: tests/_data/mysql.dump.sql
1 change: 0 additions & 1 deletion tests/_data/dump.sql

This file was deleted.

23 changes: 23 additions & 0 deletions tests/_data/mysql.dump.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";

CREATE DATABASE IF NOT EXISTS `phalcon_test` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
USE `phalcon_test`;

DROP TABLE IF EXISTS `ph_select`;
CREATE TABLE IF NOT EXISTS `ph_select` (
`sel_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`sel_name` varchar(16) COLLATE utf8_unicode_ci NOT NULL,
`sel_text` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`sel_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=9 ;

INSERT INTO `ph_select` (`sel_id`, `sel_name`, `sel_text`) VALUES
(1, 'Sun', 'The one and only'),
(2, 'Mercury', 'Cold and hot'),
(3, 'Venus', 'Yeah baby she''s got it'),
(4, 'Earth', 'Home'),
(5, 'Mars', 'The God of War'),
(6, 'Jupiter', NULL),
(7, 'Saturn', 'A car'),
(8, 'Uranus', 'Loads of jokes for this one');
10 changes: 10 additions & 0 deletions tests/_support/IntegrationHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Codeception\Module;

// here you can define custom actions
// all public methods declared in helper class will be available in $I

class IntegrationHelper extends \Codeception\Module
{

}
126 changes: 126 additions & 0 deletions tests/_support/_config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php

namespace PhalconTest;

use \Phalcon\DI\FactoryDefault as PhDI;
use \Phalcon\Config as PhConfig;
use \Phalcon\Mvc\Url as PhUrl;
use \Phalcon\Mvc\Router as PhRouter;
use \Phalcon\Mvc\Dispatcher as PhDispatcher;
use \Phalcon\Db\Adapter\Pdo\Mysql as PhMysql;
use \Phalcon\Loader as PhLoader;
use \Phalcon\Mvc\Application as PhApplication;

$di = new PhDI();

/**
* Config file
*/
$configFile = require(ROOT_PATH . '/_support/_config/global.php');
$di->set(
'config',
function () use ($configFile) {
return new PhConfig($configFile);
},
true
);

/**
* Autoloader
*/
$di->set(
'loader',
function () use ($di) {

$config = $di['config'];
$loader = new PhLoader();

$loader->registerDirs(
[$config->app_path->dirs]
);

// Register the Library namespace as well as the common module
// since it needs to always be available
$loader->registerNamespaces(
['PhalconTest\Models' => $config->app_path->models]
);

$loader->register();
}
);

/**
* The URL component is used to generate all kind of urls in the
* application
*/
$di->set(
'url',
function () use ($di) {

$config = $di['config'];

$url = new PhUrl();
$url->setBaseUri($config->app_baseUri);

return $url;
},
true
);

/**
* Router
*/
$di->set(
'router',
function () {

$router = new PhRouter(false);
return $router;
},
true
);

/**
* Dispatcher
*/
$di->set(
'dispatcher',
function () use ($di) {
$dispatcher = new PhDispatcher();
return $dispatcher;
}
);

/**
* Db
*/
$di->set(
'db',
function () use ($di) {

$config = $di['config'];

$params = [
"host" => $config->app_db_test->host,
"username" => $config->app_db_test->username,
"password" => $config->app_db_test->password,
"dbname" => $config->app_db_test->dbname,
"charset" => $config->app_db_test->charset,
];

$adapter = $config->app_db_test->adapter;
$conn = new $adapter();

// Set everything to UTF8
$conn->execute('SET NAMES UTF8', []);

return $conn;
}
);

$application = new PhApplication();
$application->setDI($di);

PhDI::setDefault($di);

return $application;
26 changes: 26 additions & 0 deletions tests/_support/_config/global.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

$base = [
'app_baseUri' => '/',
'app_timezone' => 'UTC',
'app_db_test' => [
'adapter' => 'Mysql',
'host' => 'localhost',
'username' => 'root',
'password' => '1234',
'name' => 'phalcon_test',
'charset' => 'utf-8',
],
];

$path = [
'app_path' => [
'dirs' => ROOT_PATH . '/_support/',
'models' => ROOT_PATH . '/_support/_models/',
]
];

return array_merge(
$base,
$path
);
67 changes: 67 additions & 0 deletions tests/_support/_models/Select.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Select.php
* \PhalconTest\Models\Select
*
* Select model class
*
* PhalconPHP Framework
*
* @copyright (c) 2011-2014 Phalcon Team
* @link http://www.phalconphp.com
* @author Andres Gutierrez <andres@phalconphp.com>
* @author Nikolaos Dimopoulos <nikos@phalconphp.com>
*
* The contents of this file are subject to the New BSD License that is
* bundled with this package in the file docs/LICENSE.txt
*
* If you did not receive a copy of the license and are unable to obtain it
* through the world-wide-web, please send an email to license@phalconphp.com
* so that we can send you a copy immediately.
*/

namespace PhalconTest\Models;

use \Phalcon\Mvc\Model as PhModel;

class Select extends PhModel
{
public function initialize()
{
}

public function getSource()
{
return 'ph_select';
}

public function getId()
{
return $this->sel_id;
}

public function getName()
{
return $this->sel_name;
}

public function getText()
{
return $this->sel_text;
}

public function setId($id)
{
$this->sel_id = $id;
}

public function setName($name)
{
$this->sel_name = $name;
}

public function setText($text)
{
$this->sel_text = $text;
}
}
53 changes: 36 additions & 17 deletions tests/acceptance/AcceptanceTester.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php //[STAMP] 09ccda81657f0c7f3e38fe7c5280f02a
<?php //[STAMP] cf1df50feafa1eac32baa9f878f6239f

// This class was automatically generated by build task
// You should not change it manually as it will be overwritten on next build
Expand All @@ -19,7 +19,7 @@
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void haveFriend($name)
* @method void haveFriend($name, $actorClass = null)
*/
class AcceptanceTester extends \Codeception\Actor
{
Expand All @@ -35,6 +35,39 @@ public function setHeader($header, $value) {
}


/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Authenticates user for HTTP_AUTH
*
* @param $username
* @param $password
* @see \Codeception\Module\PhpBrowser::amHttpAuthenticated()
*/
public function amHttpAuthenticated($username, $password) {
return $this->scenario->runStep(new \Codeception\Step\Condition('amHttpAuthenticated', func_get_args()));
}


/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Open web page at absolute URL.
* Base url will be reconfigured to use the host of provided Url.
*
* ``` php
* <?php
* $I->amOnUrl('http://codeception.com');
* $I->anOnPage('/quickstart'); // moves to http://codeception.com/quickstart
* ?>
* ```
* @see \Codeception\Module\PhpBrowser::amOnUrl()
*/
public function amOnUrl($url) {
return $this->scenario->runStep(new \Codeception\Step\Condition('amOnUrl', func_get_args()));
}


/**
* [!] Method is generated. Documentation taken from corresponding module.
*
Expand Down Expand Up @@ -90,20 +123,6 @@ public function executeInGuzzle($function) {
}


/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Authenticates user for HTTP_AUTH
*
* @param $username
* @param $password
* @see \Codeception\Lib\InnerBrowser::amHttpAuthenticated()
*/
public function amHttpAuthenticated($username, $password) {
return $this->scenario->runStep(new \Codeception\Step\Condition('amHttpAuthenticated', func_get_args()));
}


/**
* [!] Method is generated. Documentation taken from corresponding module.
*
Expand Down Expand Up @@ -1050,7 +1069,7 @@ public function sendAjaxPostRequest($uri, $params = null) {
*
* ``` php
* <?php
* $I->sendAjaxRequest('PUT', /posts/7', array('title' => 'new title');
* $I->sendAjaxRequest('PUT', '/posts/7', array('title' => 'new title'));
*
* ```
*
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/FunctionalTester.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php //[STAMP] 2d5424bd64b96072b405bc6a67c7f316
<?php //[STAMP] 4cad8118365b82e5299a25109a8e4fe3

// This class was automatically generated by build task
// You should not change it manually as it will be overwritten on next build
Expand All @@ -19,7 +19,7 @@
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void haveFriend($name)
* @method void haveFriend($name, $actorClass = null)
*/
class FunctionalTester extends \Codeception\Actor
{
Expand Down
6 changes: 6 additions & 0 deletions tests/integration.suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class_name: IntegrationTester
modules:
enabled: [IntegrationHelper, Phalcon1]
config:
Phalcon1:
bootstrap: '/tests/_support/_config/bootstrap.php'
Loading

0 comments on commit 5c191c5

Please sign in to comment.