How to access models in tests #15502
Replies: 1 comment
-
For the main repo (cphalcon) we are using Codeception for our tests. I am not sure what you are using but this might give you some ideas on how to bootstap things. The configuration file of codeception will execute/require a file called https://github.com/phalcon/cphalcon/blob/master/codeception.yml#L23 You can add whatever you want in that file to set your environment up. Another more robust example for the database tests: https://github.com/phalcon/cphalcon/blob/master/tests/database.suite.yml#L5 Here we point to the https://github.com/phalcon/cphalcon/blob/master/tests/_config/bootstrap.php |
Beta Was this translation helpful? Give feedback.
-
Hi!
I am trying to write a test using PHPUnit, and I want to access my Users model.
I have followed the instructions on setting up PHPUnit at https://docs.phalcon.io/4.0/en/unit-testing.
I have this in my composer.json:
"autoload-dev": { "psr-4": { "Tests\\": "tests" } }
My loader looks like this:
$loader = new \Phalcon\Loader(); $loader->registerDirs( [ $config->application->controllersDir, $config->application->modelsDir, ] )->register();
I can't figure out how to access my classes during a test
The following throws an error:
$user = new \User;
Beta Was this translation helpful? Give feedback.
All reactions