Skip to content

Commit 74be735

Browse files
authored
Merge branch '1.x' into feature/add-bats-test-ahoy-operation
2 parents 73d4a7e + 10493ea commit 74be735

31 files changed

+607
-165
lines changed

.ahoy.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,41 @@ commands:
4545
4646
test:
4747
usage: Run all tests.
48-
cmd: ./.devtools/test.sh
48+
cmd: |
49+
pushd "build" >/dev/null || exit 1
50+
vendor/bin/phpunit
51+
popd >/dev/null || exit 1
52+
53+
test-unit:
54+
usage: Run unit tests.
55+
cmd: |
56+
pushd "build" >/dev/null || exit 1
57+
vendor/bin/phpunit --testsuite unit
58+
popd >/dev/null || exit 1
59+
60+
test-kernel:
61+
usage: Run kernel tests.
62+
cmd: |
63+
pushd "build" >/dev/null || exit 1
64+
vendor/bin/phpunit --testsuite kernel
65+
popd >/dev/null || exit 1
66+
67+
test-functional:
68+
usage: Run functional tests.
69+
cmd: |
70+
pushd "build" >/dev/null || exit 1
71+
vendor/bin/phpunit --testsuite functional
72+
popd >/dev/null || exit 1
4973
5074
# Override entrypoint to alter default behaviour of Ahoy.
5175
entrypoint:
5276
- bash
5377
- -c
5478
- -e
79+
- |
80+
extension="$(basename -s .info.yml -- ./*.info.yml)"
81+
export SIMPLETEST_BASE_URL=http://${WEBSERVER_HOST:-localhost}:${WEBSERVER_PORT:-8000}
82+
export SIMPLETEST_DB=sqlite://localhost/drupal_test_${extension}.sqlite
83+
bash -e -c "$0" "$@"
5584
- '{{cmd}}'
5685
- '{{name}}'

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ job-test: &job-test
5858

5959
- run:
6060
name: Run tests
61-
command: .devtools/test.sh || [ "${CI_TEST_IGNORE_FAILURE:-0}" -eq 1 ]
61+
command: vendor/bin/phpunit || [ "${CI_TEST_IGNORE_FAILURE:-0}" -eq 1 ]
62+
working_directory: build
6263

6364
- run:
6465
name: Process artifacts

.devtools/build-codebase.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ for composer_suggest in $composer_suggests; do
107107
done
108108

109109
echo "> Copy tools configuration files."
110-
cp phpcs.xml phpstan.neon phpmd.xml rector.php .twig_cs.php "build/"
110+
cp phpcs.xml phpstan.neon phpmd.xml rector.php .twig_cs.php phpunit.xml "build/"
111111

112112
echo "> Symlink extension's code."
113113
rm -rf "build/web/${type}/custom" >/dev/null && mkdir -p "build/web/${type}/custom/${extension}"

.devtools/test.sh

Lines changed: 0 additions & 53 deletions
This file was deleted.

.github/workflows/scaffold-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
working-directory: .scaffold/tests
4040

4141
- name: Run tests
42-
run: kcov --include-pattern=.sh,.bash --bash-parse-files-in-dir=. --exclude-pattern=vendor,node_modules,.scaffold-coverage-html "$(pwd)"/.scaffold-coverage-html .scaffold/tests/node_modules/.bin/bats .scaffold/tests/bats
42+
run: kcov --include-pattern=.sh,.bash --bash-parse-files-in-dir=. --exclude-pattern=vendor,node_modules,.scaffold-coverage-html,.scaffold "$(pwd)"/.scaffold-coverage-html .scaffold/tests/node_modules/.bin/bats .scaffold/tests/bats
4343

4444
- name: Upload coverage report as an artifact
4545
uses: actions/upload-artifact@v4

.github/workflows/test.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,28 @@ jobs:
9494
run: vendor/bin/twigcs || [ "${CI_TWIGCS_IGNORE_FAILURE:-0}" -eq 1 ]
9595

9696
- name: Run tests
97-
run: .devtools/test.sh || [ "${CI_TEST_IGNORE_FAILURE:-0}" -eq 1 ]
97+
working-directory: build
98+
run: vendor/bin/phpunit || [ "${CI_TEST_IGNORE_FAILURE:-0}" -eq 1 ]
9899

99100
- name: Process artifacts
100101
uses: actions/upload-artifact@v4
101102
with:
102103
name: Artifacts (${{ matrix.name }})
103104
path: build/web/sites/simpletest/browser_output
105+
106+
- name: Upload coverage report as an artifact
107+
uses: actions/upload-artifact@v4
108+
with:
109+
name: ${{github.job}}-code-coverage-report-${{ matrix.name }}
110+
path: ./.logs/coverage/phpunit/.coverage-html
111+
if-no-files-found: error
112+
113+
- name: Upload coverage report to Codecov
114+
uses: codecov/codecov-action@v4
115+
if: ${{ env.CODECOV_TOKEN != '' }}
116+
with:
117+
files: ./.logs/coverage/phpunit/cobertura.xml
118+
fail_ci_if_error: true
119+
token: ${{ secrets.CODECOV_TOKEN }}
120+
env:
121+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.logs
12
composer.lock
23
build

.scaffold/tests/bats/_assert_init.bash

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ assert_files_present_common() {
7171

7272
# Assert other things.
7373
assert_dir_not_contains_string "${dir}" "your_extension"
74-
assert_dir_contains_string "${dir}" "YodasHut"
7574

7675
popd >/dev/null || exit 1
7776
}

.scaffold/tests/bats/functional.init.bats

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export SCRIPT_FILE="init.sh"
1616
# bats test_tags=smoke
1717
@test "Init, defaults - extension module, workflow" {
1818
answers=(
19-
"YodasHut" # namespace
2019
"Force Crystal" # name
2120
"force_crystal" # machine_name
2221
"module" # type
@@ -38,7 +37,6 @@ export SCRIPT_FILE="init.sh"
3837
# bats test_tags=smoke
3938
@test "Init, extension theme, workflow" {
4039
answers=(
41-
"YodasHut" # namespace
4240
"Force Crystal" # name
4341
"force_crystal" # machine_name
4442
"theme" # type
@@ -60,7 +58,6 @@ export SCRIPT_FILE="init.sh"
6058
# bats test_tags=smoke
6159
@test "Init, CircleCI" {
6260
answers=(
63-
"YodasHut" # namespace
6461
"Force Crystal" # name
6562
"force_crystal" # machine_name
6663
"module" # type
@@ -80,7 +77,6 @@ export SCRIPT_FILE="init.sh"
8077

8178
@test "Init, do not remove script" {
8279
answers=(
83-
"YodasHut" # namespace
8480
"Force Crystal" # name
8581
"force_crystal" # machine_name
8682
"module" # type
@@ -99,7 +95,6 @@ export SCRIPT_FILE="init.sh"
9995

10096
@test "Init, remove script" {
10197
answers=(
102-
"YodasHut" # namespace
10398
"Force Crystal" # name
10499
"force_crystal" # machine_name
105100
"module" # type

.scaffold/tests/bats/unit.init.bats

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ load "../../../init.sh"
1111
input="I am a_string-With spaces 13"
1212

1313
TEST_CASES=(
14-
"$input" "file_name" "i_am_a_string-with_spaces_13"
15-
"$input" "route_path" "i_am_a_string-with_spaces_13"
14+
"I am a_string-With spaces 13" "file_name" "i_am_a_string-with_spaces_13"
15+
"I am a_string-With spaces 13" "route_path" "i_am_a_string-with_spaces_13"
16+
"I am a_string-With spaces 13" "deployment_id" "i_am_a_string-with_spaces_13"
17+
"I am a_string-With spaces 13" "domain_name" "i_am_a_stringwith_spaces_13"
18+
"I am a_string-With spaces 13" "namespace" "IAmAStringWithSpaces13"
19+
"I am a_string-With spaces 13" "package_name" "i-am-a_string-with-spaces-13"
20+
"I am a_string-With spaces 13" "function_name" "i_am_a_string-with_spaces_13"
21+
"I am a_string-With spaces 13" "ui_id" "i_am_a_string-with_spaces_13"
22+
"I am a_string-With spaces 13" "cli_command" "i_am_a_string-with_spaces_13"
23+
"I am a_string-With spaces 13" "log_entry" "I am a_string-With spaces 13"
24+
"I am a_string-With spaces 13" "code_comment_title" "I am a_string-With spaces 13"
25+
"I am a_string-With spaces 13" "dummy_type" "Invalid conversion type"
1626
)
1727

1828
dataprovider_run "convert_string" 3

README.dist.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<img width=200px height=200px src="https://placehold.jp/000000/ffffff/200x200.png?text=Your+Extension&css=%7B%22border-radius%22%3A%22%20100px%22%7D" alt="Yourproject logo"></a>
44
</p>
55

6-
<h1 align="center">Your extension</h1>
6+
<h1 align="center">Your Extension</h1>
77

88
<div align="center">
99

composer.dev.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"require-dev": {
33
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
44
"friendsoftwig/twigcs": "^6.2",
5+
"jangregor/phpstan-prophecy": "^1.0",
56
"mglaman/phpstan-drupal": "^1.2",
67
"palantirnet/drupal-rector": "^0.18",
78
"phpcompatibility/php-compatibility": "^9.3",

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"authors": [
77
{
88
"name": "Your Name",
9-
"email": "yourproject@yournamespace.com",
9+
"email": "yourproject@yourusername.com",
1010
"homepage": "https://www.drupal.org/u/yourusername",
1111
"role": "Maintainer"
1212
}

config/install/user.role.demorole.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
your_extension.settings:
2+
type: config_object
3+
label: 'Your Extension settings'
4+
mapping:
5+
text:
6+
type: string
7+
label: 'Text for <noscript> Tag'

init.sh

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77
# ./init.sh
88
#
99
# Silent:
10-
# ./init.sh yournamespace "Extension Name" extension_machine_name extension_type "CI Provider"
10+
# ./init.sh "Extension Name" extension_machine_name extension_type "CI Provider"
1111
#
1212
# shellcheck disable=SC2162,SC2015
1313

1414
set -euo pipefail
1515
[ "${SCRIPT_DEBUG-}" = "1" ] && set -x
1616

17-
namespace=${1-}
18-
extension_name=${2-}
19-
extension_machine_name=${3-}
20-
extension_type=${4-}
21-
ci_provider=${5-}
17+
extension_name=${1-}
18+
extension_machine_name=${2-}
19+
extension_type=${3-}
20+
ci_provider=${4-}
2221

2322
#-------------------------------------------------------------------------------
2423

@@ -34,7 +33,7 @@ convert_string() {
3433
echo "${input_string}" | tr ' ' '_' | tr '[:upper:]' '[:lower:]' | tr -d '-'
3534
;;
3635
"namespace" | "class_name")
37-
echo "${input_string}" | awk -F" " '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2));} 1' | tr -d ' -'
36+
echo "${input_string}" | tr '-' ' ' | tr '_' ' ' | awk -F" " '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2));} 1' | tr -d ' -'
3837
;;
3938
"package_name")
4039
echo "${input_string}" | tr ' ' '-' | tr '[:upper:]' '[:lower:]'
@@ -154,30 +153,29 @@ process_readme() {
154153
}
155154

156155
process_internal() {
157-
local namespace="${1}"
158-
local extension_name="${2}"
159-
local extension_machine_name="${3}"
160-
local extension_type="${4}"
161-
local ci_provider="${5}"
162-
local namespace_lowercase
163-
164-
namespace_lowercase="$(to_lowercase "${namespace}")"
165-
166-
replace_string_content "YourNamespace" "${namespace}"
167-
replace_string_content "yournamespace" "${namespace_lowercase}"
168-
replace_string_content "AlexSkrypnyk" "${namespace}"
169-
replace_string_content "alexskrypnyk" "${namespace_lowercase}"
156+
local extension_name="${1}"
157+
local extension_machine_name="${2}"
158+
local extension_type="${3}"
159+
local ci_provider="${4}"
160+
161+
extension_machine_name_class="$(convert_string "${extension_machine_name}" "class_name")"
162+
163+
replace_string_content "YourNamespace" "${extension_machine_name}"
164+
replace_string_content "yournamespace" "${extension_machine_name}"
165+
replace_string_content "AlexSkrypnyk" "${extension_machine_name}"
166+
replace_string_content "alexskrypnyk" "${extension_machine_name}"
170167
replace_string_content "yourproject" "${extension_machine_name}"
171168
replace_string_content "Yourproject logo" "${extension_name} logo"
172-
replace_string_content "Your extension" "${extension_name}"
169+
replace_string_content "Your Extension" "${extension_name}"
173170
replace_string_content "your extension" "${extension_name}"
174171
replace_string_content "Your+Extension" "${extension_machine_name}"
175172
replace_string_content "your_extension" "${extension_machine_name}"
173+
replace_string_content "YourExtension" "${extension_machine_name_class}"
176174
replace_string_content "Provides your_extension functionality." "Provides ${extension_machine_name} functionality."
177175
replace_string_content "drupal-module" "drupal-${extension_type}"
178176
replace_string_content "Drupal module scaffold FE example used for template testing" "Provides ${extension_machine_name} functionality."
179-
replace_string_content "drupal_extension_scaffold" "${extension_machine_name}"
180177
replace_string_content "Drupal extension scaffold" "${extension_name}"
178+
replace_string_content "drupal_extension_scaffold" "${extension_machine_name}"
181179
replace_string_content "type: module" "type: ${extension_type}"
182180
replace_string_content "\[EXTENSION_NAME\]" "${extension_machine_name}"
183181

@@ -202,6 +200,17 @@ process_internal() {
202200
remove_string_content "LICENSE export-ignore"
203201

204202
mv "your_extension.info.yml" "${extension_machine_name}.info.yml"
203+
mv "your_extension.install" "${extension_machine_name}.install"
204+
mv "your_extension.links.menu.yml" "${extension_machine_name}.links.menu.yml"
205+
mv "your_extension.module" "${extension_machine_name}.module"
206+
mv "your_extension.routing.yml" "${extension_machine_name}.routing.yml"
207+
mv "your_extension.services.yml" "${extension_machine_name}.services.yml"
208+
mv "config/schema/your_extension.schema.yml" "config/schema/${extension_machine_name}.schema.yml"
209+
mv "src/Form/YourExtensionForm.php" "src/Form/${extension_machine_name_class}Form.php"
210+
mv "src/YourExtensionService.php" "src/${extension_machine_name_class}Service.php"
211+
mv "tests/src/Unit/YourExtensionServiceUnitTest.php" "tests/src/Unit/${extension_machine_name_class}ServiceUnitTest.php"
212+
mv "tests/src/Kernel/YourExtensionServiceKernelTest.php" "tests/src/Kernel/${extension_machine_name_class}ServiceKernelTest.php"
213+
mv "tests/src/Functional/YourExtensionFunctionalTest.php" "tests/src/Functional/${extension_machine_name_class}FunctionalTest.php"
205214

206215
rm -f LICENSE >/dev/null || true
207216
rm -Rf "tests/scaffold" >/dev/null || true
@@ -229,7 +238,6 @@ main() {
229238
echo "Please follow the prompts to adjust your extension configuration"
230239
echo
231240

232-
[ -z "${namespace}" ] && namespace="$(ask "Namespace")"
233241
[ -z "${extension_name}" ] && extension_name="$(ask "Name")"
234242
[ -z "${extension_machine_name}" ] && extension_machine_name="$(ask "Machine name")"
235243
[ -z "${extension_type}" ] && extension_type="$(ask "Type: module or theme")"
@@ -240,7 +248,6 @@ main() {
240248
echo
241249
echo " Summary"
242250
echo "---------------------------------"
243-
echo "Namespace : ${namespace}"
244251
echo "Name : ${extension_name}"
245252
echo "Machine name : ${extension_machine_name}"
246253
echo "Type : ${extension_type}"
@@ -261,15 +268,14 @@ main() {
261268
# Processing.
262269
#
263270

264-
: "${namespace:?namespace is required}"
265271
: "${extension_name:?name is required}"
266272
: "${extension_machine_name:?machine_name is required}"
267273
: "${extension_type:?type is required}"
268274
: "${ci_provider:?ci_provider is required}"
269275

270276
process_readme "${extension_name}"
271277

272-
process_internal "${namespace}" "${extension_name}" "${extension_machine_name}" "${extension_type}" "${ci_provider}"
278+
process_internal "${extension_name}" "${extension_machine_name}" "${extension_type}" "${ci_provider}"
273279

274280
[ "${remove_self}" != "n" ] && rm -- "$0" || true
275281

0 commit comments

Comments
 (0)