box icon indicating copy to clipboard operation
box copied to clipboard

Interfaces are not copied into the Phar

Open ramsey opened this issue 3 years ago β€’ 4 comments

Bug report

Question Answer
Box version 3.16.0
PHP version 8.0.16
Platform with version macOS 12.2.1
Github Repo n/a

I'm encountering an issue where it appears some of the interfaces from the vendor/ directory are not being copied into the generated Phar file.

box.json.dist

My box.json.dist is empty, for the sake of this reproducible example.

{}
Steps to reproduce
mkdir box-test/
cd box-test/
composer require phpunit/phpunit humbug/box
echo "<?php echo 'Hello';" > index.php
./vendor/bin/box compile --debug

# Get a list of all files in `vendor/` that contain a line matching `'^interface '`
ack --nocolor --sort-files --files-with-matches '^interface ' vendor/ > interfaces-pre-build.txt

# Get a list of all files in `.box_dump/vendor/` that contain a line matching `'^interface '`
ack --nocolor --sort-files --files-with-matches '^interface ' .box_dump/vendor/ > interfaces-post-build.txt

# Remove the `.box_dump/` prefix from paths in `interfaces-post-build.txt` for easier comparison
sed -i -e 's/\.box_dump\///' interfaces-post-build.txt

# Compare the files
diff -u interfaces-pre-build.txt interfaces-post-build.txt

You'll see output like this:

--- interfaces-pre-build.txt	2022-03-13 14:59:11.000000000 -0500
+++ interfaces-post-build.txt	2022-03-13 15:01:36.000000000 -0500
@@ -3,8 +3,6 @@
 vendor/amphp/amp/lib/Promise.php
 vendor/amphp/byte-stream/lib/InputStream.php
 vendor/amphp/byte-stream/lib/OutputStream.php
-vendor/amphp/parallel/docs/worker-pool.md
-vendor/amphp/parallel/docs/workers.md
 vendor/amphp/parallel/lib/Context/Context.php
 vendor/amphp/parallel/lib/Context/ContextFactory.php
 vendor/amphp/parallel/lib/Sync/Channel.php
@@ -34,8 +32,6 @@
 vendor/fidry/console/src/Command/LazyCommand.php
 vendor/fidry/console/src/Internal/Type/InputType.php
 vendor/fidry/console/src/Internal/Type/ScalarType.php
-vendor/humbug/box/.requirement-checker/src/IsFulfilled.php
-vendor/humbug/box/.requirement-checker/vendor/composer/semver/src/Constraint/ConstraintInterface.php
 vendor/humbug/box/fixtures/composer-dump/dir002/vendor/beberlei/assert/lib/Assert/AssertionFailedException.php
 vendor/humbug/box/fixtures/configuration/dir001/vendor/beberlei/assert/lib/Assert/AssertionFailedException.php
 vendor/humbug/box/fixtures/configuration/dir002/vendor/beberlei/assert/lib/Assert/AssertionFailedException.php
@@ -66,7 +62,6 @@
 vendor/jetbrains/phpstorm-stubs/pq/pq.php
 vendor/jetbrains/phpstorm-stubs/pthreads/pthreads.php
 vendor/jetbrains/phpstorm-stubs/session/SessionHandler.php
-vendor/jetbrains/phpstorm-stubs/tests/Model/StubProblemType.php
 vendor/jetbrains/phpstorm-stubs/yaf/yaf.php
 vendor/jetbrains/phpstorm-stubs/yaf/yaf_namespace.php
 vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/ConstraintInterface.php
@@ -125,7 +120,6 @@
 vendor/phpunit/php-text-template/src/exceptions/Exception.php
 vendor/phpunit/php-timer/src/exceptions/Exception.php
 vendor/phpunit/phpunit/src/Exception.php
-vendor/phpunit/phpunit/src/Framework/IncompleteTest.php
 vendor/phpunit/phpunit/src/Framework/MockObject/Builder/Identity.php
 vendor/phpunit/phpunit/src/Framework/MockObject/Builder/InvocationStubber.php
 vendor/phpunit/phpunit/src/Framework/MockObject/Builder/MethodNameMatch.php
@@ -140,8 +134,6 @@
 vendor/phpunit/phpunit/src/Framework/MockObject/Verifiable.php
 vendor/phpunit/phpunit/src/Framework/Reorderable.php
 vendor/phpunit/phpunit/src/Framework/SelfDescribing.php
-vendor/phpunit/phpunit/src/Framework/SkippedTest.php
-vendor/phpunit/phpunit/src/Framework/Test.php
 vendor/phpunit/phpunit/src/Framework/TestListener.php
 vendor/phpunit/phpunit/src/Runner/Hook/AfterIncompleteTestHook.php
 vendor/phpunit/phpunit/src/Runner/Hook/AfterLastTestHook.php

What's important to note is that the vendor directory in .box_dump is missing the following interfaces:

  • vendor/jetbrains/phpstorm-stubs/tests/Model/StubProblemType.php
  • vendor/phpunit/phpunit/src/Framework/IncompleteTest.php
  • vendor/phpunit/phpunit/src/Framework/SkippedTest.php
  • vendor/phpunit/phpunit/src/Framework/Test.php

This seems to happen every time I run it, so I don't think this is an intermittent issue.

ramsey avatar Mar 13 '22 20:03 ramsey

Weird indeed, could you also print out the resolved configuration? (it should be in .box_dump

theofidry avatar Mar 13 '22 20:03 theofidry

Apparently, GitHub has a limit to the size of comments: 65,536 characters. πŸ˜„

Here's the .box_configuration: https://gist.github.com/ramsey/711387b710852213a54bf6446f9ebf0f

ramsey avatar Mar 13 '22 20:03 ramsey

I'm curious whether you (or others) have been able to reproduce this.

ramsey avatar Mar 19 '22 15:03 ramsey

I tried debugging this a bit, but I’m unable to figure out what’s different about these files that makes them consistently excluded from the Phar.

ramsey avatar Mar 31 '22 18:03 ramsey

Finally had the time to take a look. I am pretty sure this is caused by https://github.com/box-project/box/blob/main/src/Configuration/Configuration.php#L1519.

theofidry avatar Feb 01 '23 19:02 theofidry

Thanks for looking. It's been a long time since I've looked at this (I gave up trying πŸ˜„). That line wouldn't explain why StubProblemType.php was excluded.

ramsey avatar Feb 01 '23 23:02 ramsey

It's in the same group:

-vendor/jetbrains/phpstorm-stubs/tests/Model/StubProblemType.php

Notice it's in the tests directory which is also excluded. I think the intent is good and it's there since forever and has been improved but removing the test PHP classes seems to be too much. At the very least there should be an option to disable this optimization.

theofidry avatar Feb 02 '23 08:02 theofidry