Skip to content
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

Upgrade testing suite #654

Merged
merged 48 commits into from May 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
fd9f676
Update codesniffer version
ericpoe Mar 22, 2019
59efc0b
Update phpunit
ericpoe Mar 22, 2019
b0fa844
Take care of deprecated `@expectedException...`
ericpoe Mar 24, 2019
ec85bdf
Remove unused 'use' statement
ericpoe Mar 24, 2019
afa66e5
Add missing exception messages to tests
ericpoe Mar 24, 2019
1f951e4
Add missing exception codes to tests
ericpoe Mar 24, 2019
0a2b587
Fix spelling error in test name
ericpoe Mar 24, 2019
e569d4b
Convert getMock to createMock since the old getMock is no longer part of
ericpoe Mar 24, 2019
02218ea
Rename test to include the "test" prefix
ericpoe Mar 25, 2019
1a5c0c2
Remove test that doesn't really test anything
ericpoe Mar 25, 2019
4d807e4
Remove deprecated assertions that test internal details
ericpoe Mar 25, 2019
641aac2
Add coverage to composer scripts
ericpoe Mar 25, 2019
8bb3b42
Remove temp fix that is resovled with the new version of PHPUnit
ericpoe Mar 25, 2019
8722743
Add auto-generated phpunit cache file to gitignore
ericpoe Mar 25, 2019
ed3d95b
Use script-lang-aware codeblocks in documentation
ericpoe Mar 25, 2019
471ed89
Update codesniffer to have similar output to web2 codesniffer
ericpoe Mar 30, 2019
e2a47ed
Fix spelling
ericpoe Mar 30, 2019
c523acd
Remove setting deprecated since PHPUnit 5.2
ericpoe Mar 30, 2019
a901621
Replace deprecated phpunit setting with new setting
ericpoe Mar 30, 2019
91dc948
Remove no-longer valid log option 'title'
ericpoe Mar 31, 2019
2710717
Remove no-longer valid log option 'charset'
ericpoe Mar 31, 2019
f1b1a2a
Remove no-longer valid log option 'yui'
ericpoe Mar 31, 2019
6346455
emove no-longer valid log option 'highlight'
ericpoe Mar 31, 2019
ddc5794
Remove no-longer-allowed logIncompleteSkipped attribute in log
ericpoe Mar 31, 2019
379d0b3
Update exussum12/coverage-checker
ericpoe Mar 31, 2019
bb08764
Update phpunit
ericpoe Mar 31, 2019
f861c4d
Rename and move ruleset to phpcs.xml in the project root
ericpoe Mar 31, 2019
9c353aa
Match ruleset schema to what squizlabs uses
ericpoe Mar 31, 2019
ce37bf9
Move ignore-patterns from command line to phpcs.xml file
ericpoe Mar 31, 2019
0975c4e
grammar update
ericpoe Mar 31, 2019
148a3b2
Show how to run phpcs using composer
ericpoe Mar 31, 2019
ad0b9f9
Show how to use `composer sniff` to generate a summary
ericpoe Mar 31, 2019
3ee0102
Use phing for running and reporting on the sniff
ericpoe Mar 31, 2019
d551aeb
Use same phpunit explanation text as what is used for web2
ericpoe Mar 31, 2019
96b2aac
Remove unused use-statement
ericpoe Mar 31, 2019
04eeef3
Fix spelling error
ericpoe Mar 31, 2019
da00000
Replace nested will-return with an actuall willReturn
ericpoe Apr 1, 2019
97b66cd
Fix spelling error in test
ericpoe Apr 1, 2019
16644ae
Remove personalized docblock header
ericpoe Apr 1, 2019
5f2c849
Intentionally assert a count
ericpoe Apr 1, 2019
cc165d5
Remove unused mock
ericpoe Apr 1, 2019
02be936
Change from implicit $this->talk_mapper to explicit use
ericpoe Apr 1, 2019
802fb9e
Update phpunit
ericpoe Apr 5, 2019
c3210ad
Ensure tests pass when xdebug is not enabled
ericpoe May 2, 2019
10c2bf4
Fix capitalization
ericpoe May 2, 2019
7b98cf5
Simplify phpcs config
ericpoe May 3, 2019
4d3c6bc
Use nicer reasons for skipped tests when xdebug not enabled
ericpoe May 3, 2019
0afa833
Merge branch 'master' into upgradeTestingSuite
ericpoe May 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -11,3 +11,5 @@ vendor/.git
node_modules
vendor
diff.txt
.phpunit.result.cache
.phpcs-cache
79 changes: 53 additions & 26 deletions README.md
Expand Up @@ -24,7 +24,6 @@ There's more documentation here: http://joindin.github.io/joindin-api/ - it's po

We are happy for you to make whatever use of the API you wish (bear in mind we run everything from a single donated server so please implement some caching on your side and be considerate of the traffic levels you send to us). Please mention the source of your data, but do not use "joind.in" in your project name or imply that the joind.in project endorses your project.


## Tools and Tests

### API Tests
Expand All @@ -34,66 +33,92 @@ We have tests that make HTTP requests from the outside of the API, functional te
To run the frisby tests (frisby.js), you will first need to install node.js and
npm on you computer. Then run:

cd tests/frisby
npm install
```bash
cd tests/frisby
npm install
```

To run the tests on your computer against your Vagrant VM, from the `tests/frisby` directory run:

npm test
```bash
npm test
```

We also have a set of "destructive" tests, these create, edit and delete data as well as just reading it. These aren't safe to run on a live platform, but are very valuable in testing. Before you run them, you will need to run this query against your database:

insert into oauth_consumers (consumer_key, consumer_secret, user_id, enable_password_grant) values ('0000', '1111', '1', '1');
```sql
insert into oauth_consumers (consumer_key, consumer_secret, user_id, enable_password_grant) values ('0000', '1111', '1', '1');
```

Then run:

npm run test_write

```bash
npm run test_write
```

#### Proxying the frisy tests
#### Proxying the frisby tests

If you want to proxy the frisby tests via Charles or another proxy, then export `HTTP_PROXY` first:

export HTTP_PROXY=http://localhost:8888

You can now run `npm run test_write` or `npm test` as required and all the network requests will go via the proxy.


### Unit Tests

There are some tests set up, which use PHPUnit; these can be found in the
tests directory. There is a phing task
configured to run them - from the root directory simply run `phing phpunit` to run
the tests. Unfortunately, there will be no output about whether the tests passed
or failed from the phing target. A better way to test when you are developing is
to run the tests from within the tests directory by just typing
`phpunit`. The phpunit.xml in each directory will configure the bootstrap as well
as any files that should not be included.
### Testing Code
We use [PHPUnit](https://phpunit.de/documentation.html) for running unit tests against the joindin-api codebase.
To run PHPUnit tests, you can go the classic route:
```bash
vendor/bin/phpunit -c . tests/
```
You can also use composer to run your tests:
```bash
composer test
```
### Code Coverage
Code coverage requires that [xdebug](https://xdebug.org/) be running. If you are using the joindin-vm Vagrant box, you can run your tests from within vagrant:
```bash
vagrant ssh
xon # note: this turns on xdebug
cd ~/joindin-vm/joindin-api
composer test
```
You can see your code coverage report by going to http://localhost:63342/joindin-api/build/coverage/index.html

### Database Patches

If you need to include a new patch, then create the SQL needed and add it to the next patch number in the `db` directory. You need to include a line that looks like this at the end of your script:

INSERT INTO patch_history SET patch_number = 17;
```sql
INSERT INTO patch_history SET patch_number = 17;
```

The number in that line should match the filename of your new patch number - check out the existing database patches in the project for examples.

### Coding Style

Please do your best to ensure that any code you contributed adheres to the
Joind.in coding style. This is the PSR-2 coding standard with
no namespaces. You can run php codesniffer using phing on an
individual file like so:
Joind.in coding style -- this is the PSR-2 coding standard with no namespaces.
You can run php codesniffer on an individual file like so:

phing phpcs-human -Dfilename.php
```bash
vendor/bin/phpcs path/of/filename.php
```

This will run codesniffer on any file within the regular source for Joind.in or the
API-v2 source. Wildcards work as does specifying part of the path in case the
filename alone results in sniffing more files than you wanted.

To see the codesniff errors and warnings across the entire project, run

```bash
composer sniff
```

To see a summary of the codesniff errors and warnings across the entire project, run

phing phpcs-human-summary
```bash
composer sniff -- --report=summary
```

#### Inline Documentation

Expand Down Expand Up @@ -122,7 +147,9 @@ projects too.
You can define the gitignore file with a command that looks like this, where the
last argument is the file that holds the patterns to ignore:

$ git config --global core.excludesfile ~/.gitignore_global
```bash
git config --global core.excludesfile ~/.gitignore_global
```

Octocat gives [a good starting point](https://gist.github.com/octocat/9257657) for
what to include, but you can also ignore the files used by your editor:
Expand Down
28 changes: 1 addition & 27 deletions build.xml
Expand Up @@ -46,35 +46,9 @@
</target>

<target name="phpcs" description="Generate checkstyle.xml using PHP_CodeSniffer">
<exec command="composer sniff"/>
<exec command="vendor/bin/phpcs --extensions=php --report-checkstyle=build/logs/checkstyle.xml --runtime-set ignore_warnings_on_exit true -p ."/>
</target>

<target name="phpcs-human-summary" description="Generate human-readable Codesniffer output">
<phpcodesniffer standard="tools/codesniffer/JoindInPSR2/">
<fileset dir="${apiv2source}">
<patternset>
<include name="**/*.php"/>
<exclude name="**/config.php" />
<exclude name="**/database.php" />
</patternset>
</fileset>
<formatter type="summary" usefile="false" />
</phpcodesniffer>
</target>

<target name="phpcs-human" description="Check codes style with PHP_CodeSniffer">
<phpcodesniffer standard="tools/codesniffer/JoindInPSR2/">
<fileset dir="${apiv2source}">
<patternset>
<include name="**/*.php"/>
<exclude name="**/config.php" />
<exclude name="**/database.php" />
</patternset>
</fileset>
<formatter type="full" usefile="false" />
</phpcodesniffer>
</target>

<target name="lint" description="Run linter over the fileset">
<exec command="composer lint" logoutput="true" checkreturn="true" />
</target>
Expand Down
13 changes: 7 additions & 6 deletions composer.json
Expand Up @@ -19,9 +19,10 @@
"swiftmailer/swiftmailer": "^v5.4.9"
},
"require-dev": {
"exussum12/coverage-checker": "^0.11.0",
"exussum12/coverage-checker": "^0.11.1",
"jakub-onderka/php-parallel-lint": "^1.0",
"phpunit/phpunit": "^5.7",
"phpunit/php-invoker": "^2.0",
"phpunit/phpunit": "^8.1",
"roave/security-advisories": "dev-master",
"sensiolabs/security-checker": "^5.0",
"squizlabs/php_codesniffer": "^3.4"
Expand Down Expand Up @@ -49,13 +50,12 @@
"tests/models",
"tests/routers",
"tests/views"
],
"files": ["tests/compatibility/File.php"]
]
},
"scripts": {
"test": "phpunit -c . tests/",
"lint": "parallel-lint --exclude vendor .",
"sniff": "phpcs --standard=tools/codesniffer/JoindInPSR2/ruleset.xml --ignore=**/config.php,**/database.php,vendor,tools,tests/bootstrap.php --extensions=php --report-checkstyle=build/logs/checkstyle.xml --runtime-set ignore_warnings_on_exit true -p .",
"sniff": "phpcs --runtime-set ignore_warnings_on_exit true -p .",
"security": "security-checker security:check composer.lock",
"coverage": [
"git diff origin/master... -- > diff.txt",
Expand All @@ -66,7 +66,8 @@
"@lint",
"@sniff",
"@security",
"@test"
"@test",
"@coverage"
]
},
"config": {
Expand Down