Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Pest not support when composer "vendor" dir is customised (aka in a subdirectory not named vendor/) #1130

Open
luri-fr opened this issue Apr 8, 2024 · 3 comments
Labels

Comments

@luri-fr
Copy link

luri-fr commented Apr 8, 2024

What Happened

I use composer config to change vendor/ directory to libs/. (see : https://getcomposer.org/doc/06-config.md#vendor-dir )
But when I use ./libs/bin/pest --init, I have somes error :

PHP Warning:  include_once(D:\[...]\MyOidc\libs\pestphp\pest/vendor/autoload.php): Failed to open stream: No such file or directory in D:\[...]\MyOidc\libs\pestphp\pest\bin\pest on line 63
PHP Stack trace:
PHP   1. {main}() D:\[...]\MyOidc\libs\bin\pest:0
PHP   2. include() D:\[...]\MyOidc\libs\bin\pest:119
PHP   3. {closure:D:\[...]\MyOidc\libs\pestphp\pest\bin\pest:12-99}() D:\[...]\MyOidc\libs\pestphp\pest\bin\pest:99

Warning: include_once(D:\[...]\MyOidc\libs\pestphp\pest/vendor/autoload.php): Failed to open stream: No such file or directory in D:\[...]\MyOidc\libs\pestphp\pest\bin\pest on line 63

Call Stack:
    0.0002     559592   1. {main}() D:\[...]\MyOidc\libs\bin\pest:0
    0.0003     571984   2. include('D:\[...]\MyOidc\libs\pestphp\pest\bin\pest') D:\[...]\MyOidc\libs\bin\pest:119
    0.0004     572368   3. {closure:D:\[...]\MyOidc\libs\pestphp\pest\bin\pest:12-99}() D:\[...]\MyOidc\libs\pestphp\pest\bin\pest:99

PHP Warning:  include_once(): Failed opening 'D:\[...]\MyOidc\libs\pestphp\pest/vendor/autoload.php' for inclusion (include_path='.;C:\php\pear') in D:\[...]\MyOidc\libs\pestphp\pest\bin\pest on line 63
PHP Stack trace:
PHP   1. {main}() D:\[...]\MyOidc\libs\bin\pest:0
PHP   2. include() D:\[...]\MyOidc\libs\bin\pest:119
PHP   3. {closure:D:\[...]\MyOidc\libs\pestphp\pest\bin\pest:12-99}() D:\[...]\MyOidc\libs\pestphp\pest\bin\pest:99

Warning: include_once(): Failed opening 'D:\[...]\MyOidc\libs\pestphp\pest/vendor/autoload.php' for inclusion (include_path='.;C:\php\pear') in D:\[...]\MyOidc\libs\pestphp\pest\bin\pest on line 63

Call Stack:
    0.0002     559592   1. {main}() D:\[...]\MyOidc\libs\bin\pest:0
    0.0003     571984   2. include('D:\[...]\MyOidc\libs\pestphp\pest\bin\pest') D:\[...]\MyOidc\libs\bin\pest:119
    0.0004     572368   3. {closure:D:\[...]\MyOidc\libs\pestphp\pest\bin\pest:12-99}() D:\[...]\MyOidc\libs\pestphp\pest\bin\pest:99

PHP Fatal error:  Uncaught Error: Class "Symfony\Component\Console\Input\ArgvInput" not found in D:\[...]\MyOidc\libs\pestphp\pest\bin\pest:69
Stack trace:
#0 D:\[...]\MyOidc\libs\pestphp\pest\bin\pest(99): {closure}()
#1 D:\[...]\MyOidc\libs\bin\pest(119): include('D:\\[...]\\...')
#2 {main}
  thrown in D:\[...]\MyOidc\libs\pestphp\pest\bin\pest on line 69

Fatal error: Uncaught Error: Class "Symfony\Component\Console\Input\ArgvInput" not found in D:\[...]\MyOidc\libs\pestphp\pest\bin\pest on line 69

Error: Class "Symfony\Component\Console\Input\ArgvInput" not found in D:\[...]\MyOidc\libs\pestphp\pest\bin\pest on line 69

Call Stack:
    0.0002     559592   1. {main}() D:\[...]\MyOidc\libs\bin\pest:0
    0.0003     571984   2. include('D:\[...]\MyOidc\libs\pestphp\pest\bin\pest') D:\Gilles\Docs\projets\MyOidc\libs\bin\pest:119
    0.0004     572368   3. {closure:D:\[...]\MyOidc\libs\pestphp\pest\bin\pest:12-99}() D:\[...]\MyOidc\libs\pestphp\pest\bin\pest:99

Composer explicitly support custom vendor directory, so Pest must support them.

I'll see if there's an easy modification I can make to correct this.

How to Reproduce

  • Make a projet whith this composer.json file 👍
{
	"name": "TEST",
	"require": {
		"php": ">=8.2"
    },
	"config": {
		"vendor-dir": "libs",
		"allow-plugins": {
			"pestphp/pest-plugin": true
		}
	},
	"require-dev": {
		"pestphp/pest": "^2.34"
	}
}

composer install --dev

./libs/bin/pest --init

Sample Repository

No response

Pest Version

2.34

PHP Version

8.2.16

Operation System

Windows

Notes

No response

@luri-fr luri-fr added the bug label Apr 8, 2024
@luri-fr
Copy link
Author

luri-fr commented Apr 8, 2024

Ok. In my libs/bin/pest file, I have :

#!/usr/bin/env php
<?php

/**
 * Proxy PHP file generated by Composer
 *
 * This file includes the referenced bin path (../pestphp/pest/bin/pest)
 * using a stream wrapper to prevent the shebang from being output on PHP<8
 *
 * @generated
 */

namespace Composer;

$GLOBALS['_composer_bin_dir'] = __DIR__;
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';

if (PHP_VERSION_ID < 80000) {
[...]

So, if I replace Line 54 of pestphp/pest/bin/pest :

    $vendorPath = dirname(__DIR__, 4).'/vendor/autoload.php';

by

    $vendorPath = $GLOBALS['_composer_autoload_path'];

it's working for me.
But this fix is linked to the version of composer (2.7.2) and i don't know in which version composer introduce $GLOBALS['_composer_autoload_path'] and which minimum version of composer you want to support.
So I don't make PR. (I don't want to break other people.)

@luri-fr
Copy link
Author

luri-fr commented Apr 8, 2024

Well... not really working.

.\libs\bin\pest --init create file in libs\bin\ directory and after I move the files .\libs\bin\pest show :

   INFO  Cannot open bootstrap script "D:\[...]\MyOidc\vendor/autoload.php".

@luri-fr
Copy link
Author

luri-fr commented Apr 8, 2024

Ok I found.

In phpunit.xml, I must replace :

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         colors="true"
>

by

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
         bootstrap="libs/autoload.php"
         colors="true"
>

Perhaps this can be added in the documention ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant