Skip to content

Commit f8f6d4c

Browse files
authored
Add new env vars to ease Docker usage and debug (#52)
* Add new env vars to ease Docker usage and debug * AppVeyor
1 parent 8cb8d88 commit f8f6d4c

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,28 @@ Since Panthère implements the API of popular, it already has an extensive docum
138138
* For the `Crawler` class, read [the DomCrawler's documentation](https://symfony.com/doc/current/components/dom_crawler.html)
139139
* For Webdriver, read [the Facebook's PHP WebDriver documentation](https://github.com/facebook/php-webdriver)
140140

141+
## Environment Variables
142+
143+
The following environment variables can be set to change some Panthère behaviors:
144+
145+
* `PANTHERE_NO_HEADLESS`: to disable browsers's headless mode (will display the testing window, useful to debug)
146+
* `PANTHERE_NO_SANDBOX`: to disable [Chrome's sandboxing](https://chromium.googlesource.com/chromium/src/+/b4730a0c2773d8f6728946013eb812c6d3975bec/docs/design/sandbox.md) (unsafe, but allows to use Panthère in containers)
147+
* `PANTHERE_WEB_SERVER_DIR`: to change the project's document root (default to `public/`)
148+
149+
## Docker Integration
150+
151+
Here is a minimal Docker image that can run Panthère:
152+
153+
```
154+
FROM php:latest
155+
156+
RUN apt-get update && apt-get install -y zlib1g-dev chromium && docker-php-ext-install zip
157+
ENV PANTHERE_NO_SANDBOX 1
158+
```
159+
160+
Build it with `docker build . -t myproject`
161+
Run it with `docker run -it -v "$PWD":/srv/myproject -w /srv/myproject myproject bin/phpunit`
162+
141163
## Travis CI Integration
142164

143165
Panthère will work out of the box with Travis if you add the Chrome addon. Here is a minimal `.travis.yml` file to run
@@ -154,6 +176,38 @@ php:
154176
script:
155177
- phpunit
156178
```
179+
## AppVeyor Integration
180+
181+
Panthère will work out of the box with AppVeyor as long as Google Chrome is installed. Here is a minimal `appveyor.yml`
182+
file to run Panthère tests:
183+
184+
```yaml
185+
build: false
186+
platform: x86
187+
clone_folder: c:\projects\myproject
188+
189+
cache:
190+
- '%LOCALAPPDATA%\Composer\files'
191+
192+
install:
193+
- ps: Set-Service wuauserv -StartupType Manual
194+
- cinst -y php composer googlechrome
195+
- refreshenv
196+
- cd c:\tools\php72
197+
- copy php.ini-production php.ini /Y
198+
- echo date.timezone="UTC" >> php.ini
199+
- echo extension_dir=ext >> php.ini
200+
- echo extension=php_openssl.dll >> php.ini
201+
- echo extension=php_mbstring.dll >> php.ini
202+
- echo extension=php_curl.dll >> php.ini
203+
- echo memory_limit=3G >> php.ini
204+
- cd %APPVEYOR_BUILD_FOLDER%
205+
- composer install --no-interaction --no-progress
206+
207+
test_script:
208+
- cd %APPVEYOR_BUILD_FOLDER%
209+
- php vendor\phpunit\phpunit\phpunit
210+
```
157211

158212
## Limitations
159213

src/PanthereTestCaseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected static function startWebServer(?string $webServerDir = null, string $h
7979

8080
if (null === $webServerDir) {
8181
// Try the local $webServerDir property, or the PANTHERE_WEB_SERVER_DIR env var or default to the Flex directory structure
82-
$webServerDir = static::$webServerDir ?? $_ENV['PANTHERE_WEB_SERVER_DIR'] ?? __DIR__.'/../../../../public';
82+
$webServerDir = static::$webServerDir ?? $_SERVER['PANTHERE_WEB_SERVER_DIR'] ?? __DIR__.'/../../../../public';
8383
}
8484

8585
self::$webServerManager = new WebServerManager($webServerDir, $hostname, $port);

src/ProcessManager/ChromeManager.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ private function findChromeDriverBinary(): string
8080

8181
private function getDefaultArguments(): array
8282
{
83-
// Enable the headless mode
84-
$args = ['--headless', 'window-size=1200,1100', '--disable-gpu'];
83+
// Enable the headless mode unless PANTHERE_NO_HEADLESS is defined
84+
$args = ($_SERVER['PANTHERE_NO_HEADLESS'] ?? false) ? [] : ['--headless', 'window-size=1200,1100', '--disable-gpu'];
8585

86-
if ($_SERVER['HAS_JOSH_K_SEAL_OF_APPROVAL'] ?? false) {
86+
// Disable Chrome's sandbox if PANTHERE_NO_SANDBOX is defined or if running in Travis
87+
if ($_SERVER['PANTHERE_NO_SANDBOX'] ?? $_SERVER['HAS_JOSH_K_SEAL_OF_APPROVAL'] ?? false) {
8788
// Running in Travis, disabling the sandbox mode
8889
$args[] = '--no-sandbox';
8990
}

0 commit comments

Comments
 (0)