Bug 1381344

Summary: Supplied examples don't work for php-mongodb
Product: [Fedora] Fedora Reporter: KB Benton <kbcmdba>
Component: php-mongodbAssignee: Remi Collet <fedora>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: unspecified    
Version: 24CC: fedora
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-10-04 07:49:03 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description KB Benton 2016-10-03 18:57:51 UTC
Description of problem:

Examples supplied use the bootstrap.php file which looks for a composer installation in order to get the autoload.php file.

Version-Release number of selected component (if applicable):
php-mongodb-1.0.2-1.fc24.noarch

How reproducible:
/usr/share/doc/php-mongodb/examples files won't run as-provided.

bootstrap.php contains...

<?php

if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
    // Dependencies were installed with Composer and this is the main project
    $loader = require_once __DIR__ . '/../vendor/autoload.php';
} elseif (file_exists(__DIR__ . '/../../../../autoload.php')) {
    // We're installed as a dependency in another project's `vendor` directory
    $loader = require_once __DIR__ . '/../../../../autoload.php';
} else {
    throw new Exception('Can\'t find autoload.php. Did you install dependencies with Composer?');
}

Steps to Reproduce:
1. php /usr/share/doc/php-mongodb/examples/write.php
2.
3.

Actual results:
PHP Fatal error:  Uncaught exception 'Exception' with message 'Can't find autoload.php. Did you install dependencies with Composer?' in /usr/share/doc/php-mongodb/examples/bootstrap.php:10
Stack trace:
#0 /usr/share/doc/php-mongodb/examples/write.php(3): require_once()
#1 {main}
  thrown in /usr/share/doc/php-mongodb/examples/bootstrap.php on line 10

Expected results:
Database connection error in the event that MongoDB isn't running locally or the dialog listed in write.php

Additional info:

Comment 1 KB Benton 2016-10-03 19:01:54 UTC
Thanks for supplying php-mongodb with Fedora. It's much preferred to install libraries like this via RPM than through composer. That way, once installed, dnf can keep me up-to-date. Unfortunately, the supplied examples don't work as expected.

Comment 2 KB Benton 2016-10-03 19:47:09 UTC
Also note:

In examples/write.php:

$collection = new MongoDB\Collection($manager, "phplib_demo.write");

... should be changed to

$collection = new MongoDB\Collection($manager, "phplib_demo", "write");

in order to run as expected.

Comment 3 KB Benton 2016-10-03 19:51:45 UTC
Please note, I did not utilize the README.md instructions before reporting this bug. Note: Despite that, I am concerned that the examples supplied rely on the composer method of installing parts of the libraries required in order to make these examples work. I think it's important for RPMs to rely solely on other RPMs where possible/practical. I would hope that this is one case of that. I don't have editbugs priv or I'd drop the severity to medium.

Comment 4 Remi Collet 2016-10-04 07:45:46 UTC
(In reply to KB Benton from comment #2)
> Also note:
> 
> In examples/write.php:
> 
> $collection = new MongoDB\Collection($manager, "phplib_demo.write");
> 
> ... should be changed to
> 
> $collection = new MongoDB\Collection($manager, "phplib_demo", "write");
> 
> in order to run as expected.

If there is a mistake in the provided examples, please report this upstream on https://github.com/mongodb/mongo-php-library/issues

(In reply to KB Benton from comment #0)
> Description of problem:
> 
> Examples supplied use the bootstrap.php file which looks for a composer
> installation in order to get the autoload.php file.

I will have a look, but can't consider this a important.
I plan to fix rawhide, so the fix will be in next update (and I don't want to differ more the 1.0.3 update, in testing)

Comment 5 Remi Collet 2016-10-04 07:49:03 UTC
BTW, examples have been dropped upstream, and are no more provided as documentation (1.0.3)