Updated Development (markdown)

El RIDO 2017-01-29 16:31:35 +01:00
parent c8c9f2bd44
commit 0332f5fe02

@ -24,31 +24,72 @@ More details can be found in the [API documentation](https://zerobin.dssr.ch/doc
## Unit Tests
### PHP
For unit tests of the php code the folder `tst/` can be used. Apart from helping to implement new features correctly it helps to keep regressions at bay. By default a code coverage report is generated after phpunit is run, the one of the latest release is [publicly](https://codeclimate.com/github/PrivateBin/PrivateBin/coverage) [available](https://www.codacy.com/app/PrivateBin/PrivateBin/files).
In order to run these tests, you will need the following packages and its dependencies:
In order to run these tests, you will need to install the following packages
and its dependencies:
* phpunit
* php5-gd
* php5-sqlite
* php5-xdebug
* php-gd
* php-sqlite3
* php-xdebug (for code coverage reports)
Example installation for Debian and Ubuntu:
$ sudo aptitude install phpunit php5-mysql php5-xdebug
To run the tests, just change into the `tst/` directory and run phpunit:
Example for Debian and Ubuntu:
```console
$ sudo apt install phpunit php-gd php-sqlite php-xdebug
```
To run the tests, just change into this directory and run phpunit:
```console
$ cd PrivateBin/tst
$ phpunit
```
Additionally there is the `configGenerator`. Based on the configurations defined in its constructor, it generates the unit test file `tst/configuration.php`, containing all possible combinations of these configurations and test for (most) valid combinations. Some of combinations can't be tested with this method, i.e. a valid option combined with an invalid one. Other very specific test cases (i.e. to trigger multiple errors) are covered in `tst/privatebin.php`. Here is how to generate the configuration test and run it:
Additionally there is the `ConfigurationTestGenerator`. Based on the configurations defined in its constructor, it generates the unit test file `tst/ConfigurationCombinationsTest.php`, containing all possible combinations of these configurations and test for (most) valid combinations. Some of combinations can't be tested with this method, i.e. a valid option combined with an invalid one. Other very specific test cases (i.e. to trigger multiple errors) are covered in `tst/PrivateBinTest.php`. Here is how to generate the configuration test and run it:
$ cd PrivateBin/tst
$ php configGenerator.php
$ phpunit configuration.php
$ php ConfigurationTestGenerator.php
$ phpunit ConfigurationCombinationsTest.php
Note that it can take an hour or longer to run the several thousand tests.
### JavaScript
For unit tests of the JS code the folder `js/` can be used. Apart from helping to implement new features correctly it helps to keep regressions at bay. By default a code coverage report is generated after istanbul is run.
In order to run these tests, you will need to install the following packages
and its dependencies:
* npm
Then you can use the node package manager to install the latest stable release
of mocha and istanbul (for code coverage reports) globally and jsVerify, jsdom
and jsdom-global locally:
```console
$ npm install -g mocha istanbul
$ cd PrivateBin/js
$ npm install jsverify jsdom jsdom-global
```
Example for Debian and Ubuntu, including steps to allow current user to install
node modules globally:
```console
$ sudo apt install npm
$ sudo mkdir /usr/local/lib/node_modules
$ sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
$ ln -s /usr/bin/nodejs /usr/local/bin/node
$ npm install -g mocha istanbul
$ cd PrivateBin/js
$ npm install jsverify jsdom jsdom-global
```
To run the tests, just change into the `js` directory and run istanbul:
```console
$ cd PrivateBin/js
$ istanbul cover _mocha
```
## Data Model
If you want to create your own data models, you might want to know how the arrays, that you have to store, look like: