I am trying to get Codeception to run and I can get it working based off CodeCeption Phalcon. However, I cannot get my own project working when I use namespaces. Any advice would be appreciated.
Using
- Phalcon 3.2
- Php 7.0 (Both OS's)
- Ubuntu x64 16.04 LTS
- Windows 10
Other Question) It seems all of Phalcon Autoloading files works. However when I add namespaces for reasons I dont know, some of the CSS gets broken. I am using webpack. This seems totally irrelevent but it isnt because using the exact fsame compiled SASS gives me a different result when using a namespace or not. Im quite confused.
Question 1
Can you test if phalcon is doing something wrong with loading files? I should get a warning but the namespaces break things I am not sure if Im overwriting in my loader.php file. Does get_declared_classes()
output what Phalcon has loaded in the Loader?
Question 2
I get an error like this undefined variable di
, I am not sure where to look.
I also get an error just recently of this: Cannot declare class PHPUnit_Framework_Assert, because the name is already in use in /home/jesse/projects/jream.com/vendor/codeception/codeception/shim.php on line 17
Here are my files that seem releveant. I made sure to set index.php
to require_once it hasn't had any effect.
Composer.json
],
"require": {
"aws/aws-sdk-php": "^3.33",
"erusev/parsedown": "^1.6",
"facebook/graph-sdk": "^5.6",
"filp/whoops": "^2.1",
"google/auth": "^1.0",
"guzzlehttp/guzzle": "^6.3",
"monolog/monolog": "^1.23",
"omnipay/common": "^2.5",
"omnipay/paypal": "^2.6",
"phalcon/incubator": "^v3.2",
"php-http/guzzle6-adapter": "^1.1",
"sendgrid/php-http-client": "^3.7",
"sendgrid/sendgrid": "^5.6",
"sentry/sentry": "^1.7",
"stripe/stripe-php": "^v3.23",
"swiftmailer/swiftmailer": "^5.4",
"symfony/dotenv": "^v3.3",
"symfony/var-dumper": "^3.3",
"php": ">=7.0",
"ext-phalcon": ">=3.2"
},
"require-dev": {
"codeception/codeception": "^2.3",
"codeception/specify": "^0.4",
"codeception/verify": "^0.4",
"phalcon/ide-stubs": "^3.2",
"squizlabs/php_codesniffer": "^2.9"
},
"autoload-dev": {
"psr-4": {
"App\\Test\\Unit\\": "tests/unit/"
}
}
Structure
- app/ -- No Namespace
- app/components/ -- Namespace:
Components
- app/controllers/ -- Namespace
Controllers
- app/controllers/api -- Namespace
Controllers\Api
- app/controllers/dashboard -- Namespcae
Controllers\Dashboard
- app/forms/ -- No Namespace
- app/library/ -- Namespace
Library
(Not Used) - app/middleware/ -- Namespace
Middleware
- app/models/ -- No Namespace (easiest to access)
- app/plugins/ -- Namespace
Plugins
(Not Used) - app/tasks/ -- No Namespace, Issues with
Tasks
namespace I removed it. - app/views/ -- No namespace (Just views)
Loader.php
<?php
$loader = new \Phalcon\Loader();
$loader->registerNamespaces([
'Components' => $config->get('componentsDir'),
'Controllers' => $config->get('controllersDir'),
'Controllers\Api' => $config->get('controllersDir') . 'api/',
'Controllers\Dashboard' => $config->get('controllersDir') . 'dashboard/',
'Library' => $config->get('libraryDir'),
'Middleware' => $config->get('middlewareDir'),
'Migrations' => $config->get('migrationsDir'),
'Plugins' => $config->get('pluginsDir'),
]);
$loader->registerClasses([
'Phalcon' => DOCROOT . 'vendor/phalcon/incubator/Library/Phalcon/',
]);
$registerDirs = [
$config->get('configDir'),
$config->get('formsDir'),
$config->get('modelsDir'),
$config->get('tasksDir'),
];
// 1: For running unit tests
// 2: For the CLI Tasks
if (strtolower(\PHP_SAPI) === 'cli')
{
// Auto Load the Tests Directory.
$registerDirs[] = $config->get('testsDir');
}
// Register Remaining Directories
$loader->registerDirs($registerDirs);
// Finished
$loader->register();
public/index.php
use Phalcon\Mvc\Application;
/**
* ==============================================================
* Load Environment (Composer Auto-Loader, Constants)
*
* @important The Order of file loading is crucial.
* =============================================================
*/
require_once realpath(dirname(__DIR__)) . '/config/env.php';
/**
* ==============================================================
* Phalcon Bootstrap
* =============================================================
*/
try {
/** Read the configuration */
$config = require_once DOCROOT . "config/config.php";
$api = require_once $config->get('configDir') . "api.php";
/** Read phalcon auto-loader */
require_once $config->get('configDir') . "loader.php";
/** Read services */
require_once $config->get('configDir') . "services.php";
/** Handle the request */
$application = new Application($di);
if (\APPLICATION_ENV === \APP_TEST) {
return $application;
}
echo $application->handle()->getContent();
} catch(Exception $e) {
// etc..
}
Running Codeception
Phalcon Linux Output from Codeception
./vendor/bin/codecept run unit -vvv
PHP Warning: Cannot declare class PHPUnit_Framework_Assert, because the name is already in use in /home/jesse/projects/justrun/vendor/codeception/codeception/shim.php on line 17
PHP Stack trace:
PHP 1. {main}() /home/jesse/projects/justrun/vendor/codeception/codeception/codecept:0
PHP 2. require_once() /home/jesse/projects/justrun/vendor/codeception/codeception/codecept:7
PHP 3. include_once() /home/jesse/projects/justrun/vendor/codeception/codeception/autoload.php:45
PHP 4. class_alias() /home/jesse/projects/justrun/vendor/codeception/codeception/shim.php:17
Warning: Cannot declare class PHPUnit_Framework_Assert, because the name is already in use in /home/jesse/projects/justrun/vendor/codeception/codeception/shim.php on line 17
Call Stack:
0.0002 379088 1. {main}() /home/jesse/projects/justrun/vendor/codeception/codeception/codecept:0
0.0004 406896 2. require_once('/home/jesse/projects/justrun/vendor/codeception/codeception/autoload.php') /home/jesse/projects/justrun/vendor/codeception/codeception/codecept:7
0.0279 2081144 3. include_once('/home/jesse/projects/justrun/vendor/codeception/codeception/shim.php') /home/jesse/projects/justrun/vendor/codeception/codeception/autoload.php:45
0.0296 2336016 4. class_alias() /home/jesse/projects/justrun/vendor/codeception/codeception/shim.php:17
Codeception PHP Testing Framework v2.3.5
Powered by PHPUnit 6.2.4 by Sebastian Bergmann and contributors.
Phalcon Linux Output from Windows 10
Warning: Cannot declare class PHPUnit_Framework_Assert, because the name is already in use in C:\Users\inno\projects\justrun\veodeception\codeception\shim.php on line 17
Codeception PHP Testing Framework v2.3.5
Powered by PHPUnit 6.2.4 by Sebastian Bergmann and contributors.
Unit Tests (21) --------------------------------------------------------------------------------------------------------
Modules: Asserts, \Helper\Unit, Phalcon
------------------------------------------------------------------------------------------------------------------------
- AuthTest: Login action
[Database] Transaction started
+ AuthTest: Login action (0.00s)
[Database] Transaction cancelled; all changes reverted.
- AuthTest: Register actionUndefined variable: di
[email protected] MINGW64 ~/projects/justrun (master)
Any ideas :) ?