Skip to content

Commit

Permalink
Move tests to Codeception.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleigh committed Mar 13, 2017
1 parent c9c9d6e commit 81d69f3
Show file tree
Hide file tree
Showing 48 changed files with 9,187 additions and 182 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/vendor
.env

tests/_output/*
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ before_install:
- composer install --prefer-source --no-interaction
- ./install-phalcon.sh 3.0.x

install:
- echo "Download and Install codecept.phar"
- wget -c -nc --retry-connrefused --tries=0 http://codeception.com/releases/2.2.8/codecept.phar
- chmod +x codecept.phar
- php codecept.phar --version

script:
- vendor/bin/phpunit
- php codecept.phar run acceptance --no-interaction

cache:
directories:
Expand Down
15 changes: 15 additions & 0 deletions app/config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* The app directory is here for testing purposes only.
* This file bootstraps the Codeception test suite.
*/

$config = include __DIR__ . '/config.php';

include __DIR__ . '/loader.php';

$di = new \Phalcon\DI\FactoryDefault();

include __DIR__ . '/services.php';

return new \Phalcon\Mvc\Application($di);
30 changes: 30 additions & 0 deletions app/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/*
* Modified: prepend directory path of current file, because of this file own different ENV under between Apache and command line.
* NOTE: please remove this comment.
*/
defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..'));
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app');

return new \Phalcon\Config([
'database' => [
'adapter' => 'Mysql',
'host' => '127.0.0.1',
'username' => 'root',
'password' => 'password',
'dbname' => 'yarak',
'charset' => 'utf8',
],
'application' => [
'appDir' => APP_PATH . '/',
'controllersDir' => APP_PATH . '/controllers/',
'modelsDir' => APP_PATH . '/models/',
'migrationsDir' => APP_PATH . '/database/migrations/',
'viewsDir' => APP_PATH . '/views/',
'pluginsDir' => APP_PATH . '/plugins/',
'servicesDir' => APP_PATH . '/services/',
'cacheDir' => BASE_PATH . '/cache/',
'formsDir' => APP_PATH . '/forms',
'baseUri' => '/',
]
]);
17 changes: 17 additions & 0 deletions app/config/loader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use Phalcon\Loader;
use Phalcon\Di\FactoryDefault;

$loader = new Loader();

$loader->registerNamespaces([
'App\Models' => APP_PATH.'/models',
]);

$loader->register();

/**
* Composer
*/
// require_once BASE_PATH . '/vendor/autoload.php';
134 changes: 134 additions & 0 deletions app/config/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

use Yarak\Kernel;
use Phalcon\Mvc\View;
use Phalcon\Security;
use Sonohini\Acl\Acl;
use Sonohini\Auth\Auth;
use Phalcon\Mvc\Dispatcher;
use Elasticsearch\ClientBuilder;
use Phalcon\Flash\Direct as Flash;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Mvc\View\Engine\Php as PhpEngine;
use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
use Phalcon\Mvc\Model\Manager as ModelsManager;
use Phalcon\Session\Adapter\Files as SessionAdapter;
use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;

$di->setShared('config', function () {
return include APP_PATH.'/config/config.php';
});

$di->setShared('url', function () {
$config = $this->getConfig();

$url = new UrlResolver();
$url->setBaseUri($config->application->baseUri);

return $url;
});

$di->setShared('view', function () {
$config = $this->getConfig();

$view = new View();
$view->setDI($this);
$view->setViewsDir($config->application->viewsDir);

$view->registerEngines([
'.volt' => function ($view) {
$config = $this->getConfig();

$volt = new VoltEngine($view, $this);

$volt->setOptions([
'compiledPath' => $config->application->cacheDir,
'compiledSeparator' => '_',
]);

return $volt;
},
'.phtml' => PhpEngine::class,

]);

return $view;
});

$di->setShared('db', function () {
$config = $this->getConfig();

$class = 'Phalcon\Db\Adapter\Pdo\\'.$config->database->adapter;

$params = [
'host' => $config->database->host,
'username' => $config->database->username,
'password' => $config->database->password,
'dbname' => $config->database->dbname,
'charset' => $config->database->charset,
];

if ($config->database->adapter == 'Postgresql') {
unset($params['charset']);
}

$connection = new $class($params);

$connection->setNestedTransactionsWithSavepoints(true);

return $connection;
});

$di->setShared('modelsMetadata', function () {
return new MetaDataAdapter();
});

$di->set('flash', function () {
return new Flash([
'error' => 'alert alert-danger',
'success' => 'alert alert-success',
'notice' => 'alert alert-info',
'warning' => 'alert alert-warning',
]);
});

$di->set('session', function () {
$session = new SessionAdapter();
$session->start();

return $session;
});

$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('Sonohini\Controllers');

return $dispatcher;
});

$di->set('security', function () {
return new Security();
});

$di->set('modelsManager', function() {
return new ModelsManager();
});

$di->setShared('yarak', function () {
$config = $this->getConfig();

return new Kernel([
'application' => [
'databaseDir' => APP_PATH.'/database/',
],
'database' => [
'adapter' => $config->database->adapter,
'host' => $config->database->host,
'username' => $config->database->username,
'password' => $config->database->password,
'dbname' => $config->database->dbname,
'charset' => $config->database->charset,
],
]);
});

36 changes: 36 additions & 0 deletions app/database/migrations/2017_03_13_224917_create_test_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Phalcon\Db\Index;
use Phalcon\Db\Column;
use Phalcon\Db\Reference;
use Phalcon\Db\Adapter\Pdo;
use Yarak\Migrations\Migration;

class CreateTestTable implements Migration
{
/**
* Run the migration.
*
* @param Pdo $connection
*/
public function up(Pdo $connection)
{
$connection->createTable(
'test',
null,
[
//
]
);
}

/**
* Reverse the migration.
*
* @param Pdo $connection
*/
public function down(Pdo $connection)
{
$connection->dropTable('test');
}
}
18 changes: 18 additions & 0 deletions app/models/Posts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Models;

use Phalcon\Mvc\Model;

class Posts extends Model
{
public function initialize()
{
$this->hasOne(
'users_id',
'App\Models\Users',
'id',
['alias' => 'users']
);
}
}
18 changes: 18 additions & 0 deletions app/models/Users.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Models;

use Phalcon\Mvc\Model;

class Users extends Model
{
public function initialize()
{
$this->hasMany(
'id',
'App\Models\Posts',
'users_id',
['alias' => 'posts']
);
}
}
21 changes: 21 additions & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: 'mysql:host=127.0.0.1;dbname=yarak'
user: 'root'
password: 'password'
dump: tests/_data/dump.sql
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"vlucas/phpdotenv": "^2.4",
"symfony/filesystem": "^3.2",
"phalcon/zephir": "^0.9.6",
"fzaninotto/faker": "^1.6"
"fzaninotto/faker": "^1.6",
"codeception/codeception": "^2.2"
},
"autoload": {
"files": [
Expand Down
Loading

0 comments on commit 81d69f3

Please sign in to comment.