Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TECH-114: Add tests to the-build #217

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ jobs:
echo "phpstan for tasks"
vendor/bin/phpstan analyse src --level=2

# Run internal tests
- run:
name: Test custom phing commands
command: ./run-tests.sh

# Install a drupal test project.
- run:
name: Create artifacts directory
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
.idea
tests/*.txt
61 changes: 61 additions & 0 deletions .the-build/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# @file
# Default build configuration properties.
#
# This file may be customized for your project. The full set of default values can be
# found in the-build's repository.
# @see https://github.com/palantirnet/the-build/blob/release-2.0/defaults.yml

projectname: the-build-test

# These properties are used when building the settings.php and settings.yml for your
# Drupal site, and by some of the targets in the default build.xml file.
# @see .the-build/drupal/services.build.yml
# @see .the-build/drupal/settings.build.php
build:
host: acquia

drupal:
root: docroot

twig:
debug: true

sites:
default:
# REQUIRED: Name of the sites subdirectory where the `settings.php` file
# should live.
dir: default

# REQUIRED: Your site's URI; the default should be the URI of your local
# development environment.
uri: "localhost"

# OPTIONAL: Drupal hash salt defaults to "temporary".
hash_salt: "12345"

# OPTIONAL: The Drupal database name defaults to the site's "dir" value.
database:
database: "drupal"

# Multisites created by `phing drupal-add-multisite` will be automatically added here.
# @multisite_placeholder@

# Defaults for all sites; these can be overridden for individual sites.
_defaults:
database:
username: "test"
password: "test"
host: "localhost"

# Putting these flags in configuration allows you to vary the behat configuration per
# environment. Sometimes, there are tests that are appropriate to skip on CI. Compare
# these values to the defaults in build.circleci.yml.
behat:
args: "--suite=default --strict"

# To build an artifact from your code, add the URL to your artifact git repository.
# @see https://github.com/palantirnet/the-build/blob/release-2.0/defaults.yml
#
# artifact:
# git:
# remote:
97 changes: 97 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0"?>

<project name="the-build-tests" default="tests">
<!-- Default target: tests -->
<target name="tests" description="List available tests.">
<exec command="${phing.home}/bin/phing -q -f ${phing.file} -l" passthru="true"/>
</target>

<!-- Add property loading and targets from palantirnet/the-build. -->
<import file="targets/the-build.xml" />

<!-- Make these additional targets available by default. -->
<import file="targets/drupal.xml" />
<!-- Additional optional targets. -->
<import file="targets/artifact.xml" />
<import file="targets/acquia.xml" />
<import file="targets/styleguide.xml" />

<target name="run-tests" description="Runs all phing tests">
<!-- TODO: these should perhaps return true instead of print success.-->
<phingcall target="test-the-build" />
<phingcall target="test-set-site" />
</target>

<target name="test-the-build">
<loadfile property="result" file="tests/the-build.txt"/>
<property name="expected" value="Hello! I'm the-build." />
<if>
<!-- See https://www.phing.info/guide/chunkhtml/conditions.html -->
<contains string="${result}" substring="${expected}" />
<then>
<echo>the-build test passed</echo>
</then>
<else>
<echo>--Expected--</echo>
<echo>[${expected}]</echo>
<fail message="the-build test failed -- output below" />
</else>
</if>
</target>

<target name="test-set-site" depends="set-site">
<phingcall target="check-equals">
<property name="expected" value="../config/sites/default" />
<property name="actual" value="${drupal.site.config_sync_directory}" />
<property name="prop_name" value="drupal.site.config_sync_directory" />
</phingcall>
<phingcall target="check-equals">
<property name="expected" value="drupal" />
<property name="actual" value="${drupal.site.database.database}" />
<property name="prop_name" value="drupal.site.database.database" />
</phingcall>
<phingcall target="check-equals">
<property name="expected" value="sites/default/files" />
<property name="actual" value="${drupal.site.settings.file_public_path}" />
<property name="prop_name" value="drupal.site.settings.file_public_path" />
</phingcall>
<phingcall target="check-equals">
<property name="expected" value="../artifacts/private/default" />
<property name="actual" value="${drupal.site.settings.file_private_path}" />
<property name="prop_name" value="drupal.site.settings.file_private_path" />
</phingcall>
<phingcall target="check-equals">
<property name="expected" value="docroot/sites/default/settings.build.php" />
<property name="actual" value="${drupal.site.build.settings_dest}" />
<property name="prop_name" value="drupal.site.build.settings_dest" />
</phingcall>
<phingcall target="check-equals">
<property name="expected" value="docroot/sites/default/services.build.yml" />
<property name="actual" value="${drupal.site.build.services_dest}" />
<property name="prop_name" value="drupal.site.build.services_dest" />
</phingcall>
<phingcall target="check-equals">
<property name="expected" value="localhost" />
<property name="actual" value="${drush.uri}" />
<property name="prop_name" value="drush.uri" />
</phingcall>

<echo>set-site test passed</echo>
</target>

<target name="check-equals">
<echo>Checking ${prop_name}</echo>
<if>
<not><equals arg1="${expected}" arg2="${actual}" /></not>
<then>
<echo>${prop_name} test failed</echo>
<echo>--Expected--</echo>
<echo>${expected}</echo>
<echo>--Actual--</echo>
<echo>${actual}</echo>
<fail message="${prop_name} not set properly" />
</then>
</if>
</target>

</project>
6 changes: 6 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# Setup tests that read output before testing.
test='the-build'
vendor/bin/phing -logfile "tests/$test.txt" $test
vendor/bin/phing run-tests
Empty file added tests/.gitkeep
Empty file.