Bug 1381344 - Supplied examples don't work for php-mongodb
Summary: Supplied examples don't work for php-mongodb
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: php-mongodb
Version: 24
Hardware: All
OS: Linux
unspecified
low
Target Milestone: ---
Assignee: Remi Collet
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-10-03 18:57 UTC by KB Benton
Modified: 2016-10-04 07:49 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-10-04 07:49:03 UTC
Type: Bug


Attachments (Terms of Use)

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)


Note You need to log in before you can comment on or make changes to this bug.