Azure Pipeline + Laravel + MySQL + PHPUnit + Laravel Dusk
# PHP
# Test and package your PHP project.
# Add steps that run tests, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/php
pool:
vmImage: 'Ubuntu 16.04'
variables:
phpVersion: 7.2
steps:
- script: |
sudo update-alternatives --set php /usr/bin/php$(phpVersion)
sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)
sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)
sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)
sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)
php -version
displayName: 'Use PHP version $(phpVersion)'
- script: |
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt-get install -y build-essential debconf-utils screen nodejs mysql-server google-chrome-stable
sudo apt-get install -y unzip xvfb autogen autoconf libtool pkg-config nasm
sudo mysql -uroot -proot -e "use mysql; update user set authentication_string=PASSWORD('poowf') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;"
sudo mysql -u root -ppoowf -e 'create database invoiceneko_test;'
displayName: 'Installing System Dependencies'
- script: |
mysql --version
displayName: 'MySQL Version'
- script: |
cp .env.travis .env
displayName: 'Environment Setup'
- script: |
sudo composer self-update
composer install --no-interaction --prefer-dist --no-suggest
composer --version
displayName: 'Installing Package Dependencies'
- script: |
php artisan key:generate
php artisan migrate
displayName: 'Running Migrations'
- script: |
sudo npm i -g npm
sudo chown -R vsts:vsts ~/.npm
sudo chown -R vsts:vsts ~/.config
npm install
npm run prod
node -v
displayName: 'Generating build assets'
- script: |
screen -d -m google-chrome-stable --headless --disable-gpu --disable-dev-shm-usage --disable-software-rasterizer --remote-debugging-port=9222 http://localhost &
screen -d -m php artisan serve &
displayName: 'Starting Chrome and the Web Server'
- script: |
vendor/bin/phpunit --log-junit tests/Results/TEST-phpunit-junit.xml
displayName: 'Running Unit Tests'
- script: |
php artisan dusk --log-junit tests/Results/TEST-dusk-junit.xml
displayName: 'Running Browser Tests'
# Publish Test Results to Azure Pipelines/TFS
- task: PublishTestResults@2
inputs:
testRunner: 'JUnit' # Options: JUnit, NUnit, VSTest, xUnit
testResultsFiles: '**/TEST-*.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/tests/Results' # Optional
mergeTestResults: false # Optional
#testRunTitle: # Optional
#buildPlatform: # Optional
#buildConfiguration: # Optional
#publishRunAttachments: true # Optional
condition: always()Install NodeJS v11.x
Install necessary packages, screen; nodejs; mysql-server; google-chrome-stable
Updates the MySQL password to poowf
Creates the MySQL Database
Copy the travis environment file(You can make one for azure)
Removes installed composer version(It's composer v1.0 built in 2016) (They fixed it)
Export the path for composer
Download new composer snapshot and update to stable
Install Composer dependencies
Run Migrations
Generate Key
Update NPM
Install NPM packages
Build package assets
Run google-chrome in a screen and detach
Run the web server in a screen and detach
Run Unit Tests
Run Browser Tests
Publish Test Results for both Unit and Browser Tests to Pipelines