Skip to content

Commit

Permalink
Added assertions for equal fixture directories and updated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Sep 14, 2024
1 parent 638559a commit 694bd93
Show file tree
Hide file tree
Showing 121 changed files with 1,155 additions and 1,655 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
with:
name: ${{github.job}}-code-coverage-report-${{ matrix.composer-channel }}-${{ matrix.php-versions }}
path: ./.coverage-html
include-hidden-files: true
if-no-files-found: error

- name: Upload coverage report to Codecov
Expand Down
23 changes: 17 additions & 6 deletions CustomizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* Please keep this link in your project to help others find this tool.
* Thank you!
*
* @see https://github.com/alexSkrypnyk/customizer
* @see https://github.com/AlexSkrypnyk/customizer
*
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
Expand Down Expand Up @@ -71,7 +71,7 @@ class CustomizeCommand extends BaseCommand {
public string $composerjson;

/**
* Composer config data.
* Composer config data loaded before customization.
*
* @var array<string,mixed>
*/
Expand Down Expand Up @@ -113,6 +113,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (empty($answers)) {
$this->io->success($this->message('result_no_questions'));

$this->cleanupSelf();

return 0;
}

Expand Down Expand Up @@ -235,7 +237,7 @@ protected function cleanupSelf(): void {
$should_proceed = $this->configClass::cleanup($this);

if ($should_proceed === FALSE) {
$this->debug("Customizer's was cleanup skipped by the config class.");
$this->debug("Customizer's cleanup was skipped by the config class.");

return;
}
Expand All @@ -261,6 +263,13 @@ protected function cleanupSelf(): void {
static::arrayUnsetDeep($json, ['autoload-dev', 'psr-4', 'AlexSkrypnyk\\Customizer\\Tests\\']);
static::arrayUnsetDeep($json, ['config', 'allow-plugins', 'alexskrypnyk/customizer']);

// Remove the Customizer from the list of repositories if it was added as a
// local or overridden dependency.
// @todo Update to only remove if the package `url` path matches the current
// working directory.
static::arrayUnsetDeep($json, ['repositories']);
static::arrayUnsetDeep($json, ['minimum-stability']);

// If the package data has changed, update the composer.json file.
if (strcmp(serialize($this->composerjsonData), serialize($json)) !== 0) {
$this->writeComposerJson($this->cwd . '/composer.json', $json);
Expand Down Expand Up @@ -309,10 +318,12 @@ protected function cleanupSelf(): void {
* Message.
*/
protected function message(string $name, array $tokens = []): string {
// Default messages from this class.
$messages = static::messages($this);

if (!empty($this->configClass)) {
if (method_exists($this->configClass, 'messages') && !is_callable([$this->configClass, 'messages'])) {
// Messages from the config class if 'messages' method exists.
if (!empty($this->configClass) && method_exists($this->configClass, 'messages')) {
if (!is_callable([$this->configClass, 'messages'])) {
throw new \RuntimeException(sprintf('Optional method `messages()` exists in the config class %s but is not callable', $this->configClass));
}
$messages = array_replace_recursive($messages, $this->configClass::messages($this));
Expand Down Expand Up @@ -673,7 +684,7 @@ public static function arrayUnsetDeep(array &$array, array $path, ?string $value
*/
public static function messages(CustomizeCommand $c): array {
return [
'title' => 'Welcome to {{ package.name }} project customizer',
'title' => 'Welcome to the "{{ package.name }}" project customizer',
'header' => [
'Please answer the following questions to customize your project.',
'You will be able to review your answers before proceeding.',
Expand Down
3 changes: 1 addition & 2 deletions customize.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public static function questions(CustomizeCommand $c): array {
// The discover callback function is used to discover the value from the
// environment. In this case, we use the current directory name
// and the GITHUB_ORG environment variable to generate the package name.
// @phpstan-ignore-next-line
'discover' => static function (CustomizeCommand $c): ?string {
'discover' => static function (CustomizeCommand $c): string {
$name = basename((string) getcwd());
$org = getenv('GITHUB_ORG') ?: 'acme';

Expand Down
5 changes: 5 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@
<exclude-pattern>*.TestCase\.php</exclude-pattern>
<exclude-pattern>*.test</exclude-pattern>
</rule>

<!-- Allow missing class description names in test fixtures. -->
<rule ref="Drupal.Commenting.ClassComment.Short">
<exclude-pattern>tests/phpunit/Fixtures</exclude-pattern>
</rule>
</ruleset>
107 changes: 0 additions & 107 deletions tests/phpunit/Dirs.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Syntax of this file is similar to .gitignore with addition of content changes
# ignoring using ^ prefix:
# Comments start with #.
# file - ignore file
# dir/ - ignore directory and all subdirectories
# dir/* - ignore all files in directory, but not subdirectories
# ^file - ignore content changes in file, but not the file itself
# ^dir/ - ignore content changes in all files and subdirectories, but check that the directory itself exists
# ^dir/* - ignore content changes in all files, but not subdirectories and check that the directory itself exists
# !file - do not ignore file
# !dir/ - do not ignore directory, including all subdirectories
# !dir/* - do not ignore all files in directory, but not subdirectories
# !^file - do not ignore content changes in file
# !^dir/ - do not ignore content changes in all files and subdirectories
# !^dir/* - do not ignore content changes in all files, but not subdirectories

# Ignore all files by extension.
*.log

# Ignore file in root and all directories.
f3-new-file-ignore-everywhere.txt

# Ignore dir with all files, but not subdirectories.
dir2_flat/*

# Ignore all files and subdirectories in the directory.
dir3_subdirs/*
# But include sub-sub-directory.
!dir3_subdirs/dir32-unignored/

# Ignore directory and all subdirectories.
dir4_full_ignore/

# Ignore content in the directory.
^dir5_content_ignore/
# But include this file content changes for comparison.
!^dir5_content_ignore/d5f2-unignored-content.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d1f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d1f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d3f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
d3f2l1

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d31f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d31f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d32f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d32f2l1.log only src
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d32f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d5f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d5f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d5f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f4l1.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d1f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d1f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d2f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d2f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d3f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d3f2l1-changes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d31f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d31f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f3l1 - full ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d32f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d32f2l1.log only dst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d32f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f3l1 - full ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d4f1l1-fully ignored
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d5f1l1-changed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d5f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d5f1l1-changed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f3l1 - full ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f4l1.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f4l1.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Syntax of this file is similar to .gitignore with addition of content changes
# ignoring using ^ prefix:
# Comments start with #.
# file - ignore file
# dir/ - ignore directory and all subdirectories
# dir/* - ignore all files in directory, but not subdirectories
# ^file - ignore content changes in file, but not the file itself
# ^dir/ - ignore content changes in all files and subdirectories, but check that the directory itself exists
# ^dir/* - ignore content changes in all files, but not subdirectories and check that the directory itself exists
# !file - do not ignore file
# !dir/ - do not ignore directory, including all subdirectories
# !dir/* - do not ignore all files in directory, but not subdirectories
# !^file - do not ignore content changes in file
# !^dir/ - do not ignore content changes in all files and subdirectories
# !^dir/* - do not ignore content changes in all files, but not subdirectories

# Ignore all files by extension.
*.log

# Ignore file in root and all directories.
f3-new-file-ignore-everywhere.txt

# Ignore dir with all files, but not subdirectories.
dir2_flat/*

# Ignore all files and subdirectories in the directory.
dir3_subdirs/*
# But include sub-sub-directory.
!dir3_subdirs/dir32-unignored/

# Ignore directory and all subdirectories.
dir4_full_ignore/

# Ignore content in the directory.
^dir5_content_ignore/
# But include this file content changes for comparison.
!^dir5_content_ignore/d5f2-unignored-content.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d1f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d1f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d1f3l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d3f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
d3f2l1

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d31f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d31f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d32f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d32f2l1.log only src
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d32f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d5f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d5f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d5f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f4l1.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d1f1l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d1f2l1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d2f1l1
Loading

0 comments on commit 694bd93

Please sign in to comment.