Skip to content

Add composer scripts #1120

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

Merged
merged 2 commits into from
Jun 29, 2023
Merged
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
38 changes: 23 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Composer.

The test suite may be executed with:

```
$ vendor/bin/simple-phpunit
```console
$ composer run test
```

The `phpunit.xml.dist` file is used as the default configuration file for the
Expand All @@ -47,8 +47,8 @@ By default, the `simple-phpunit` binary chooses the correct PHPUnit version for
the PHP version you are running. To run tests against a specific PHPUnit
version, use the `SYMFONY_PHPUNIT_VERSION` environment variable:

```
$ SYMFONY_PHPUNIT_VERSION=7.5 vendor/bin/simple-phpunit
```console
$ SYMFONY_PHPUNIT_VERSION=8.5 vendor/bin/simple-phpunit
```

### Environment Variables
Expand Down Expand Up @@ -108,55 +108,63 @@ The following environment variables are used for [CSFLE testing](https://github.
* `KMS_TLS_CA_FILE`
* `KMS_TLS_CERTIFICATE_KEY_FILE`

## Checking coding standards
## Code quality

Before submitting a pull request, please ensure that your code adheres to the
coding standards and passes static analysis checks.

```console
$ composer run checks
```

### Coding standards

The library's code is checked using [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer),
which is installed as a development dependency by Composer. To check the code
for style errors, run the `phpcs` binary:


```
```console
$ vendor/bin/phpcs
```

To automatically fix all fixable errors, use the `phpcbf` binary:

```
```console
$ vendor/bin/phpcbf
```

## Running static analysis
### Static analysis

The library uses [psalm](https://psalm.dev) to run static analysis on the code
and ensure an additional level of type safety. New code is expected to adhere
to level 1, with a baseline covering existing issues. To run static analysis
checks, run the `psalm` binary:

```
```console
$ vendor/bin/psalm
```

To remove fixed errors from the baseline, you can use the `update-baseline`
command-line argument:

```
```console
$ vendor/bin/psalm --update-baseline
```

Note that this will not add new errors to the baseline. New errors should be
fixed instead of being added to the technical debt, but in case this isn't
possible it can be added to the baseline using `set-baseline`:

```
```console
$ vendor/bin/psalm --set-baseline=psalm-baseline.xml
```

## Automatic code refactoring
### Refactoring

The library uses [rector](https://getrector.com/) to refactor the code for new features.
To run automatic refactoring, use the `rector` command:

```
```console
$ vendor/bin/rector
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to change this to the fix: or check: command? Or are you intentionally calling the original binary here?

Copy link
Member Author

@GromNaN GromNaN Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really hesitated. In the end, I think we should offer the 2 entry points into the document: Composer scripts in the header and the path to the binaries in details.

```

Expand All @@ -178,7 +186,7 @@ repository:
repository.
* Create and activate Python 2.7 virtual environment if necessary.

```
```console
$ virtualenv -p python2.7 venv
$ source venv/bin/activate
```
Expand Down
12 changes: 6 additions & 6 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ the Evergreen configuration should be updated:

Commit and push any changes:

```
```console
$ git commit -m "Update composer.json and CI matrices for X.Y.Z" composer.json .evergreen/config.yml
$ git push mongodb
```
Expand All @@ -85,7 +85,7 @@ $ git push mongodb

Create a tag for the release and push:

```
```console
$ git tag -a -m "Release X.Y.Z" X.Y.Z
$ git push mongodb --tags
```
Expand Down Expand Up @@ -119,7 +119,7 @@ The above would be changed to:

Commit this change:

```
```console
$ git commit -m "Master is now 1.10-dev" composer.json
```

Expand All @@ -128,7 +128,7 @@ $ git commit -m "Master is now 1.10-dev" composer.json
After a new minor version is released (i.e. `master` was tagged), a maintenance
branch should be created for future patch releases:

```
```console
$ git checkout -b vX.Y
$ git push mongodb vX.Y
```
Expand All @@ -146,7 +146,7 @@ Update the master branch alias in `composer.json`:

Commit and push this change:

```
```console
$ git commit -m "Master is now X.Y-dev" composer.json
$ git push mongodb
```
Expand All @@ -155,7 +155,7 @@ $ git push mongodb

If this was a patch release, the maintenance branch must be merged up to master:

```
```console
$ git checkout master
$ git pull mongodb master
$ git merge vX.Y --strategy=ours
Expand Down
17 changes: 16 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"license": "Apache-2.0",
"authors": [
{ "name": "Andreas Braun", "email": "andreas.braun@mongodb.com" },
{ "name": "Jeremy Mikola", "email": "jmikola@gmail.com" }
{ "name": "Jeremy Mikola", "email": "jmikola@gmail.com" },
{ "name": "Jérôme Tamarelle", "email": "jerome.tamarelle@mongodb.com" }
],
"require": {
"php": "^7.2 || ^8.0",
Expand All @@ -33,6 +34,20 @@
"psr-4": { "MongoDB\\Tests\\": "tests/" },
"files": [ "tests/PHPUnit/Functions.php" ]
},
"scripts": {
"checks": [
"@check:cs",
"@check:psalm",
"@check:rector"
],
"check:cs": "phpcs",
"check:psalm": "psalm",
"check:rector": "rector --ansi --dry-run",
"fix:cs": "phpcbf",
"fix:psalm:baseline": "psalm --set-baseline=psalm-baseline.xml",
"fix:rector": "rector process --ansi",
"test": "simple-phpunit"
},
"extra": {
"branch-alias": {
"dev-master": "1.17.x-dev"
Expand Down