-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Unit testing using Codeception #26
Comments
Thank you, this will be very helpful. I assume Because I use Docker, I'll need to persist that unit tests folder so I don't lose I'll have to tweak some of the hardcoded I am thinking the simplest way for me to run these development tools in my development installs is to create a development tag on my Docker Grav platform image. The image can include this and #25, and eventually my Xdebug integration (when I get it working!). Great tools! I'll let you know when I've run these tests successfully and presumably you can close the issue after that. |
assume _before() runs before any test, so I'd need to hook this up with a disposable installation because of clearFiles(). Can do.
That's correct. The _before() is run before every test and is quite destructive.
In my setup, the pushy code is located outside of the pushy website and added to the "/user/plugin" folder using a symbolic link.
```
/www/grav/
add-ons/
plugins/
contactform/
pushy/
themes/
/base
site-dev/
site-pushy/
user/plugins/pushy = symlink to ./www/grav/add-ons/plugins/pushy
```
This way I can easily clear/setup site-pushy/user/pages folder.
I'll have to tweak some of the hardcoded PushyTest.php paths and local URLs too.
Ideally, the unit tests should be added to pushy itself and added to Git.
However, since we have different environment setups, it cannot be hardcoded
to pushy (yet). That's why I provided a script.
Yes, all urls/paths need to be adapted to your setup.
I cannot be any help on Docker. I've looked at it a few times, but it's
just too complex for me...
|
I'm running There was 1 error:
---------
1) PushyTest: Read items
Test tests/unit/PushyTest.php:testReadItems
[TypeError] array_merge(): Argument #1 must be of type array, null given
#1 /var/www/grav/user/shared/plugins/pushy/vendor/bin/codecept:119
ERRORS!
Tests: 1, Assertions: 0, Errors: 1. (Initially I ran all unit tests and also saw this message for the Publish Items test.) I've tweaked your code snippet for working paths. I've confirmed the URL used retrieving I changed into the plugin directory before running the I suspect I missed or did something wrong setting this up. |
I've update the instructions in first post.
|
Thanks. I'm still seeing the same error, unfortunately.
My setup is very similar. I usually keep plugins/themes, that are shared or I hack on, in their own path and symlink them as required. It's a bit more complicated than that, but effectively that is a working setup. Symlinks generally seem transparent although I have noticed traversing using parent expressions like Going back a step, I actually finally got to trying out your instructions here because I am building a new plugin and wanted to drive it with tests from the start (TDD!). This plugin currently sits under a site's I think next I will try your instructions in this new plugin with a dummy test and see if I have more luck there. Thanks for your patient explanations! |
I was able to run a dummy unit test, but hit other problems when I tried to assert anything. Examples in Codeception docs are also throwing errors. Seems something is not bootstrapping or loading properly. I need to move onto other tasks. I will contact you offline because it's a bit tedious troubleshooting this here. |
When updating the setup script shown above an error was thrown about not existing
|
I had made that change and it's not solving it for me :/ |
Just to be sure, a setup with a fresh copy of Grav and fresh plugin... In my previous tests, an older version of Codeception 4.2 was lingering around while 5.0 is out. I presume your dev environment is PHP 8.x Setup:
Note, no need to change any PHP version in composer.json inside the plugin. |
Thanks. I finally got to testing this and it worked with the clean install. I ran the previous tests on "clean" installs, except I reused/persisted I think (from faulty memory) I have also tried this with another instance/container and got the same result. Let me try some others and get back to you. |
Updated 2023-08-21
The following will add Unit tests using Codeception.
I don't know how you've setup your dev environment. I've separated themes/plugins I develop into folders outside the root of Grav and use symlinks to add the plugin.
Create fresh install of Grav + Admin
Add pushy as plugin (either regular or symlinked)
$ cd user/plugins/pushy
Edit composer.json to use higher PHP versions required by Grav:
$ composer require --dev codeception/codeception
$ vendor/bin/codecept bootstrap
$ vendor/bin/codecept generate:test unit Pushy
Copy the following into /tests/unit/PushyTests.php.
The code will:
Run the following commands:
$ vendor/bin/codecept run --debug unit
$ vendor/bin/codecept run --debug unit PushyTest
$ vendor/bin/codecept run --debug unit PushyTest::testReadItems
$ vendor/bin/codecept run --debug unit PushyTest::testPublishItems
The text was updated successfully, but these errors were encountered: