Skip to content

Commit ab4b611

Browse files
authored
docs(PubSub): README improvements (#2097)
1 parent 7dd8e32 commit ab4b611

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

pubsub/api/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,67 @@ Usage: create_topic.php $projectId $topicName
6464
@param string $topicName The Pub/Sub topic name.
6565
```
6666

67+
## PHPUnit Tests
68+
69+
At this time, the GitHub actions in this repo fail to run the tests written in this folder. The developer is responsible for locally running and confirming their samples and corresponding tests.
70+
71+
### PubSub Emulator
72+
Some tests in the pubsubTest.php requires PubSub emulator. These tests start with ```$this->requireEnv('PUBSUB_EMULATOR_HOST')```.
73+
74+
#### Prerequisites
75+
- Python
76+
```
77+
xcode-select --install
78+
brew install pyenv
79+
pyenv install <version>
80+
python3 --version
81+
```
82+
- JDK
83+
```
84+
brew install openjdk
85+
export JAVA_HOME=<path to openjdk folder>
86+
export PATH="$JAVA_HOME/bin:$PATH"
87+
```
88+
89+
Once python, JDK, and GCloud CLI are installed, follow [these instructions](https://cloud.google.com/pubsub/docs/emulator) to run the emulator.
90+
91+
### Setting up environment variables
92+
Open a new tab in terminal, separate from the one running your emulator.
93+
94+
```
95+
// php-docs-samples/testing folder
96+
$ cd ../../../testing
97+
98+
$ export GOOGLE_PROJECT_ID=<project id>
99+
$ export GOOGLE_PUBSUB_TOPIC=<topic name>
100+
$ export GOOGLE_PUBSUB_STORAGE_BUCKET=<bucket name>
101+
$ export GOOGLE_PUBSUB_SUBSCRIPTION=<subscription name>
102+
103+
// only set if your test requires the emulator
104+
$ export PUBSUB_EMULATOR_HOST=localhost:<emulator port>
105+
106+
// unset the PUBSUB emulator host variable if you want to run a test that doesn't require an emulator
107+
$ unset PUBSUB_EMULATOR
108+
```
109+
110+
### Running the tests
111+
Run your test(s) like so in the same terminal tab that you set your env variables in the previous step.
112+
113+
```
114+
// Run all tests in pubsubTest.php. --verbose tag is recommended to see any issues or stack trace
115+
$ php-docs-samples/testing/vendor/bin/phpunit ../pubsub/api/test/pubsubTest.php --verbose
116+
117+
// Run a single test in pubsubTest.php
118+
$ php-docs-samples/testing/vendor/bin/phpunit ../pubsub/api/test/pubsubTest.php --filter testSubscriptionPolicy --verbose
119+
```
120+
121+
## Fixing Styling Errors
122+
If you create a PR and the Lint / styles (pull_request) check fails, this is a quick fix.
123+
124+
```
125+
$ php-docs-samples/testing/vendor/bin/php-cs-fixer fix <path to your file>
126+
```
127+
67128
## Troubleshooting
68129

69130
If you get the following error, set the environment variable `GCLOUD_PROJECT` to your project ID:

0 commit comments

Comments
 (0)