Skip to content

Commit cf5b119

Browse files
authored
Create experimental builder (mongodb#1)
1 parent a52d35e commit cf5b119

File tree

633 files changed

+27191
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

633 files changed

+27191
-10
lines changed

.gitattributes

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
.* export-ignore
22
*.md export-ignore
3+
generator export-ignore
34
tests export-ignore
4-
docs export-ignore
5-
examples export-ignore
6-
mongo-orchestration export-ignore
7-
stubs export-ignore
8-
tools export-ignore
95
phpcs.xml.dist export-ignore
10-
phpunit.evergreen.xml export-ignore
116
phpunit.xml.dist export-ignore
127
psalm.xml.dist export-ignore
138
psalm-baseline.xml export-ignore
9+
10+
# Keep generated files from displaying in diffs by default
11+
# https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github
12+
/src/Builder/Accumulator/*.php linguist-generated=true
13+
/src/Builder/Expression/*.php linguist-generated=true
14+
/src/Builder/Query/*.php linguist-generated=true
15+
/src/Builder/Projection/*.php linguist-generated=true
16+
/src/Builder/Stage/*.php linguist-generated=true

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
blank_issues_enabled: false
2+
23
contact_links:
34
- name: MongoDB PHP library
45
url: https://github.com/mongodb/mongo-php-library/issues/new/choose
56
about: Experiencing a problem with mongo-php-builder? Please report it through the mongo-php-library repository.
7+
- name: MongoDB Developer Community Forums
8+
url: https://developer.mongodb.com/community/forums/
9+
about: For questions, discussions, or general technical support, visit the MongoDB Community Forums. The MongoDB Community Forums are a centralized place to connect with other MongoDB users, ask questions, and get answers.
10+
- name: Report a Security Vulnerability
11+
url: https://mongodb.com/docs/manual/tutorial/create-a-vulnerability-report
12+
about: If you believe you have discovered a vulnerability in MongoDB products or have experienced a security incident related to MongoDB products, please report the issue to aid in its resolution.

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: "Coding Standards"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "[0-9]+.[0-9]+"
7+
- "feature/*"
8+
paths-ignore:
9+
- "docs/**"
10+
push:
11+
branches:
12+
- "[0-9]+.[0-9]+"
13+
- "feature/*"
14+
paths-ignore:
15+
- "docs/**"
16+
17+
env:
18+
PHP_VERSION: "8.2"
19+
DRIVER_VERSION: "mongodb/mongo-php-driver@master"
20+
21+
jobs:
22+
phpcs:
23+
name: "phpcs"
24+
runs-on: "ubuntu-22.04"
25+
26+
steps:
27+
- name: "Checkout"
28+
uses: "actions/checkout@v4"
29+
30+
- name: Setup cache environment
31+
id: extcache
32+
uses: shivammathur/cache-extensions@v1
33+
with:
34+
php-version: ${{ env.PHP_VERSION }}
35+
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
36+
key: "extcache-v1"
37+
38+
- name: Cache extensions
39+
uses: actions/cache@v3
40+
with:
41+
path: ${{ steps.extcache.outputs.dir }}
42+
key: ${{ steps.extcache.outputs.key }}
43+
restore-keys: ${{ steps.extcache.outputs.key }}
44+
45+
- name: "Install PHP"
46+
uses: "shivammathur/setup-php@v2"
47+
with:
48+
coverage: "none"
49+
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
50+
php-version: "${{ env.PHP_VERSION }}"
51+
tools: "cs2pr"
52+
53+
- name: "Show driver information"
54+
run: "php --ri mongodb"
55+
56+
- name: "Install dependencies with Composer"
57+
uses: "ramsey/[email protected]"
58+
with:
59+
composer-options: "--no-suggest"
60+
61+
# The -q option is required until phpcs v4 is released
62+
- name: "Run PHP_CodeSniffer"
63+
run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr"

.github/workflows/static-analysis.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: "Static Analysis"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "[0-9]+.[0-9]+"
7+
- "feature/*"
8+
paths-ignore:
9+
- "docs/**"
10+
push:
11+
branches:
12+
- "[0-9]+.[0-9]+"
13+
- "feature/*"
14+
paths-ignore:
15+
- "docs/**"
16+
17+
env:
18+
PHP_VERSION: "8.2"
19+
DRIVER_VERSION: "mongodb/mongo-php-driver@master"
20+
21+
jobs:
22+
psalm:
23+
name: "Psalm"
24+
runs-on: "ubuntu-22.04"
25+
26+
steps:
27+
- name: "Checkout"
28+
uses: "actions/checkout@v4"
29+
30+
- name: Setup cache environment
31+
id: extcache
32+
uses: shivammathur/cache-extensions@v1
33+
with:
34+
php-version: ${{ env.PHP_VERSION }}
35+
extensions: "mongodb-${{ ENV.DRIVER_VERSION }}"
36+
key: "extcache-v1"
37+
38+
- name: Cache extensions
39+
uses: actions/cache@v3
40+
with:
41+
path: ${{ steps.extcache.outputs.dir }}
42+
key: ${{ steps.extcache.outputs.key }}
43+
restore-keys: ${{ steps.extcache.outputs.key }}
44+
45+
- name: "Install PHP"
46+
uses: "shivammathur/setup-php@v2"
47+
with:
48+
coverage: "none"
49+
extensions: "mongodb-${{ ENV.DRIVER_VERSION }}"
50+
php-version: "${{ env.PHP_VERSION }}"
51+
tools: "cs2pr"
52+
53+
- name: "Show driver information"
54+
run: "php --ri mongodb"
55+
56+
- name: "Install dependencies with Composer"
57+
uses: "ramsey/[email protected]"
58+
with:
59+
composer-options: "--no-suggest"
60+
61+
- name: "Run Psalm"
62+
run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc)"

.github/workflows/tests.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: "Tests"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "[0-9]+.[0-9]+"
7+
- "feature/*"
8+
paths-ignore:
9+
- "docs/**"
10+
push:
11+
branches:
12+
- "[0-9]+.[0-9]+"
13+
- "feature/*"
14+
paths-ignore:
15+
- "docs/**"
16+
17+
jobs:
18+
phpunit:
19+
name: "PHPUnit tests"
20+
runs-on: "${{ matrix.os }}"
21+
22+
strategy:
23+
fail-fast: true
24+
matrix:
25+
os:
26+
- "ubuntu-20.04"
27+
php-version:
28+
- "8.1"
29+
- "8.2"
30+
- "8.3"
31+
mongodb-version:
32+
- "4.4"
33+
driver-version:
34+
- "mongodb/mongo-php-driver@master"
35+
topology:
36+
- "server"
37+
include:
38+
- os: "ubuntu-20.04"
39+
php-version: "8.1"
40+
mongodb-version: "6.0"
41+
driver-version: "mongodb/mongo-php-driver@master"
42+
topology: "replica_set"
43+
- os: "ubuntu-20.04"
44+
php-version: "8.1"
45+
mongodb-version: "6.0"
46+
driver-version: "mongodb/mongo-php-driver@master"
47+
topology: "sharded_cluster"
48+
- os: "ubuntu-20.04"
49+
php-version: "8.1"
50+
mongodb-version: "5.0"
51+
driver-version: "mongodb/mongo-php-driver@master"
52+
topology: "server"
53+
- os: "ubuntu-20.04"
54+
php-version: "8.1"
55+
mongodb-version: "4.4"
56+
driver-version: "mongodb/mongo-php-driver@master"
57+
topology: "replica_set"
58+
- os: "ubuntu-20.04"
59+
php-version: "8.1"
60+
mongodb-version: "4.4"
61+
driver-version: "mongodb/mongo-php-driver@master"
62+
topology: "sharded_cluster"
63+
64+
steps:
65+
- name: "Checkout"
66+
uses: "actions/checkout@v4"
67+
with:
68+
fetch-depth: 2
69+
70+
- id: setup-mongodb
71+
uses: mongodb-labs/drivers-evergreen-tools@master
72+
with:
73+
version: ${{ matrix.mongodb-version }}
74+
topology: ${{ matrix.topology }}
75+
76+
- name: Setup cache environment
77+
id: extcache
78+
uses: shivammathur/cache-extensions@v1
79+
with:
80+
php-version: ${{ matrix.php-version }}
81+
extensions: "mongodb-${{ matrix.driver-version }}"
82+
key: "extcache-v1"
83+
84+
- name: Cache extensions
85+
uses: actions/cache@v3
86+
with:
87+
path: ${{ steps.extcache.outputs.dir }}
88+
key: ${{ steps.extcache.outputs.key }}
89+
restore-keys: ${{ steps.extcache.outputs.key }}
90+
91+
- name: "Install PHP"
92+
uses: "shivammathur/setup-php@v2"
93+
with:
94+
php-version: "${{ matrix.php-version }}"
95+
tools: "pecl"
96+
extensions: "mongodb-${{ matrix.driver-version }}"
97+
coverage: "none"
98+
ini-values: "zend.assertions=1"
99+
100+
- name: "Show driver information"
101+
run: "php --ri mongodb"
102+
103+
- name: "Install dependencies with Composer"
104+
uses: "ramsey/[email protected]"
105+
with:
106+
composer-options: "--no-suggest"
107+
108+
- name: "Run PHPUnit"
109+
run: "vendor/bin/simple-phpunit -v"
110+
env:
111+
SYMFONY_DEPRECATIONS_HELPER: 999999
112+
MONGODB_URI: ${{ steps.setup-mongodb.outputs.cluster-uri }}

CONTRIBUTING.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Contributing to the PHP Builder for MongoDB
2+
3+
## Initializing the Repository
4+
5+
Developers who would like to contribute to the library will need to clone it and
6+
initialize the project dependencies with [Composer](https://getcomposer.org/):
7+
8+
```
9+
$ git clone https://github.com/mongodb/mongo-php-builder.git
10+
$ cd mongo-php-builder
11+
$ composer update
12+
```
13+
14+
In addition to installing project dependencies, Composer will check that the
15+
required extension version is installed. Directions for installing the extension
16+
may be found [here](https://php.net/manual/en/mongodb.installation.php).
17+
18+
Installation directions for Composer may be found in its
19+
[Getting Started](https://getcomposer.org/doc/00-intro.md) guide.
20+
21+
## Testing
22+
23+
The library's test suite uses [PHPUnit](https://phpunit.de/), which is installed
24+
through the [PHPUnit Bridge](https://symfony.com/phpunit-bridge) dependency by
25+
Composer.
26+
27+
The test suite may be executed with:
28+
29+
```console
30+
$ composer run test
31+
```
32+
33+
The `phpunit.xml.dist` file is used as the default configuration file for the
34+
test suite. In addition to various PHPUnit options, it defines environment
35+
variables such as `MONGODB_URI` and `MONGODB_DATABASE`. You may customize
36+
this configuration by creating your own `phpunit.xml` file based on the
37+
`phpunit.xml.dist` file we provide.
38+
39+
By default, the `simple-phpunit` binary chooses the correct PHPUnit version for
40+
the PHP version you are running. To run tests against a specific PHPUnit
41+
version, use the `SYMFONY_PHPUNIT_VERSION` environment variable:
42+
43+
```console
44+
$ SYMFONY_PHPUNIT_VERSION=8.5 vendor/bin/simple-phpunit
45+
```
46+
47+
### Environment Variables
48+
49+
The test suite references the following environment variables:
50+
51+
* `MONGODB_DATABASE`: Default database to use in tests. Defaults to
52+
`phplib_test`.
53+
* `MONGODB_PASSWORD`: If specified, this value will be appended as the
54+
`password` URI option for clients constructed by the test suite, which will
55+
override any credentials in the connection string itself.
56+
* `MONGODB_URI`: Connection string. Defaults to `mongodb://127.0.0.1/`, which
57+
assumes a MongoDB server is listening on localhost port 27017.
58+
* `MONGODB_USERNAME`: If specified, this value will be appended as the
59+
`username` URI option for clients constructed by the test suite, which will
60+
override any credentials in the connection string itself.
61+
62+
## Code quality
63+
64+
Before submitting a pull request, please ensure that your code adheres to the
65+
coding standards and passes static analysis checks.
66+
67+
```console
68+
$ composer run checks
69+
```
70+
71+
### Coding standards
72+
73+
The library's code is checked using [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer),
74+
which is installed as a development dependency by Composer. To check the code
75+
for style errors, run the `phpcs` binary:
76+
77+
```console
78+
$ vendor/bin/phpcs
79+
```
80+
81+
To automatically fix all fixable errors, use the `phpcbf` binary:
82+
83+
```console
84+
$ vendor/bin/phpcbf
85+
```
86+
87+
### Static analysis
88+
89+
The library uses [psalm](https://psalm.dev) to run static analysis on the code
90+
and ensure an additional level of type safety. New code is expected to adhere
91+
to level 1, with a baseline covering existing issues. To run static analysis
92+
checks, run the `psalm` binary:
93+
94+
```console
95+
$ vendor/bin/psalm
96+
```
97+
98+
To remove fixed errors from the baseline, you can use the `update-baseline`
99+
command-line argument:
100+
101+
```console
102+
$ vendor/bin/psalm --update-baseline
103+
```
104+
105+
Note that this will not add new errors to the baseline. New errors should be
106+
fixed instead of being added to the technical debt, but in case this isn't
107+
possible it can be added to the baseline using `set-baseline`:
108+
109+
```console
110+
$ vendor/bin/psalm --set-baseline=psalm-baseline.xml
111+
```
112+
113+
## Releasing
114+
115+
The releases are created by the maintainers of the library. The process is documented in
116+
the [RELEASING.md](RELEASING.md) file.

0 commit comments

Comments
 (0)