CodeIgniter Forums
Problem with Project-tests - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Problem with Project-tests (/thread-74791.html)

Pages: 1 2


Problem with Project-tests - Poetawd - 11-06-2019

First,

Thank you MGatner for all the effort on this GREAT CI4 code ! Really awesome !

Also, thank you very much for all the help you have being given me !

The first problem I encountered with project-tests was right after installing it.

I even started a new CI4 installation to check if the problem was me.

On a brand-new CI4 installation, just after after adding the requirements in COMPOSER.JSON file I got the following error:

Code:
λ php spark serve


CodeIgniter CLI Tool - Version 4.0.0-rc.3 - Server-Time: 2019-11-06 20:14:39pm

PHP Fatal error:  Uncaught Error: Class 'Tests\Support\Config\Registrar' not found in C:\Users\gabri\Documents\ci4.dev\system\Config\BaseConfig.php:206
Stack trace:
#0 C:\Users\gabri\Documents\ci4.dev\system\Config\BaseConfig.php(101): CodeIgniter\Config\BaseConfig->registerProperties()


The error happens after adding this line into composer:

Code:
    "autoload-dev": {
        "psr-4": {
            "ProjectTests\\Support\\": "tests/_support"
        }
    },

Without it the command php spark serve will work OK


RE: Problem with Project-tests - MGatner - 11-07-2019

That's an odd one. Just to be clear, you copied the folder from ProjectTests/src into the root of your App, and you also have a regular framework System folder located somewhere that your Paths.php file can find?

The tests bootstrap does load a constant for the framework tests (https://github.com/codeigniter4projects/project-tests/blob/develop/src/tests/_support/bootstrap.php#L23) but I don't know how that would affect a non-testing instance.


RE: Problem with Project-tests - Poetawd - 11-07-2019

(11-07-2019, 01:10 PM)MGatner Wrote: That's an odd one. Just to be clear, you copied the folder from ProjectTests/src into the root of your App, and you also have a regular framework System folder located somewhere that your Paths.php file can find?

The tests bootstrap does load a constant for the framework tests (https://github.com/codeigniter4projects/project-tests/blob/develop/src/tests/_support/bootstrap.php#L23) but I don't know how that would affect a non-testing instance.

I tried everything... Installing a new CI4 using composer... using the manual installation... etc...

Whenever I add the PS4 autoload in composer the SPARK command will give me that error...

If you want to I can make a video to show you the issue...


RE: Problem with Project-tests - MGatner - 11-07-2019

Can you edit system\Config\BaseConfig.php and modify line 206 to look like this:
PHP Code:
$className            $locator->getClassname($file);
if (
$classname == 'Tests\Support\Config\Registrar')
{
trace(); dd($registrarsFiles);
}
static::
$registrars[] = new $className(); 

And share the output?


RE: Problem with Project-tests - Poetawd - 11-07-2019

Code:
��������������������������������������������������������������������������������
Called from .../system/Config/BaseConfig.php:208 [CodeIgniter\Config\BaseConfig->registerProperties()]

������������������������������������������������������������������������������Ŀ
� $registrarsFiles                                                             �
��������������������������������������������������������������������������������
array (2) [
    0 => string (90) "C:\Users\gabri\Documents\ci4.dev\vendor\composer/../../tests/_support\Config/Registrar.php"
    1 => string (84) "C:\Users\gabri\Documents\ci4.dev\vendor\composer/../../MythAuth\Config/Registrar.php"
]
��������������������������������������������������������������������������������
Called from .../system/Config/BaseConfig.php:208 [CodeIgniter\Config\BaseConfig->registerProperties()]

Need more ? Or that part is good ?

And the file is there... Just checked...


RE: Problem with Project-tests - MGatner - 11-08-2019

I was actually hoping for the `trace()` output - I'm curious how this is being called to being with, and why it is trying to load the tests registrar in a production instance.


RE: Problem with Project-tests - Poetawd - 11-08-2019

(11-08-2019, 07:12 AM)MGatner Wrote: I was actually hoping for the `trace()` output - I'm curious how this is being called to being with, and why it is trying to load the tests registrar in a production instance.

Code:
CodeIgniter CLI Tool - Version 4.0.0-rc.3 - Server-Time: 2019-11-08 13:07:29pm


������������������������������������������������������������������������������Ŀ
� Kint::trace()                                                                �
��������������������������������������������������������������������������������
Debug Backtrace (14):
    1:  .../system/Config/BaseConfig.php:208
        trace()

                        $registrarsFiles = $locator->search('Config/Registrar.php');

                        foreach ($registrarsFiles as $file)
                        {
                                $className            = $locator->getClassname($file);
                                if ($className == 'Tests\Support\Config\Registrar')
                                {
                                trace(); dd($registrarsFiles);
                                }
                                static::$registrars[] = new $className();
                        }

                        static::$didDiscovery = true;
                }
    2:  .../system/Config/BaseConfig.php:101
        CodeIgniter\Config\BaseConfig->registerProperties()

                        $this->initEnvValue($this->$property, $property, $prefix, $shortPrefix);
                }

                if (defined('ENVIRONMENT') && ENVIRONMENT !== 'testing')
                {
                        // well, this won't happen during unit testing
                        // @codeCoverageIgnoreStart
                        $this->registerProperties();
                        // @codeCoverageIgnoreEnd
                }
        }

        //--------------------------------------------------------------------

        /**
    3:  .../system/Config/Config.php:157
        CodeIgniter\Config\BaseConfig->__construct()

                $name = $locator->getClassname($file);

                if (empty($name))
                {
                        return null;
                }

                return new $name();
        }

        //--------------------------------------------------------------------
    }
    4:  .../system/Config/Config.php:83
        CodeIgniter\Config\Config::createClass(string $name)

                if (! $getShared)
                {
                        return self::createClass($name);
                }

                if (! isset( self::$instances[$class] ))
                {
                        self::$instances[$class] = self::createClass($name);
                }
                return self::$instances[$class];
        }

        //--------------------------------------------------------------------

        /**
    5:  .../system/Common.php:109
        CodeIgniter\Config\Config::get(string $name, bool $getShared = true)

         * @param string  $name
         * @param boolean $getShared
         *
         * @return mixed
         */
        function config(string $name, bool $getShared = true)
        {
                return Config::get($name, $getShared);
        }
    }

    //--------------------------------------------------------------------

    if (! function_exists('db_connect'))
    {
    6:  .../system/Config/Services.php:839
        config(string $name, bool $getShared = true)

                if ($getShared)
                {
                        return static::getSharedInstance('toolbar', $config);
                }

                if (! is_object($config))
                {
                        $config = config('Toolbar');
                }

                return new Toolbar($config);
        }

        //--------------------------------------------------------------------
    7:  .../system/Config/BaseService.php:120
        CodeIgniter\Config\Services::toolbar(Config\Toolbar $config = null, bool $getShared = true)

                }

                if (! isset(static::$instances[$key]))
                {
                        // Make sure $getShared is false
                        array_push($params, false);

                        static::$instances[$key] = static::$key(...$params);
                }

                return static::$instances[$key];
        }

        //--------------------------------------------------------------------
    8:  .../system/Config/Services.php:834
        CodeIgniter\Config\BaseService::getSharedInstance(string $key, $params)

         *
         * @return \CodeIgniter\Debug\Toolbar
         */
        public static function toolbar(\Config\Toolbar $config = null, bool $getShared = true)
        {
                if ($getShared)
                {
                        return static::getSharedInstance('toolbar', $config);
                }

                if (! is_object($config))
                {
                        $config = config('Toolbar');
                }
    9:  .../app/Config/Events.php:41
        CodeIgniter\Config\Services::toolbar(Config\Toolbar $config = null, bool $getShared = true)

         * Debug Toolbar Listeners.
         * --------------------------------------------------------------------
         * If you delete, they will no longer be collected.
         */
        if (ENVIRONMENT !== 'production')
        {
                Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
                Services::toolbar()->respond();
        }
    });
    10: PHP internal call
        CodeIgniter\Events\Events::Config\{closure}(...)

    11: .../system/Events/Events.php:188
        call_user_func($function_name, $parameters)

                $listeners = static::listeners($eventName);

                foreach ($listeners as $listener)
                {
                        $start = microtime(true);

                        $result = static::$simulate === false ? call_user_func($listener, ...$arguments) : true;

                        if (CI_DEBUG)
                        {
                                static::$performanceLog[] = [
                                        'start' => $start,
                                        'end'   => microtime(true),
                                        'event' => strtolower($eventName),
    12: .../system/CodeIgniter.php:227
        CodeIgniter\Events\Events::trigger($eventName, $arguments)

                $this->getRequestObject();
                $this->getResponseObject();

                $this->forceSecureAccess();

                $this->spoofRequestMethod();

                Events::trigger('pre_system');

                // Check for a cached page. Execution will stop
                // if the page has been cached.
                $cacheConfig = new Cache();
                $response    = $this->displayCache($cacheConfig);
                if ($response instanceof ResponseInterface)
                {
    13: .../system/CLI/Console.php:86
        CodeIgniter\CodeIgniter->run(CodeIgniter\Router\RouteCollectionInterface $routes = null, bool $returnResponse = false)

        public function run(bool $useSafeOutput = false)
        {
                $path = CLI::getURI() ?: 'list';

                // Set the path for the application to route to.
                $this->app->setPath("ci{$path}");

                return $this->app->useSafeOutput($useSafeOutput)->run();
        }

        //--------------------------------------------------------------------

        /**
         * Displays basic information about the Console.
         */
    14: .../spark:57
        CodeIgniter\CLI\Console->run(bool $useSafeOutput = false)

    error_reporting(-1);
    ini_set('display_errors', 1);

    // Show basic information before we do anything else.
    $console->showHeader();

    // fire off the command in the main framework.
    $response = $console->run();
    if ($response->getStatusCode() >= 300)
    {
        exit($response->getStatusCode());
    }
��������������������������������������������������������������������������������
Called from .../system/Config/BaseConfig.php:208 [CodeIgniter\Config\BaseConfig->registerProperties()]

������������������������������������������������������������������������������Ŀ
� $registrarsFiles                                                             �
��������������������������������������������������������������������������������
array (1) [
    0 => string (95) "C:\Users\gabri\Documents\asist.com.br\vendor\composer/../../tests/_support\Config/Registrar.php"
]
��������������������������������������������������������������������������������
Called from .../system/Config/BaseConfig.php:208 [CodeIgniter\Config\BaseConfig->registerProperties()]

I hope it helps find the BUG...

I hope it helps find the BUG...

I hope it helps find the BUG...


RE: Problem with Project-tests - MGatner - 11-09-2019

Thanks! I’m on mobile and that’s a nightmare to try to read but I’ll take a look when I get a chance. Thanks for helping troubleshoot this.


RE: Problem with Project-tests - Poetawd - 11-09-2019

No problem... I hope you can solve this... It is a bitch have to change composer everytime...


RE: Problem with Project-tests - MGatner - 11-09-2019

Okay, I think I see what is happening. I believe you have the CodeIgniter "tests" folder in your root (this one: https://github.com/codeigniter4/CodeIgniter4/tree/develop/tests) but you are forcing it to the ProjectTests namespace via composer.json ("ProjectTests\\Support\\": "tests/_support"). Make sure you have removed the CodeIgniter tests folder and all subfolders, then copy in the version from CodeIgniter4Projects/ProjectTests.

If I'm wrong about that let me know and we'll try something else.