Skip to content

[Documentation:Developer] Improve php unit test instructions #686

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions _docs/developer/testing/install_php.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ If you are missing extensions you can install them with `PECL` which will be
installed automatically with PHP, but you should have everything required by
default.

### Windows

Download [php 8.1](https://windows.php.net/download/) as a zip file under the thread safe category. Then extract the contents of the zip to a folder, and add the path to that folder to your path system variable. It's suggested that one extracts the contents of the zip to a folder called `php`, which can be put at `C:\php` for simplicity. You can then add `C:\php` to your path system environment variable.

-------------

Verify you have PHP installed correctly, submitty requires a version greater than 7.0
Expand Down
2 changes: 1 addition & 1 deletion _docs/developer/testing/linting_static_analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The following instructions were tested for Windows:

1. First, you will need PHP installed on your host system first. See [Installing PHP](/developer/testing/install_php)*

2. Next, you will need [Composer](https://getcomposer.org/doc/00-intro.md) installed on your host system as well.
2. Next, you will need [Composer](https://getcomposer.org/download/) installed on your host system as well.
During this install, you will need to change settings in a php.ini file. Change the settings the prompt recommends.

3. Run ``composer global require slevomat/coding-standard`` and ``composer global require "squizlabs/php_codesniffer=*"`` inside your terminal.
Expand Down
19 changes: 12 additions & 7 deletions _docs/developer/testing/php_unit_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,41 @@ category: Developer > Development Instructions > Continuous Integration Testing
To validate the unit behavior of the site code, we utilize
[phpunit](https://phpunit.readthedocs.io/en/latest).

*If tests are failing for you even on main, you may need to run `apt install php-sqlite3`, especially if you haven't vagrant upped from scratch in a while.*

### Running PHP Unit Tests

*You will need PHP installed on your host system first, see [Installing PHP](/developer/testing/install_php)*
*If you are running on WSL and are seeing errors, remove `php` from the following commands.*

To run the PHP unit test suite locally, `cd` to the `Submitty/site` directory and type:
To run the PHP unit test suite in VM use the alias

If you are running on WSL and are seeing errors, remove "`php`" from the following commands.
```
submitty_test php-unit
```

or

```
php vendor/bin/phpunit
sudo -u submitty_php php vendor/bin/phpunit
```

To run just an individual class or test, you can use the `--filter` flag on PHPUnit.
For example, to run the function `testInvalidProperty` would be
`php vendor/bin/phpunit --filter testInvalidProperty` and running all
`sudo -u submitty_php php vendor/bin/phpunit --filter testInvalidProperty` and running all
of `AccessControlTester` would be
`php vendor/bin/phpunit--filter AccessControlTester`. Be aware, filter
can match against partial strings, so if you have two tests `testFoo` and `testFooBar`,
running `--filter testFoo` will run them both. Alternatively, you can also directly run
`phpunit` against a specific class by passing the path to the test class directly to
`phpunit`, for example
`php vendor/bin/phpunit tests/app/authentication/DatabaseAuthenticationTester.php` will run
`sudo -u submitty_php php vendor/bin/phpunit tests/app/authentication/DatabaseAuthenticationTester.php` will run
only the test methods in `DatabaseAuthenticationTester.php`.

The two concepts above can be combined to run a specific test function in a specific
class by doing:

```bash
vendor/bin/phpunit --filter testFunction tests/app/path/to/TestClass.php
sudo -u submitty_php php vendor/bin/phpunit --filter testFunction tests/app/path/to/TestClass.php
```

You can pass in the `--debug` flag when using PHPUnit to see PHP output, this can be
Expand Down
Loading