Skip to content

Investigate and fix failing tests in the ComposerTest class #339

@ajoh504

Description

@ajoh504

Describe the bug
The ComposerTest class fails when generating composer.json settings. PHPUnit reports these errors:

Failed asserting that two strings are identical.
#Warning: Strings contain different line endings!

There are at least three possible causes:

  1. Schema Mismatch: The "actual" output includes an authors block missing from the "expected" resource file.
  2. For the file line endings, there is a possible mismatch between Unix (\n) and Windows (\r\n) endings.
  3. The expected value conains Unix path separators which causes the tests to fail in a Windows environment. The path separator should be normalized to prevent this.

PHPUnit diffs

-'{
-    "name": "wsdltophp/bing",
-    "description": "Package generated from C:\CS\Web Development\PHP\WsdlToPHP\PackageGenerator\PackageGenerator\tests/resources/bingsearch.wsdl using wsdltophp/packagegenerator",
-    "require": {
-        "php": ">=7.4",
-        "ext-dom": "*",
-        "ext-mbstring": "*",
-        "ext-soap": "*",
-        "wsdltophp/packagebase": "~5.0",
-        "wsdltophp/wssecurity": "dev-master"
-    },
-    "autoload": {
-        "psr-4": {
-            "": "./src/"
-        }
-    },
-    "require-dev": {
-        "friendsofphp/php-cs-fixer": "^3.0",
-        "phpstan/phpstan": "^2",
-        "phpunit/phpunit": "^9",
-        "rector/rector": "^2"
-    },
-    "config": {
-        "disable-tls": true,
-        "sort-packages": true
-    }

PHPUnit - example output for "actual" value:

+'{
+    "name": "wsdltophp/bing",
+    "description": "Package generated from C:\\CS\\Web Development\\PHP\\WsdlToPHP\\PackageGenerator\\PackageGenerator\\tests/resources/bingsearch.wsdl using wsdltophp/packagegenerator",
+    "require": {
+        "php": ">=7.4",
+        "ext-dom": "*",
+        "ext-mbstring": "*",
+        "ext-soap": "*",
+        "wsdltophp/packagebase": "~5.0",
+        "wsdltophp/wssecurity": "dev-master"
+    },
+    "authors": [
+        {
+            "name": "author_name",
+            "email": "author@email.com"
+        }
+    ],
+    "autoload": {
+        "psr-4": {
+            "": "./src\\"
+        }
+    },
+    "require-dev": {
+        "friendsofphp/php-cs-fixer": "^3.0",
+        "phpstan/phpstan": "^2",
+        "phpunit/phpunit": "^9",
+        "rector/rector": "^2"
+    },
+    "config": {
+        "disable-tls": true,
+        "sort-packages": true
+    }

To Reproduce
Run the tests:

  • composer test
  • vendor/bin/phpunit --filter=ComposerTest

Expected behavior
Tests should pass regardless of the development platform, and the expected resource files should match the generated schema.

Additional context
The "expected" value comes from test files in the following location: src/tests/resources/generated.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions