Skip to content

Commit

Permalink
Merge pull request #151 from Chi-teck/fix-test
Browse files Browse the repository at this point in the history
Update tests
  • Loading branch information
Chi-teck authored May 20, 2024
2 parents 54435aa + 1f016bf commit 504d605
Show file tree
Hide file tree
Showing 109 changed files with 300 additions and 309 deletions.
16 changes: 9 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"ext-json": "*",
"psr/event-dispatcher": "^1.0",
"psr/log": "^3.0",
"symfony/console": "^7.0",
"symfony/dependency-injection": "^7.0",
"symfony/filesystem": "^7.0",
"symfony/string": "^7.0",
"symfony/console": "^7.1",
"symfony/dependency-injection": "^7.1",
"symfony/filesystem": "^7.1",
"symfony/string": "^7.1",
"twig/twig": "^3.4"
},
"require-dev": {
Expand All @@ -41,12 +41,14 @@
"phpspec/prophecy-phpunit": "^2.2",
"phpunit/phpunit": "^10.5",
"squizlabs/php_codesniffer": "^3.9",
"symfony/var-dumper": "^7.0",
"symfony/yaml": "^7.0",
"symfony/var-dumper": "^7.1",
"symfony/yaml": "^7.1",
"vimeo/psalm": "^5.24.0"
},
"conflict": {
"squizlabs/php_codesniffer": "<3.6",
"nikic/php-parser": "<4.17"
}
},
"minimum-stability": "RC",
"prefer-stable": true
}
34 changes: 17 additions & 17 deletions scripts/sut-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ if [[ $test_filter = all || $test_filter = form ]]; then

dcg_phpcs --exclude=DrupalPractice.Yaml.RoutingAccess .
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name
fi

Expand Down Expand Up @@ -200,7 +200,7 @@ if [[ $test_filter = all || $test_filter = module_component ]]; then

dcg_phpcs .
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name
fi

Expand Down Expand Up @@ -242,7 +242,7 @@ if [[ $test_filter = all || $test_filter = plugin ]]; then
dcg_module_install $module_machine_name
echo 'Build CKEditor plugin...'
npm install && npm run build
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name
fi

Expand Down Expand Up @@ -274,7 +274,7 @@ if [[ $test_filter = all || $test_filter = service ]]; then

dcg_phpcs $module_dir
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
# Do not uninstall this module as the uninstall validator prevents it.
fi

Expand All @@ -299,7 +299,7 @@ if [[ $test_filter = all || $test_filter = yml ]]; then

dcg_phpcs $module_dir
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name
fi

Expand All @@ -321,7 +321,7 @@ if [[ $test_filter = all || $test_filter = test ]]; then

dcg_phpcs --exclude=Generic.CodeAnalysis.UselessOverridingMethod $module_dir
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name
fi

Expand All @@ -347,7 +347,7 @@ if [[ $test_filter = all || $test_filter = theme_component ]]; then

dcg_phpcs --exclude=Generic.CodeAnalysis.UselessOverridingMethod $module_dir
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name
fi

Expand All @@ -366,7 +366,7 @@ if [[ $test_filter = all || $test_filter = plugin_manager ]]; then

dcg_phpcs .
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name
fi

Expand All @@ -383,7 +383,7 @@ if [[ $test_filter = all || $test_filter = configuration_entity ]]; then

dcg_phpcs .
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name
fi

Expand All @@ -402,7 +402,7 @@ if [[ $test_filter = all || $test_filter = content_entity ]]; then

dcg_phpcs .
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name

dcg_label 'Content entity (with fields)'
Expand All @@ -418,7 +418,7 @@ if [[ $test_filter = all || $test_filter = content_entity ]]; then

dcg_phpcs .
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name

dcg_label 'Content entity (without bundles, fields and canonical page)'
Expand All @@ -434,7 +434,7 @@ if [[ $test_filter = all || $test_filter = content_entity ]]; then

dcg_phpcs .
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name
fi

Expand All @@ -450,7 +450,7 @@ if [[ $test_filter = all || $test_filter = bundle_class ]]; then
$dcg entity:bundle-class -a acme -a Acme -a User -a UserBundle -a Yes -a UserBase
dcg_phpcs $module_dir
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name
fi

Expand All @@ -464,11 +464,11 @@ if [[ $test_filter = all || $test_filter = module ]]; then
cd $module_dir

$dcg module -d $drupal_dir/modules -a Peach -a peach -a 'Simple module generated by DCG.' \
-a DCG -a 'drupal:views, drupal:node, drupal:action' -a Yes -a Yes -a Yes
-a DCG -a 'drupal:views, drupal:node' -a Yes -a Yes -a Yes

dcg_phpcs $module_dir
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name
fi

Expand All @@ -491,7 +491,7 @@ if [[ $test_filter = all || $test_filter = theme ]]; then
dcg_phpcs $theme_dir
dcg_phpcs $module_dir
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name
fi

Expand All @@ -509,6 +509,6 @@ if [[ $test_filter = all || $test_filter = drush ]]; then

dcg_phpcs $module_dir
dcg_module_install $module_machine_name
dcg_phpunit tests
dcg_phpunit $drupal_dir/modules/$module_machine_name/tests
dcg_module_uninstall $module_machine_name
fi
1 change: 1 addition & 0 deletions src/Twig/TwigSortTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class TwigSortTokenParser extends AbstractTokenParser {
* {@inheritdoc}
*/
public function parse(Token $token): Node {
\trigger_deprecation('chi-teck/drupal-code-generator', '3.6.0', 'The sort twig tag is deprecated and will be removed in 5.x, use the sort_namespaces twig filter.');
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(
static fn (Token $token): bool => $token->test('endsort'),
Expand Down
4 changes: 2 additions & 2 deletions templates/Test/_browser/browser.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ declare(strict_types=1);
namespace Drupal\Tests\{{ machine_name }}\Functional;

use Drupal\Tests\BrowserTestBase;
use PHPUnit\Framework\Attributes\Group;

/**
* Test description.
*
* @group {{ machine_name }}
*/
#[Group('{{ machine_name }}')]
final class {{ class }} extends BrowserTestBase {

/**
Expand Down
4 changes: 2 additions & 2 deletions templates/Test/_kernel/kernel.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ declare(strict_types=1);
namespace Drupal\Tests\{{ machine_name }}\Kernel;

use Drupal\KernelTests\KernelTestBase;
use PHPUnit\Framework\Attributes\Group;

/**
* Test description.
*
* @group {{ machine_name }}
*/
#[Group('{{ machine_name }}')]
final class {{ class }} extends KernelTestBase {

/**
Expand Down
4 changes: 2 additions & 2 deletions templates/Test/_unit/unit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ declare(strict_types=1);
namespace Drupal\Tests\{{ machine_name }}\Unit;

use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\Attributes\Group;

/**
* Test description.
*
* @group {{ machine_name }}
*/
#[Group('{{ machine_name }}')]
final class {{ class }} extends UnitTestCase {

/**
Expand Down
4 changes: 2 additions & 2 deletions templates/Test/_webdriver/webdriver.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ declare(strict_types=1);
namespace Drupal\Tests\{{ machine_name }}\FunctionalJavascript;

use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use PHPUnit\Framework\Attributes\Group;

/**
* Tests the JavaScript functionality of the {{ name }} module.
*
* @group {{ machine_name }}
*/
#[Group('{{ machine_name }}')]
final class {{ class }} extends WebDriverTestBase {

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/functional/Generator/PhpStormMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ private function assertPlugins(): void {
self::assertStringContainsString('plugin.manager.block__plugin_ids', $generated_content);
self::assertStringContainsString('plugin.manager.ckeditor5.plugin__plugin_ids', $generated_content);
self::assertStringContainsString('plugin.manager.condition__plugin_ids', $generated_content);
self::assertStringContainsString('plugin.manager.config_action__plugin_ids', $generated_content);
self::assertStringContainsString('plugin.manager.display_variant__plugin_ids', $generated_content);
self::assertStringContainsString('plugin.manager.editor__plugin_ids', $generated_content);
self::assertStringContainsString('plugin.manager.element_info__plugin_ids', $generated_content);
Expand All @@ -198,6 +199,7 @@ private function assertPlugins(): void {
self::assertStringContainsString('plugin.manager.field.widget__plugin_ids', $generated_content);
self::assertStringContainsString('plugin.manager.filter__plugin_ids', $generated_content);
self::assertStringContainsString('plugin.manager.help_section__plugin_ids', $generated_content);
self::assertStringContainsString('plugin.manager.help_topic__plugin_ids', $generated_content);
self::assertStringContainsString('plugin.manager.image.effect__plugin_ids', $generated_content);
self::assertStringContainsString('plugin.manager.link_relation_type__plugin_ids', $generated_content);
self::assertStringContainsString('plugin.manager.mail__plugin_ids', $generated_content);
Expand Down Expand Up @@ -227,7 +229,7 @@ private function assertPlugins(): void {
self::assertStringContainsString('typed_data_manager__plugin_ids', $generated_content);
self::assertStringContainsString('validation.constraint__plugin_ids', $generated_content);

self::assertSame(49, \substr_count($generated_content, 'registerArgumentsSet'));
self::assertSame(51, \substr_count($generated_content, 'registerArgumentsSet'));
}

/**
Expand Down Expand Up @@ -336,7 +338,6 @@ private function assertSettings(): void {
'file_scan_ignore_directories',
'entity_update_batch_size',
'entity_update_backup',
'state_cache',
'migrate_node_migrate_type_classic',
'config_sync_directory',
PHP;
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/Generator/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DrupalCodeGenerator\Command\Template;
use DrupalCodeGenerator\Test\Functional\GeneratorTestBase;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Tests template generator.
Expand Down Expand Up @@ -57,9 +58,8 @@ public function testGenerator(): void {

/**
* Test callback.
*
* @dataProvider templateNameValidatorProvider()
*/
#[DataProvider('templateNameValidatorProvider')]
public function testTemplateNameValidator(mixed $value, bool $exception): void {
if ($exception) {
self::expectExceptionObject(new \UnexpectedValueException('The value is not correct template name'));
Expand All @@ -72,7 +72,7 @@ public function testTemplateNameValidator(mixed $value, bool $exception): void {
/**
* Data provider callback for testTemplateNameValidator().
*/
public function templateNameValidatorProvider(): array {
public static function templateNameValidatorProvider(): array {
return [
['aaa', FALSE],
['aaa.bbb', FALSE],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace Drupal\Tests\foo\Functional;

use Drupal\Tests\BrowserTestBase;
use PHPUnit\Framework\Attributes\Group;

/**
* Test description.
*
* @group foo
*/
#[Group('foo')]
final class ExampleTest extends BrowserTestBase {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace Drupal\Tests\foo\Kernel;

use Drupal\KernelTests\KernelTestBase;
use PHPUnit\Framework\Attributes\Group;

/**
* Test description.
*
* @group foo
*/
#[Group('foo')]
final class ExampleTest extends KernelTestBase {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace Drupal\Tests\foo\Unit;

use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\Attributes\Group;

/**
* Test description.
*
* @group foo
*/
#[Group('foo')]
final class ExampleTest extends UnitTestCase {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace Drupal\Tests\foo\FunctionalJavascript;

use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use PHPUnit\Framework\Attributes\Group;

/**
* Tests the JavaScript functionality of the Foo module.
*
* @group foo
*/
#[Group('foo')]
final class ExampleTest extends WebDriverTestBase {

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/Helper/Drupal/HookInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testHookInfoTemplates(): void {
// A hook from entity.api.php file.
self::assertHookTemplate('entity_field_values_init', $hook_templates);
// A hook from file.api file.
self::assertHookTemplate('file_validate', $hook_templates);
self::assertHookTemplate('file_download', $hook_templates);
// A hook from system.api file.
self::assertHookTemplate('system_themes_page_alter', $hook_templates);
// A hook from user.api.php file.
Expand Down
Loading

0 comments on commit 504d605

Please sign in to comment.