Skip to content

Commit 03456c7

Browse files
committed
Refactored Tests
1 parent 80404ba commit 03456c7

File tree

12 files changed

+109
-50
lines changed

12 files changed

+109
-50
lines changed

codeception.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ extensions:
1111
- Codeception\Extension\RunFailed
1212
params:
1313
- .env
14+
modules:
15+
enabled:
16+
- Db:
17+
dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%;port=%DB_PORT%'
18+
user: '%DB_USERNAME%'
19+
password: '%DB_PASSWORD%'
20+
populate: no
21+
cleanup: true
22+
dump: 'tests/_data/structure.sql'

tests/_bootstrap.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
use Codeception\Util\Autoload;
4+
25
// This is global bootstrap for autoloading
36

47
error_reporting(-1);
@@ -19,3 +22,17 @@
1922

2023
echo "ENV: " . APPLICATION_ENV . PHP_EOL;
2124
echo "DB_HOST: " . getenv('DB_HOST') . ":" . getenv('DB_PORT') . PHP_EOL;
25+
26+
27+
Autoload::addNamespace(
28+
'Codeception\Module',
29+
BASE_PATH . '/src/Codeception/Module'
30+
);
31+
Autoload::addNamespace(
32+
'Codeception\Lib\Connector\Phalcon4',
33+
BASE_PATH . '/src/Codeception/Lib/Connector/Phalcon4'
34+
);
35+
Autoload::addNamespace(
36+
'App',
37+
BASE_PATH . '/tests/_data/App'
38+
);

tests/_data/controllers/ContactController.php renamed to tests/_data/App/Controllers/IndexController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Phalcon\Mvc\Controller;
66

7-
class ContactController extends Controller
7+
class IndexController extends Controller
88
{
99
public function indexAction()
1010
{

tests/_data/App/Models/Articles.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Phalcon\Mvc\Model;
6+
7+
class Articles extends Model
8+
{
9+
10+
}

tests/_data/App/Views/index.volt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
layout
2+
{{ content() }}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Index
2+
{{ content() }}

tests/_data/bootstrap.php

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Phalcon\DI\FactoryDefault;
88
use Phalcon\Db\Adapter\Pdo\Mysql;
99
use Phalcon\Url as UrlProvider;
10+
use Phalcon\Mvc\View\Engine\Volt;
11+
use Phalcon\Loader;
1012

1113
$di = new FactoryDefault();
1214
$di->setShared(
@@ -43,11 +45,48 @@ function () {
4345
/**
4446
* Setting the View
4547
*/
46-
$di->setShared('view', function () {
48+
$di->setShared('view', function () use ($di) {
4749
$view = new View();
50+
// $view->setViewsDir(BASE_PATH . '/_data/App/Views/');
51+
// $view->registerEngines(
52+
// [
53+
// ".volt" => "voltService"
54+
// ]
55+
// );
56+
// $eventsManager = $di->get('eventsManager');
57+
// $eventsManager->attach('view', function ($event, $view) use ($di) {
58+
// /**
59+
// * @var \Phalcon\Events\Event $event
60+
// * @var \Phalcon\Mvc\View $view
61+
// */
62+
// if ($event->getType() == 'notFoundView') {
63+
// $message = sprintf('View not found - %s', $view->getActiveRenderPath());
64+
// throw new Exception($message);
65+
// }
66+
// });
67+
// $view->setEventsManager($eventsManager);
4868
return $view;
4969
});
5070

71+
/**
72+
* Volt Service
73+
*/
74+
$di->set(
75+
'voltService',
76+
function ($view) use ($di) {
77+
$volt = new Volt($view, $di);
78+
79+
$volt->setOptions(
80+
[
81+
'compiledPath' => BASE_PATH . '/_output/compiled-templates/',
82+
'compiledExtension' => '.compiled',
83+
]
84+
);
85+
86+
return $volt;
87+
}
88+
);
89+
5190
/**
5291
* The URL component is used to generate all kind of urls in the application
5392
*/
@@ -60,10 +99,9 @@ function () {
6099

61100
$router = $di->getRouter();
62101

63-
$router->add('/contact', [
64-
'controller' => 'App\Controllers\Contact',
102+
$router->add('/', [
103+
'controller' => 'App\Controllers\Index',
65104
'action' => 'index'
66-
])->setName('front.contact');
67-
105+
])->setName('front.index');
68106

69107
return new Application($di);

tests/_data/models/test.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/_data/structure.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
CREATE DATABASE IF NOT EXISTS phalcon CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2-
create table test
2+
create table articles
33
(
44
id int auto_increment,
5-
name varchar(255) null,
5+
title varchar(255) null,
66
constraint test_pk
77
primary key (id)
88
);

tests/functional.suite.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,15 @@ modules:
1010
enabled:
1111
# add a framework module here
1212
- \Helper\Functional
13-
step_decorators: ~
13+
- Db:
14+
dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%;port=%DB_PORT%'
15+
user: '%DB_USERNAME%'
16+
password: '%DB_PASSWORD%'
17+
populate: no
18+
cleanup: true
19+
dump: 'tests/_data/structure.sql'
20+
- Phalcon4:
21+
bootstrap: tests/_data/bootstrap.php
22+
cleanup: true
23+
savepoints: true
24+
step_decorators: ~

0 commit comments

Comments
 (0)