Skip to content

Commit 2a24716

Browse files
authored
Merge pull request #359 from kabalin/MDL-83424
Support new directory structure
2 parents d5e4885 + 1665095 commit 2a24716

File tree

8 files changed

+197
-140
lines changed

8 files changed

+197
-140
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
],
5656
"require": {
5757
"php": ">=7.4",
58-
"moodlehq/moodle-cs": "^3.4.10",
59-
"moodlehq/moodle-local_ci": "^1.0.31",
58+
"moodlehq/moodle-cs": "^3.4.11",
59+
"moodlehq/moodle-local_ci": "^1.0.32",
6060
"moodlehq/moodle-local_moodlecheck": "^1.3.2",
6161
"sebastian/phpcpd": "^6.0.3",
6262
"sebastian/version": "^3.0.2",

composer.lock

Lines changed: 169 additions & 129 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ The format of this change log follows the advice given at [Keep a CHANGELOG](htt
1212
### Changed
1313
- Bump default Selenium version to 4.
1414

15+
### Fixed
16+
- Add support for public directory structure in 5.1 (MDL-83424).
17+
1518
## [4.5.7] - 2025-03-26
1619
### Changed
1720
- Allow to run with PHP 8.4 (supported in Moodle 5.0)

src/Bridge/Moodle.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ public function __construct(string $directory)
3939
$this->directory = $directory;
4040
}
4141

42+
/**
43+
* Get the absolute path to the public directory.
44+
*
45+
* @return string
46+
*/
47+
public function getPublicDirectory(): string
48+
{
49+
// Moodle 5.1+ is using 'public' directory structure.
50+
return file_exists($this->directory . '/public/version.php') ? $this->directory . '/public' : $this->directory;
51+
}
52+
4253
/**
4354
* Load Moodle config so we can use Moodle APIs.
4455
*/
@@ -125,7 +136,7 @@ public function getBranch(): int
125136
$filter = new StatementFilter();
126137
$parser = new CodeParser();
127138

128-
$statements = $parser->parseFile($this->directory . '/version.php');
139+
$statements = $parser->parseFile($this->getPublicDirectory() . '/version.php');
129140
$assign = $filter->findFirstVariableAssignment($statements, 'branch', 'Failed to find $branch in Moodle version.php');
130141

131142
if ($assign->expr instanceof String_) {

src/Command/BehatCommand.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7979
'--enable',
8080
'--add-core-features-to-theme',
8181
'--scss-deprecations',
82-
], $this->moodle->directory, null, null, null);
82+
], $this->moodle->getPublicDirectory(), null, null, null);
8383
$this->execute->passThroughProcess($enableprocess);
8484
}
8585

@@ -102,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
102102
$cmd[] = '--colors';
103103
}
104104

105-
$process = $this->execute->passThroughProcess(new Process($cmd, $this->moodle->directory, null, null, null));
105+
$process = $this->execute->passThroughProcess(new Process($cmd, $this->moodle->getPublicDirectory(), null, null, null));
106106

107107
$servers && $this->stopServerProcesses();
108108

@@ -167,7 +167,10 @@ private function startServerProcesses(InputInterface $input): void
167167
'php',
168168
'-S',
169169
$phpWebserverHost,
170+
'-t',
171+
$this->moodle->getPublicDirectory(),
170172
];
173+
171174
$web = new Process($cmd, $this->moodle->directory);
172175
$web->setTimeout(0);
173176
$web->disableOutput();

src/Command/MustacheCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7373
$wrapper,
7474
'--filename=' . $file,
7575
'--validator=' . $jarTmpFile,
76-
'--basename=' . $this->moodle->directory,
76+
'--basename=' . $this->moodle->getPublicDirectory(),
7777
];
7878
// _JAVA_OPTIONS is something Travis CI started to set in Trusty. This breaks Mustache because
7979
// the output from vnu.jar needs to be captured and JSON decoded. When _JAVA_OPTIONS is present,

src/Command/PHPDocCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6969
'-f=text',
7070
];
7171

72-
$process = $this->execute->passThroughProcess(new Process($cmd, $this->moodle->directory, null, null, null));
72+
$process = $this->execute->passThroughProcess(new Process($cmd, $this->moodle->getPublicDirectory(), null, null, null));
7373

7474
if (isset($filesystem)) {
7575
// Remove plugin if we added it, so we leave things clean.

src/Installer/TestSuiteInstaller.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(Moodle $moodle, MoodlePlugin $plugin, Execute $execu
4343
*/
4444
private function getBehatUtility(): string
4545
{
46-
return $this->moodle->directory . '/admin/tool/behat/cli/util_single_run.php';
46+
return $this->moodle->getPublicDirectory() . '/admin/tool/behat/cli/util_single_run.php';
4747
}
4848

4949
public function install(): void
@@ -104,7 +104,7 @@ public function getUnitTestInstallProcesses(): array
104104

105105
return [
106106
new MoodleProcess([
107-
$this->moodle->directory . '/admin/tool/phpunit/cli/util.php',
107+
$this->moodle->getPublicDirectory() . '/admin/tool/phpunit/cli/util.php',
108108
'--install',
109109
]),
110110
];
@@ -130,15 +130,15 @@ public function getPostInstallProcesses(): array
130130
if ($this->plugin->hasUnitTests()) {
131131
$this->getOutput()->debug('Build PHPUnit config');
132132
$processes[] = new MoodleProcess([
133-
$this->moodle->directory . '/admin/tool/phpunit/cli/util.php',
133+
$this->moodle->getPublicDirectory() . '/admin/tool/phpunit/cli/util.php',
134134
'--buildconfig',
135135
]);
136136
// Only create the PHPUnit config file (phpunit.xml) if it does not exist.
137137
// This is to avoid overwriting the file if it has been customized by the developer.
138138
if (!$this->plugin->hasPHPUnitConfig()) {
139139
$this->getOutput()->debug('Build PHPUnit component config');
140140
$processes[] = new MoodleProcess([
141-
$this->moodle->directory . '/admin/tool/phpunit/cli/util.php',
141+
$this->moodle->getPublicDirectory() . '/admin/tool/phpunit/cli/util.php',
142142
'--buildcomponentconfigs',
143143
]);
144144
}

0 commit comments

Comments
 (0)