Skip to content

Commit a3f7d6d

Browse files
authored
Merge pull request #7 from coldfrontlabs/codeception4
Add support for codeception 4 + DrupalFinder
2 parents c7396f7 + ff6717e commit a3f7d6d

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ If codeception was not previously set up:
2424
Provides full bootstrapping in to Drupal before test. Allows using drupal API in test cases.
2525

2626
### Configuration
27-
- root: Drupal root. Defaults to codeception root + `/web`.
2827
- server: Server and execution environment information.
28+
- root: Drupal root. Uses DrupalFinder to detect the Drupal root. Falls back to codeception root + `/web`. (optional)
2929

3030
```
3131
modules:
3232
- DrupalBootstrap:
33-
root: './web'
3433
server:
3534
SERVER_PORT: null
3635
REQUEST_URI: '/'
@@ -229,7 +228,7 @@ Includes:
229228
- FormField: Fields that can be set to cardinality unlimited
230229
- MTOFormField: Single value fields.
231230
- ParagraphFormField: Paragraph form fields.
232-
231+
233232
### Usage
234233

235234
Create paragraph field with machine name field_page_elements.

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
}
1010
],
1111
"require": {
12-
"codeception/codeception": "^2.3 || ^3.0",
13-
"fzaninotto/faker": "^1.8"
12+
"codeception/codeception": "^4.0",
13+
"fzaninotto/faker": "^1.8",
14+
"codeception/module-webdriver": "^1.1",
15+
"webflo/drupal-finder": "^1.2"
1416
},
1517
"require-dev": {
1618
"composer/installers": "^1",

src/Codeception/Module/DrupalBootstrap.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Codeception\TestDrupalKernel;
99
use Symfony\Component\HttpFoundation\Request;
1010
use Drupal\Core\DrupalKernel;
11+
use DrupalFinder\DrupalFinder;
12+
1113

1214
/**
1315
* Class DrupalBootstrap.
@@ -46,7 +48,19 @@ class DrupalBootstrap extends Module {
4648
public function __construct(ModuleContainer $container, $config = NULL) {
4749
parent::__construct($container, $config);
4850
if (!isset($this->config['root'])) {
49-
$this->_setConfig(['root' => Configuration::projectDir() . 'web']);
51+
52+
$drupalFinder = new DrupalFinder();
53+
54+
$drupalFinder->locateRoot(getcwd());
55+
$drupalRoot = $drupalFinder->getDrupalRoot();
56+
57+
// Autodetect Drupal root.
58+
if ($drupalRoot) {
59+
$this->_setConfig(['root' => $drupalRoot]);
60+
}
61+
else {
62+
$this->_setConfig(['root' => Configuration::projectDir() . 'web']);
63+
}
5064
}
5165
chdir($this->_getConfig('root'));
5266
$request = Request::createFromGlobals();

0 commit comments

Comments
 (0)