cypht
cypht copied to clipboard
Running local tests
💬 Question
What is the test methodology in cypht? Asking because I am trying to run at least the unit tests locally and getting failures.
$ cd /tests/phpunit
$ phpunit
PHPUnit 11.1.0 by Sebastian Bergmann and contributors.
Runtime: PHP 8.2.17
Configuration: /home/jono/src/cypht/tests/phpunit/phpunit.xml
.....FFFF................FEF..FFFF.......
ERRORS!
Tests: 168, Assertions: 374, Errors: 3, Failures: 10, Warnings: 4, Deprecations: 3401.
I see tests being run in the .travis dir, but I would think devs would want to run tests locally while they are working, not just in CI. Perhaps adding some development notes to the read me with instructions on how to run tests would be helpful.
@josaphatim please advise
@jonocodes please just make sure you have a database, database user and password with the value cypht_test
$config->set('db_host', '127.0.0.1');
$config->set('db_name', 'cypht_test');
$config->set('db_user', 'cypht_test');
$config->set('db_pass', 'cypht_test');
If not you can change setup_db function in tests/phpunit/mocks.php and also change Hm_Test_DB::test_build_dsn in tests/phpunit/db.php to your own values. You can add the port to db_host if not using 3306 for mysql
I personally run tests with php vendor/phpunit/phpunit/phpunit --configuration tests/phpunit/phpunit.xml
from the root folder
Thanks @josaphatim. By editing a few files and manually running some scripts I was able to get the tests to pass.
My suggestion is to make this frictionless, which would be fairly simple from what is there. The idea is I should be able to check out the code from git, and run a single command that will run the tests right away to see that they pass. This is very valuable for developers and new users. If we default to using sqlite instead of mysql this is very easy since no services need to be installed/started. So lets start by focusing on sqlite only, unit tests only.
Here is what I suggest.
- move /.github/tests/* into /tests/
- update .env and mocks.php to use sqlite
- automate the db setup. for now this is in setup.sh but that needs a bit of adjustment to work locally. it also should be using common table creation scripts, not its own.
I can probably work on this if it sounds good.
@kroky thoughts?
.github is specific to the CI, let's keep it there and not move it to tests.
+1 for the rest - devs should just be able to run phpunit and even selenium to execute their tests locally. If any specific setup is required and can't be done automatically, we should include documentation in a readme how to run the tests.
Ok, for now I wont move anything out of .github. I will start by copying it out an modifying it. Here is the basic idea: https://github.com/cypht-org/cypht/pull/1042