lucatume / wp-browser

The easy and reliable way to test WordPress with Codeception. 10 years of proven success.
https://wpbrowser.wptestkit.dev/
MIT License
603 stars 86 forks source link

PHP Warning: Invalid argument....Codeception/Lib/Driver/Db.php on line 108 #81

Closed truckee closed 7 years ago

truckee commented 7 years ago

This is a redirect from Codeception issues.

Error message & stack trace below. Database is expected to include a table named options? What are [blogs] and [site]?

HomePageCept.php

<?php 
$I = new FunctionalTester($scenario);
$I->wantTo('check home page');
$I->amOnPage('/');
$I->see('Unitarian');
$ ./codecept -vvv run
Codeception PHP Testing Framework v2.3.3
Powered by PHPUnit 6.2.1 by Sebastian Bergmann and contributors.

  Tried to replace WordPress site domain but dump file does not contain an `options` table INSERT instruction.
  Tried to replace WordPress site domain but dump file does not contain a table INSERT instruction for table [blogs].
  Tried to replace WordPress site domain but dump file does not contain a table INSERT instruction for table [site].
PHP Warning:  Invalid argument supplied for foreach() in /home/george/vendor/codeception/codeception/src/Codeception/Lib/Driver/Db.php on line 108
  [Db] Connected to uufnn
  Tried to replace WordPress site domain but dump file does not contain an `options` table INSERT instruction.
  Tried to replace WordPress site domain but dump file does not contain a table INSERT instruction for table [blogs].
  Tried to replace WordPress site domain but dump file does not contain a table INSERT instruction for table [site].

  [PHPUnit\Framework\Exception]
  Invalid argument supplied for foreach()

Exception trace:
 () at /home/george/vendor/codeception/codeception/src/Codeception/Subscriber/ErrorHandler.php:75
 Codeception\Subscriber\ErrorHandler->errorHandler() at /home/george/vendor/codeception/codeception/src/Codeception/Lib/Driver/Db.php:108
 Codeception\Lib\Driver\Db->load() at /home/george/vendor/lucatume/wp-browser/src/Codeception/Module/WPDb.php:2272
 Codeception\Module\WPDb->loadDumpUsingDriver() at /home/george/vendor/codeception/codeception/src/Codeception/Module/Db.php:363
 Codeception\Module\Db->_loadDump() at /home/george/vendor/codeception/codeception/src/Codeception/Module/Db.php:243
 Codeception\Module\Db->_beforeSuite() at /home/george/vendor/codeception/codeception/src/Codeception/Subscriber/Module.php:38
 Codeception\Subscriber\Module->beforeSuite() at n/a:n/a
 call_user_func() at /home/george/vendor/symfony/event-dispatcher/EventDispatcher.php:184
 Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() at /home/george/vendor/symfony/event-dispatcher/EventDispatcher.php:46
 Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at /home/george/vendor/codeception/codeception/src/Codeception/SuiteManager.php:156
 Codeception\SuiteManager->run() at /home/george/vendor/codeception/codeception/src/Codeception/Codecept.php:184
 Codeception\Codecept->runSuite() at /home/george/vendor/codeception/codeception/src/Codeception/Codecept.php:153
 Codeception\Codecept->run() at /home/george/vendor/codeception/codeception/src/Codeception/Command/Run.php:380
 Codeception\Command\Run->runSuites() at /home/george/vendor/codeception/codeception/src/Codeception/Command/Run.php:307
 Codeception\Command\Run->execute() at /home/george/vendor/symfony/console/Command/Command.php:266
 Symfony\Component\Console\Command\Command->run() at /home/george/vendor/symfony/console/Application.php:856
 Symfony\Component\Console\Application->doRunCommand() at /home/george/vendor/symfony/console/Application.php:203
 Symfony\Component\Console\Application->doRun() at /home/george/vendor/symfony/console/Application.php:127
 Symfony\Component\Console\Application->run() at /home/george/vendor/codeception/codeception/src/Codeception/Application.php:103
 Codeception\Application->run() at /home/george/vendor/codeception/codeception/codecept:36

$ composer show

antecedent/patchwork               2.0.6   Method redefinition (monkey-patching) functionality for PHP.
bacon/bacon-string-utils           1.1.0   BaconStringUtils contain utitilies to work with strings.
behat/gherkin                      v4.4.5  Gherkin DSL parser for PHP 5.3
codeception/codeception            2.3.3   BDD-style testing framework
composer/ca-bundle                 1.0.7   Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.
composer/composer                  1.4.2   Composer helps you declare, manage and install dependencies of PHP projects, ensuring you have the right stac...
composer/semver                    1.4.2   Semver library that offers utilities, version constraint parsing and validation.
composer/spdx-licenses             1.1.6   SPDX licenses list and validation library.
dg/mysql-dump                      v1.4.0  MySQL database dump.
doctrine/inflector                 v1.1.0  Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator              1.0.5   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
facebook/webdriver                 1.1.1   A PHP client for WebDriver
guzzlehttp/guzzle                  6.2.3   Guzzle is a PHP HTTP client library
guzzlehttp/promises                v1.3.1  Guzzle promises library
guzzlehttp/psr7                    1.4.2   PSR-7 message implementation that also provides common utility methods
hautelook/phpass                   0.3.3   Portable PHP password hashing framework
illuminate/contracts               v5.4.19 The Illuminate Contracts package.
illuminate/support                 v5.4.19 The Illuminate Support package.
justinrainbow/json-schema          5.2.1   A library to validate a json schema.
lucatume/codeception-setup-local   1.0.3   Flexible local setup for Codeception
lucatume/wp-browser                1.21.3  WordPress extension of the PhpBrowser class.
lucatume/wp-browser-commons        1.2.8.2 Common libraries of the WP-Browser package.
mikemclin/laravel-wp-password      2.0.0   Laravel package that checks and creates WordPress password hashes
mustache/mustache                  v2.11.1 A Mustache implementation in PHP.
mustangostang/spyc                 0.6.2   A simple YAML loader/dumper class for PHP
myclabs/deep-copy                  1.6.1   Create deep copies (clones) of your objects
nb/oxymel                          v0.1.0  A sweet XML builder
paragonie/random_compat            v2.0.10 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
phar-io/manifest                   1.0.1   Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                    1.0.1   Library for handling version information and constraints
phpdocumentor/reflection-common    1.0     Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock  3.1.1   With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve inform...
phpdocumentor/type-resolver        0.2.1
phpspec/prophecy                   v1.7.0  Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage          5.2.1   Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator          1.4.2   FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template          1.2.1   Simple template engine.
phpunit/php-timer                  1.0.9   Utility class for timing
phpunit/php-token-stream           1.4.11  Wrapper around PHP's tokenizer extension.
phpunit/phpunit                    6.2.1   The PHP Unit Testing framework.
phpunit/phpunit-mock-objects       4.0.1   Mock Object library for PHPUnit
psr/http-message                   1.0.1   Common interface for HTTP messages
psr/log                            1.0.2   Common interface for logging libraries
ramsey/array_column                1.1.3   Provides functionality for array_column() to projects using PHP earlier than version 5.5.
rmccue/requests                    v1.7.0  A HTTP library written in PHP, for human beings.
sebastian/code-unit-reverse-lookup 1.0.1   Looks up which function or method a line of code belongs to
sebastian/comparator               2.0.0   Provides the functionality to compare PHP values for equality
sebastian/diff                     1.4.3   Diff implementation
sebastian/environment              3.0.3   Provides functionality to handle HHVM/PHP environments
sebastian/exporter                 3.1.0   Provides the functionality to export PHP variables for visualization
sebastian/global-state             2.0.0   Snapshotting of global state
sebastian/object-enumerator        3.0.2   Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector         1.1.1   Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context        3.0.0   Provides functionality to recursively process PHP variables
sebastian/resource-operations      1.0.0   Provides a list of PHP built-in functions that operate on resources
sebastian/version                  2.0.1   Library that helps with managing the version number of Git-hosted PHP projects
seld/cli-prompt                    1.0.3   Allows you to prompt for user input on the command line, and optionally hide the characters they type
seld/jsonlint                      1.6.0   JSON Linter
seld/phar-utils                    1.0.1   PHAR file format utilities, for when PHP phars you up
stecman/symfony-console-completion 0.7.0   Automatic BASH completion for Symfony Console Component based applications.
symfony/browser-kit                v3.3.2  Symfony BrowserKit Component
symfony/config                     v2.8.22 Symfony Config Component
symfony/console                    v2.8.22 Symfony Console Component
symfony/css-selector               v3.3.2  Symfony CssSelector Component
symfony/debug                      v2.8.22 Symfony Debug Component
symfony/dependency-injection       v2.8.22 Symfony DependencyInjection Component
symfony/dom-crawler                v3.3.2  Symfony DomCrawler Component
symfony/event-dispatcher           v2.8.22 Symfony EventDispatcher Component
symfony/filesystem                 v2.8.22 Symfony Filesystem Component
symfony/finder                     v2.8.22 Symfony Finder Component
symfony/polyfill-mbstring          v1.3.0  Symfony polyfill for the Mbstring extension
symfony/process                    v2.8.22 Symfony Process Component
symfony/translation                v2.8.22 Symfony Translation Component
symfony/yaml                       v2.8.22 Symfony Yaml Component
theseer/tokenizer                  1.1.0   A small library for converting tokenized PHP source code into XML and potentially other formats
webmozart/assert                   1.2.0   Assertions to validate method input/output with nice error messages.
wp-cli/php-cli-tools               v0.11.2 Console utilities for PHP
wp-cli/wp-cli                      v1.1.0  A command line interface for WordPress
xamin/handlebars.php               v0.10.4 Handlebars processor for php
truckee commented 7 years ago

It would be nice to know whether the failure is due to an error of configuration or in the code. All I've been able to demonstrate so far is that the failure is independent of OS (Ubuntu or Windows), running from command line or in Netbeans. It is certainly true that if tables are defined in the test database they are dropped before this error is thrown.

lucatume commented 7 years ago

Thanks for reporting the issue,

could you post the configuration file of the suite you are using? How did you generate the SQL dump file?

site and blogs are multisite installation tables; WPDb will try to replace the hard-coded site URL that's in the database dump with the one defined in its configuration, those are just messages and not errors.

FreekVR commented 7 years ago

Having the same issue, since after updating wp-browser this is now broken, but used to work fine before.

Here's an example config we're using for a functional test suite.

# Codeception Test Suite Configuration

# Suite for WordPress functional tests.
# Emulate web requests and make the WordPress application process them.

class_name: FunctionalTester
modules:
    enabled:
        - \Helper\Functional
        - Filesystem
        - WPDb
        - WordPress
    config:
        WPDb:
            dsn: "mysql:host=mysql;dbname=foobar_test"
            user: root
            password: ""
            dump: tests/_data/dump.sql
            populate: true
            cleanup: true
            reconnect: true
            url: 'http://foobar.dev'
            urlReplacement: true
            tablePrefix: wp_
        WordPress:
            depends: WPDb
            wpRootFolder: public
            adminUsername: admin
            adminPassword: test
truckee commented 7 years ago

functional.suite.yml:

actor: FunctionalTester
modules:
    enabled:
        - WPDb
        - WordPress
        - Asserts
        - \Helper\Functional
    config:
        WPDb:
            dsn: 'mysql:host=localhost;dbname=wptests'
            user: 'root'
            password: '********'
            dump: 'tests/_data/dump.sql'
            populate: true
            cleanup: true
            url: 'http://uufnn'
            urlReplacement: true
            tablePrefix: 'wp_'
        WordPress:
            depends: WPDb
            wpRootFolder: 'G:/Documents/workspace/uufnn'
            adminUsername: 'gbrooks'
            adminPassword: '********'
            adminPath: '/wp-admin'

Ubuntu environment is similar

I've tried two different dump files. One was a dump from an existing WordPress sandbox with siteurl and home fields modified to match the test environment. The other was just the structure from the sandbox site.

lucatume commented 7 years ago

I've not forgotten the issue but I'm having issues with my working machine and cannot code really efficiently. I will get back on this as soon as possible. Thanks for your feedback.

truckee commented 7 years ago

No worries. Glad I'm not the only one to whom "issues" happen!

lucatume commented 7 years ago

I've got a branch out that might fix the issue, could you try pulling it using:

composer require --dev lucatume/wp-browser:dev-wpdb-sql-dump-fix
truckee commented 7 years ago

Here's the result of the command .\vendor\bin\codecept run functional:

Stack trace:
#0 G:\Documents\workspace\uufnn\wp-includes\wp-db.php(658): wpdb->db_connect()
#1 G:\Documents\workspace\uufnn\wp-includes\load.php(404): wpdb->__construct('root', '********', 'uufnn-wp', '127.0.0.1')
#2 G:\Documents\workspace\uufnn\wp-settings.php(106): require_wp_db()
#3 G:\Documents\workspace\uufnn\wp-config.php(90): require_once('G:\\Documents\\wo...')
#4 G:\Documents\workspace\uufnn\wp-load.php(37): require_once('G:\\Documents\\wo...')
#5 G:\Documents\workspace\uufnn\wp-blog-header.php(13): require_once('G:\\Documents\\wo...')
#6 G:\Documents\workspace\uufnn\index.php(17): require('G:\\Documents\\wo...')
#7 G:\Documents\workspace\uufnn\wp-content\plugins\rma\vendor\lucatume\wp-browser\src\tad\scripts\request.php(29): include('G:\\Documents\\wo...')
#8 {main}
  thrown in G:\Documents\workspace\uufnn\wp-includes\wp-db.php on line 1568

[mysql_connect]...This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0.

Environment is Windows 10 Pro 64-bit, build 1703, PHP 7.1.6, Apache 2.4.25. I imagine by VM will fly with PHP 5.6.

Guess I need to go backwards? Not a fan of going back, especially 'cuz the project is for a site that's on PHP 7.0 now. Please advise.

truckee commented 7 years ago

On VM with PHP 5.5.9, the test hangs. Do you have any suggestions on how to get useful feedback out of this?

lucatume commented 7 years ago

try running the tests with -vvv (activating the maximum level of verbosity) at the end e.g.

vendor/bin/codecept run functional -vvv
truckee commented 7 years ago

On VM, I get screens of:

  Tried to replace WordPress site domain but dump file does not contain a table INSERT instruction for table [blogs].
  Tried to replace WordPress site domain but dump file does not contain a table INSERT instruction for table [site].
lucatume commented 7 years ago

I've pushed a fix that should take care of the excess output on the same branch. The "hanging" of the machine surprises me though: how big is the SQL dump you are trying to load? As per the deprecated error: that's generated from the wp-db.php class but I never got it. Running WordPress on PHP 7.1 yields no error.

truckee commented 7 years ago

The dump is sizable: ~3M. I'll trim it to see what happens when I can get back to this. Off now. I'll let you know how it goes.

lucatume commented 7 years ago

Mmm, ok. The WPDb module, as the Db module it extends, is meant to load small initial dumps. For a dump that size use the populator to go from a PHP based import to a CLI based one: see here.

truckee commented 7 years ago

Pulled the latest, added populator and got this, where the 301 repeats:

$ ./vendor/bin/codecept run functional -vvv
Codeception PHP Testing Framework v2.3.3
Powered by PHPUnit 4.8.35 by Sebastian Bergmann and contributors.

  [Db] Executing Populator: `mysql -u root -h localhost -p******** wpTests < tests/_data/full_site_dump.sql`
  [Db] Populator Finished.
  Rebuilding FunctionalTester...
  [Db] Connected to wpTests
  [Db] Executing Populator: `mysql -u root -h localhost -p******** wpTests < tests/_data/full_site_dump.sql`
  [Db] Populator Finished.

Functional Tests (1) ----------------------------------------------------------------------------------------------------------------------------------------
Modules: WPDb, WordPress, Asserts, \Helper\Functional
-------------------------------------------------------------------------------------------------------------------------------------------------------------
HomePageCept: Check home page
Signature: HomePageCept
Test: tests/functional/HomePageCept.php
Scenario --
 I am on page "/"
  [Cookie Jar] ["wordpress_test_cookie=WP+Cookie+check; path=/; httponly"]
  [Request Headers] []
  [Page] /
  [Response] 301
  [Request Cookies] {"wordpress_test_cookie":"WP Cookie check"}
  [Response Headers] {"Location":"http://rmasite.wp/","Content-type":"text/html; charset=UTF-8","Set-Cookie":["wordpress_test_cookie=WP Cookie check"]}
  [Redirecting to] http://rmasite.wp/
  [Page] http://rmasite.wp/
  [Response] 301
  [Request Cookies] {"wordpress_test_cookie":"WP Cookie check"}
  [Response Headers] {"Location":"http://rmasite.wp/","Content-type":"text/html; charset=UTF-8","Set-Cookie":["wordpress_test_cookie=WP Cookie check"]}
  [Redirecting to] http://rmasite.wp/
  [Page] http://rmasite.wp/
  [Response] 301
...
lucatume commented 7 years ago

Ok, then the database issue is solved. The 301 redirection seems to be a looping redirection issue that's not related to the database issue at hand. To debug this: could you try using the WPBrowser module in place of the WordPress one to visit the page? Without access to the site code and database I have little material to go by.

truckee commented 7 years ago

Ah, but you found the solution. By replacing WordPress with WPBrowser and its configuration I get (with much gratitude!):

$ ./vendor/bin/codecept run functional
Codeception PHP Testing Framework v2.3.3
Powered by PHPUnit 4.8.35 by Sebastian Bergmann and contributors.

Functional Tests (1) ----------------------------------------------------------------------------------------------------------------------------------------
✔ HomePageCept: Check home page (0.11s)
-------------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 859 ms, Memory: 24.75MB

OK (1 test, 1 assertion)
lucatume commented 7 years ago

You are more than welcome but I fear we just found another bug. That 301 loop is a WordPress module bug I'm tracking in a separate issue (https://github.com/lucatume/wp-browser/issues/85)

Thanks for reporting the issue (the original one and the new one) and the patience.

Closing this.