title: php7 mongodb driver ObjectId not found
body: <p>I follow the instructions on <a href="https://github.com/mongodb/mongo-php-library" rel="nofollow noreferrer">mongodb/mongo-php-library</a> official repository </p>
  
  <pre><code>$ pecl install mongodb
  $ echo "extension=mongodb.so" &gt;&gt; `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
  </code></pre>
  
  <p>but when i try to execute a test with phpunit over this constructor:</p>
  
  <pre><code>    use MongoDB\BSON\ObjectID;
  
      (...)
  
      /**
       * X constructor.
       *
       * @param ObjectID|null $id
       */
      public function __construct(ObjectID $id = null)
      {
          if (!$id) {
              $id = new ObjectID();
          }
  
          $this-&gt;id = $id;
      }
  
      (...)
  </code></pre>
  
  <p>i got this error</p>
  
  <pre><code>1) tests\X\X\XTest::testBeConstructed
  Error: Class 'MongoDB\BSON\ObjectID' not found
  </code></pre>
  
  <h1>EDIT</h1>
  
  <p>if i create a test file with this single line of code:</p>
  
  <pre><code>&lt;?php
  
  echo new \MongoDB\BSON\ObjectID();
  </code></pre>
  
  <p>and i execute it with</p>
  
  <pre><code>php test.php
  </code></pre>
  
  <p>it shows:</p>
  
  <pre><code>581ddc9c6fb3720352664f11
  </code></pre>
  
  <h1>SECOND EDIT</h1>
  
  <p>As adviced in the comments i put some debug lines at first line on my phpunit tests:</p>
  
  <pre><code>var_dump(extension_loaded('mongodb'));
  echo phpversion().PHP_EOL;
  print_r(get_loaded_extensions());
  </code></pre>
  
  <p>here is the output</p>
  
  <pre><code>bool(true)
  7.0.8-0ubuntu0.16.04.3
  Array
  (
      [0] =&gt; Core
      [1] =&gt; date
      [2] =&gt; libxml
      [3] =&gt; openssl
      [4] =&gt; pcre
      [5] =&gt; zlib
      [6] =&gt; filter
      [7] =&gt; hash
      [8] =&gt; pcntl
      [9] =&gt; Reflection
      [10] =&gt; SPL
      [11] =&gt; session
      [12] =&gt; standard
      [13] =&gt; phpdbg
      [14] =&gt; mysqlnd
      [15] =&gt; PDO
      [16] =&gt; xml
      [17] =&gt; bcmath
      [18] =&gt; calendar
      [19] =&gt; ctype
      [20] =&gt; curl
      [21] =&gt; dom
      [22] =&gt; mbstring
      [23] =&gt; fileinfo
      [24] =&gt; ftp
      [25] =&gt; gd
      [26] =&gt; gettext
      [27] =&gt; iconv
      [28] =&gt; intl
      [29] =&gt; json
      [30] =&gt; exif
      [31] =&gt; mcrypt
      [32] =&gt; mysqli
      [33] =&gt; pdo_mysql
      [34] =&gt; Phar
      [35] =&gt; posix
      [36] =&gt; readline
      [37] =&gt; shmop
      [38] =&gt; SimpleXML
      [39] =&gt; sockets
      [40] =&gt; sysvmsg
      [41] =&gt; sysvsem
      [42] =&gt; sysvshm
      [43] =&gt; tokenizer
      [44] =&gt; wddx
      [45] =&gt; xmlreader
      [46] =&gt; xmlwriter
      [47] =&gt; xsl
      [48] =&gt; Zend OPcache
  )
  PHPUnit 5.6.2 by Sebastian Bergmann and contributors.
  </code></pre>
  
  <p>im running phpunit with the following command</p>
  
  <pre><code>phpdbg -qrr /root/.composer/vendor/bin/phpunit
  </code></pre>
  
  <p>Why is phpunit not recognizing the mongodb ext?</p>
  
  <p>What im missing?</p>
  
  <p>Thanks</p>
  
  <p>NOTE: if you wonder why im root is because this is inside a docker container</p>