How to perform unittests in docker development environment

Hello,

I need help setting up the phpunit in my docker:

Making first steps in app development with the contacts app. For the development I use a simple docker:

docker-compose.yml

version: '2'

volumes:
 nextcloud:

services:
  app:
    image: nextcloud
    ports:
      - 8099:80
    volumes:
      - nextcloud:/var/www/html
      - ./contacts:/var/www/html/custom_apps/contacts
    restart: unless-stopped

The contacts directory is cloned from https://github.com/call-me-matt/contacts

Now that I would like to add unit tests for a new controller, I realize that phpunit doesn’t run. Here is where I am stuck:

docker exec -it nextcloud_app_1 bash

root@446e4b1fa66b:/var/www/html# cd custom_apps/contacts

root@446e4b1fa66b:/var/www/html/custom_apps/contacts# make test-php
php composer.phar run test:unit
Could not open input file: composer.phar
make: *** [Makefile:55: test-php] Error 1

root@446e4b1fa66b:/var/www/html/custom_apps/contacts# composer run test:unit
Do not run Composer as root/super user! See https://getcomposer.org/root for details
> phpunit -c phpunit.xml --fail-on-warning
PHP Fatal error:  require_once(): Failed opening required '/var/www/html/custom_apps/contacts/tests/../vendor/autoload.php' (include_path='/var/www/html/3rdparty/pear/archive_tar:/var/www/html/3rdparty/pear/console_getopt:/var/www/html/3rdparty/pear/pear-core-minimal/src:/var/www/html/3rdparty/pear/pear_exception:/var/www/html/apps:/var/www/html/custom_apps') in /var/www/html/custom_apps/contacts/tests/bootstrap.php on line 13
Script phpunit -c phpunit.xml --fail-on-warning handling the test:unit event returned with error code 255

root@446e4b1fa66b:/var/www/html/custom_apps/contacts# phpunit
PHP Fatal error:  require_once(): Failed opening required '/var/www/html/custom_apps/contacts/tests/../vendor/autoload.php' (include_path='/var/www/html/3rdparty/pear/archive_tar:/var/www/html/3rdparty/pear/console_getopt:/var/www/html/3rdparty/pear/pear-core-minimal/src:/var/www/html/3rdparty/pear/pear_exception:/var/www/html/apps:/var/www/html/custom_apps') in /var/www/html/custom_apps/contacts/tests/bootstrap.php on line 13

(there is no vendor/autoload.php)

root@446e4b1fa66b:/var/www/html# find -iname autoload.php
./3rdparty/autoload.php
./apps/dav/composer/autoload.php
./apps/sharebymail/composer/autoload.php
./apps/files_sharing/composer/autoload.php
./apps/provisioning_api/composer/autoload.php
./apps/federation/composer/autoload.php
./apps/workflowengine/composer/autoload.php
./apps/systemtags/composer/autoload.php
./apps/settings/composer/autoload.php
./apps/comments/composer/autoload.php
./apps/lookup_server_connector/composer/autoload.php
./apps/files_versions/composer/autoload.php
./apps/accessibility/composer/autoload.php
./apps/federatedfilesharing/composer/autoload.php
./apps/updatenotification/composer/autoload.php
./apps/twofactor_backupcodes/composer/autoload.php
./apps/files/composer/autoload.php
./apps/files_trashbin/composer/autoload.php
./apps/cloud_federation_api/composer/autoload.php
./apps/files_external/3rdparty/autoload.php
./apps/user_ldap/composer/autoload.php
./apps/oauth2/composer/autoload.php
./apps/encryption/composer/autoload.php
./apps/admin_audit/composer/autoload.php
./lib/composer/autoload.php

Thank you for your help!

Made it work as follows, but not sure if that’s the best way to do:

  1. build the dev-setup!
make dev-setup
  1. install manually dependencies listed in Makefile:
curl -sS https://getcomposer.org/installer | php 
php composer.phar install --no-dev -o
php composer.phar install -o
  1. run tests:
    make test-php