Skip to content

Commit

Permalink
Provide stub files so that we can unit test without Drupal as a depen…
Browse files Browse the repository at this point in the history
…dency
  • Loading branch information
mglaman committed Jun 30, 2021
1 parent 2485cea commit b20ddd6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
"autoload": {
"psr-4": {
"DrupalRector\\": "src"
}
},
"classmap": [
"stubs"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
16 changes: 16 additions & 0 deletions stubs/Drupal/Tests/BrowserTestBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Drupal\Tests;

use PHPUnit\Framework\TestCase;

if (class_exists('Drupal\Tests\BrowserTestBase')) {
return;
}

abstract class BrowserTestBase extends TestCase
{

}
5 changes: 5 additions & 0 deletions stubs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Stub files

PHPStan allows you to define [stub files](https://phpstan.org/user-guide/stub-files).

These are used to provide information about missing classes – such as classes provided by Drupal – inside of our unit tests.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class UiHelperTraitDrupalPostFormRectorTest extends AbstractRectorTestCase {
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->markTestIncomplete(
'Fails since BrowserTestBase cannot be resolved, will work when drupal/core added as a dev dependency.'
);
$this->doTestFileInfo($fileInfo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
$services = $containerConfigurator->services();

$services->set(UiHelperTraitDrupalPostFormRector::class);

$parameters = $containerConfigurator->parameters();
$parameters->set('drupal_rector_notices_as_comments', true);
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class BrowserTestBaseGetMock extends BrowserTestBase {
public function simple_example() {
$edit = [];
$edit['action'] = 'action_goto_action';
$this->drupalGet('admin/config/system/actions');
// TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
// You must call `$this->drupalGet("admin/config/system/actions");" before submitForm
$this->submitForm($edit, 'Create');
$this->assertSession()->statusCodeEquals(200);
}
Expand Down

0 comments on commit b20ddd6

Please sign in to comment.