PHP Fatal error: Cannot redeclare class App (in _ide_helper.php) #3990

Closed
timbroder opened this Issue Feb 3, 2017 · 9 comments

Comments

Projects
None yet
4 participants
@timbroder
Contributor

timbroder commented Feb 3, 2017

What are you trying to achieve?

Run my first unit test

What do you get instead?

Provide console output if related. Use -vvv mode for more details.

composer exec codecept run unit usa_invoice_report.feature -vvv
Reading ./composer.json
Loading config file /Users/timbroder/.composer/config.json
Loading config file /Users/timbroder/.composer/auth.json
Loading config file ./composer.json
Checked CA file /private/etc/ssl/cert.pem: valid
Executing command (/Users/timbroder/workspace/kidfund/web): git branch --no-color --no-abbrev -v
Reading /Users/timbroder/.composer/composer.json
Loading config file /Users/timbroder/.composer/config.json
Loading config file /Users/timbroder/.composer/auth.json
Loading config file /Users/timbroder/.composer/composer.json
Loading config file /Users/timbroder/.composer/auth.json
Reading /Users/timbroder/.composer/auth.json
Reading /Users/timbroder/workspace/kidfund/web/vendor/composer/installed.json
Reading /Users/timbroder/.composer/vendor/composer/installed.json
Running 1.3.2 (2017-01-27 18:23:41) with PHP 5.6.29 on Darwin / 16.3.0
> __exec_command: codecept 'run' 'unit' 'usa_invoice_report.feature'
Executing command (CWD): codecept 'run' 'unit' 'usa_invoice_report.feature'
Codeception PHP Testing Framework v2.2.8
Powered by PHPUnit 4.8.27 by Sebastian Bergmann and contributors.

Unit Tests (1) ---------------------------------------------------------------
- First Feature: First ScenarioPHP Fatal error:  Cannot redeclare class App in /Users/timbroder/workspace/kidfund/web/_ide_helper.php on line 1096
PHP Fatal error:  Cannot mix bracketed namespace declarations with unbracketed namespace declarations in /Users/timbroder/workspace/kidfund/web/vendor/symfony/debug/Exception/FatalErrorException.php on line 12

Provide test source code if related

public function firstScenario()
    {
        print("HI");
    }

At the top of my _ide_helper.php file, there is an exit that doesn't seem to process with codeception. This file should be ignored

/**
 * A helper file for Laravel 5, to provide autocomplete information to your IDE
 * Generated for Laravel 5.2.45 on 2017-02-03.
 *
 * @author Barry vd. Heuvel <barryvdh@gmail.com>
 * @see https://github.com/barryvdh/laravel-ide-helper
 */

namespace {
    exit("This file should not be included, only analyzed by your IDE");

    class App extends \Illuminate\Support\Facades\App{

Details

  • Codeception version: 2.2.8
  • PHP Version: 5.6.29
  • Operating System: macOS 10.12.2 (16C68)
  • Installation type: Composer
  • List of installed packages (composer show)
aws/aws-sdk-php                       3.19.3                                  AWS SDK for PHP - Use Amazon Web Services in your PHP project
barryvdh/laravel-debugbar             V2.2.3                                  PHP Debugbar integration for Laravel
barryvdh/laravel-ide-helper           v2.2.3                                  Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.
barryvdh/reflection-docblock          v2.0.4                                  
behat/behat                           dev-master 762a074                      Scenario-oriented BDD framework for PHP 5.3
behat/gherkin                         v4.4.1                                  Gherkin DSL parser for PHP 5.3
behat/mink                            dev-master a88582e                      Browser controller/emulator abstraction for PHP
behat/mink-browserkit-driver          v1.3.2                                  Symfony2 BrowserKit driver for Mink framework
behat/mink-extension                  dev-master 694c9ee                      Mink extension for Behat
behat/transliterator                  v1.1.0                                  String transliterator
ckeditor/ckeditor                     4.5.10                                  JavaScript WYSIWYG web text editor.
classpreloader/classpreloader         3.0.0                                   Helps class loading performance by generating a single PHP file containing all of the autoloaded files for a specific ...
codeception/codeception               2.2.8                                   BDD-style testing framework
container-interop/container-interop   1.1.0                                   Promoting the interoperability of container objects (DIC, SL, etc.)
davibennun/laravel-push-notification  dev-community 87ba388                   Laravel package to send push notifications to mobile devices (apns, gcm)
dingo/api                             dev-master cac67ab                      A RESTful API package for the Laravel and Lumen frameworks.
dingo/blueprint                       dev-master d37fb74                      API Blueprint documentation generator.
dnoegel/php-xdg-base-dir              0.1                                     implementation of xdg base directory specification for php
doctrine/annotations                  v1.2.7                                  Docblock Annotations Parser
doctrine/cache                        v1.6.0                                  Caching library offering an object-oriented API for many cache backends
doctrine/collections                  v1.3.0                                  Collections Abstraction library
doctrine/common                       v2.6.1                                  Common Library for Doctrine projects
doctrine/dbal                         v2.5.4                                  Database Abstraction Layer
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
doctrine/lexer                        v1.0.1                                  Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
drewm/mailchimp-api                   v2.2.4                                  Super-simple, minimum abstraction MailChimp API v3 wrapper
dwolla/dwollaswagger                  1.0.11                                  
facebook/webdriver                    1.3.0                                   A PHP client for WebDriver
frozennode/administrator              dev-community 3c4d0f5                   A database interface package for Laravel
fzaninotto/faker                      v1.6.0                                  Faker is a PHP library that generates fake data for you.
guzzlehttp/guzzle                     6.2.1                                   Guzzle is a PHP HTTP client library
guzzlehttp/oauth-subscriber           0.3.0                                   Guzzle OAuth 1.0 subscriber
guzzlehttp/promises                   1.2.0                                   Guzzle promises library
guzzlehttp/psr7                       1.3.1                                   PSR-7 message implementation
hamcrest/hamcrest-php                 v1.2.2                                  This is the PHP port of Hamcrest Matchers
jakub-onderka/php-console-color       0.1                                     
jakub-onderka/php-console-highlighter v0.3.2                                  
jeremeamia/SuperClosure               2.2.0                                   Serialize Closure objects, including their context and binding
jeroen-g/laravel-packager             dev-master 836b2d0                      A cli tool for creating Laravel packages.
joselfonseca/laravel-tactician        0.3.2                                   Laravel implementation of the Tactician Command Bus
laracasts/behat-laravel-extension     dev-community e4b0164                   Laravel extension for Behat
laracasts/flash                       2.0.1                                   Easy flash notifications
laracasts/generators                  1.1.3                                   Extend Laravel 5's generators.
laravel/framework                     v5.2.45                                 The Laravel Framework.
league/flysystem                      1.0.27                                  Filesystem abstraction: Many filesystems, one API.
league/fractal                        0.14.0                                  Handle the output of complex data structures ready for API output.
league/tactician                      v1.0.2                                  A small, flexible command bus. Handy for building service layers.
mandrill/mandrill                     1.0.55                                  API client library for the Mandrill email as a service platform
maximebf/debugbar                     v1.12.0                                 Debug bar in the browser for php application
mockery/mockery                       0.9.5                                   Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other ...
monolog/monolog                       1.21.0                                  Sends your logs to files, sockets, inboxes, databases and various web services
mtdowling/cron-expression             v1.1.0                                  CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
mtdowling/jmespath.php                2.3.0                                   Declaratively specify how to extract elements from a JSON document
namshi/cuzzle                         2.0.2                                   Get the cURL shell command from a Guzzle request
namshi/jose                           5.0.2                                   JSON Object Signing and Encryption library for PHP.
nathanmac/parser                      v3.11                                   Simple PHP Parser Utility Library for API Development
nesbot/carbon                         1.21.0                                  A simple API extension for DateTime.
nikic/php-parser                      v2.1.0                                  A PHP parser written in PHP
paragonie/random_compat               v1.4.1                                  PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
phpdocumentor/reflection-common       1.0                                     Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock     3.1.0                                   With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information tha...
phpdocumentor/type-resolver           0.2                                     
phpseclib/phpseclib                   0.3.10                                  PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.
phpspec/prophecy                      v1.6.1                                  Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage             2.2.4                                   Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator             1.4.1                                   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.8                                   Utility class for timing
phpunit/php-token-stream              1.4.8                                   Wrapper around PHP's tokenizer extension.
phpunit/phpunit                       4.8.27                                  The PHP Unit Testing framework.
phpunit/phpunit-mock-objects          2.3.8                                   Mock Object library for PHPUnit
predis/predis                         v1.1.1                                  Flexible and feature-complete Redis client for PHP and HHVM
psr/http-message                      1.0.1                                   Common interface for HTTP messages
psr/log                               1.0.0                                   Common interface for logging libraries
psy/psysh                             v0.7.2                                  An interactive shell for modern PHP.
sebastian/comparator                  1.2.0                                   Provides the functionality to compare PHP values for equality
sebastian/diff                        1.4.1                                   Diff implementation
sebastian/environment                 1.3.8                                   Provides functionality to handle HHVM/PHP environments
sebastian/exporter                    1.2.2                                   Provides the functionality to export PHP variables for visualization
sebastian/global-state                1.1.1                                   Snapshotting of global state
sebastian/recursion-context           1.0.2                                   Provides functionality to recursively process PHP variables
sebastian/version                     1.0.6                                   Library that helps with managing the version number of Git-hosted PHP projects
sentry/sentry                         0.22.0                                  A PHP client for Sentry (http://getsentry.com)
sly/notification-pusher               v2.2.12                                 Standalone PHP library for easy devices notifications push.
spatie/laravel-newsletter             3.1.0                                   Manage newsletters in Laravel 5
swiftmailer/swiftmailer               v5.4.3                                  Swiftmailer, free feature-rich PHP mailer
symfony/browser-kit                   v3.1.3                                  Symfony BrowserKit Component
symfony/class-loader                  v3.1.3                                  Symfony ClassLoader Component
symfony/config                        v3.1.3                                  Symfony Config Component
symfony/console                       v2.8.9                                  Symfony Console Component
symfony/css-selector                  v3.0.9                                  Symfony CssSelector Component
symfony/debug                         v3.0.9                                  Symfony Debug Component
symfony/dependency-injection          v3.1.3                                  Symfony DependencyInjection Component
symfony/dom-crawler                   v3.0.9                                  Symfony DomCrawler Component
symfony/event-dispatcher              v3.1.3                                  Symfony EventDispatcher Component
symfony/filesystem                    v3.1.3                                  Symfony Filesystem Component
symfony/finder                        v3.0.9                                  Symfony Finder Component
symfony/http-foundation               v3.0.9                                  Symfony HttpFoundation Component
symfony/http-kernel                   v3.0.9                                  Symfony HttpKernel Component
symfony/options-resolver              v2.8.9                                  Symfony OptionsResolver Component
symfony/polyfill-mbstring             v1.2.0                                  Symfony polyfill for the Mbstring extension
symfony/polyfill-php56                v1.2.0                                  Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-util                 v1.2.0                                  Symfony utilities for portability of PHP codes
symfony/process                       v2.8.9                                  Symfony Process Component
symfony/routing                       v3.0.9                                  Symfony Routing Component
symfony/translation                   v3.0.9                                  Symfony Translation Component
symfony/var-dumper                    v3.0.9                                  Symfony mechanism for exploring and dumping PHP variables
symfony/yaml                          v3.1.3                                  Symfony Yaml Component
twineis/raven-php                     0.2.0                                   Sentry (Raven) error monitoring for Laravel and Lumen with send in background via queues
tymon/jwt-auth                        0.5.9                                   JSON Web Token Authentication for Laravel 4 and 5
venturecraft/revisionable             1.28.0                                  Keep a revision history for your models without thinking, created as a package for use with Laravel
vlucas/phpdotenv                      v2.4.0                                  Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.
way/generators                        dev-feature/laravel-five-stable a358bb4 Rapidly generate resources, migrations, models, and much more.
weblee/mandrill                       dev-master 809dedb                      Laravel 5 Mandrill API Wrapper
webmozart/assert                      1.1.0                                   Assertions to validate method input/output with nice error messages.
webpatser/laravel-uuid                2.0.1                                   Class to generate a UUID according to the RFC 4122 standard. Support for version 1, 3, 4 and 5 UUID are built-in.
xethron/migrations-generator          dev-l5 e5e86ef                          Generates Laravel Migrations from an existing database
zendframework/zend-escaper            2.5.2                                   
zendframework/zend-http               2.5.5                                   provides an easy interface for performing Hyper-Text Transfer Protocol (HTTP) requests
zendframework/zend-json               2.6.1                                   provides convenience methods for serializing native PHP to JSON and decoding JSON to native PHP
zendframework/zend-loader             2.5.1                                   
zendframework/zend-stdlib             3.0.1                                   
zendframework/zend-uri                2.5.2                                   a component that aids in manipulating and validating » Uniform Resource Identifiers (URIs)
zendframework/zend-validator          2.8.1                                   provides a set of commonly needed validators
zendframework/zendservice-apple-apns  1.2.0                                   OOP Zend Framework 2 wrapper for Apple Push Notification Service
zendframework/zendservice-google-gcm  1.0.3                                   OOP wrapper for Google Cloud Messaging
  • Suite configuration:

codeception.yml

actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
extensions:
    enabled:
        - Codeception\Extension\RunFailed
modules:
    config:
        Db:
            dsn: ''
            user: ''
            password: ''
            dump: tests/_data/dump.sql
        Laravel5:
            environment_file: .env.phpunit
            run_database_migrations: true
            cleanup: true

unit.suite.yml

# Codeception Test Suite Configuration
#
# Suite for unit (internal) tests.

class_name: UnitTester
modules:
    enabled:
        - Laravel5:
          cleanup: false # can't wrap into transaction
        - Asserts
        - \Helper\Unit
@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Feb 3, 2017

Member

It looks like an issue of your application code.

Member

Naktibalda commented Feb 3, 2017

It looks like an issue of your application code.

@timbroder

This comment has been minimized.

Show comment
Hide comment
@timbroder

timbroder Feb 3, 2017

Contributor

@Naktibalda is there a way I can tell codeception to ignore that file?

If I remove it, it runs fine

Contributor

timbroder commented Feb 3, 2017

@Naktibalda is there a way I can tell codeception to ignore that file?

If I remove it, it runs fine

@DavertMik DavertMik added the Laravel5 label Feb 3, 2017

@timbroder timbroder referenced this issue in barryvdh/laravel-ide-helper Feb 3, 2017

Closed

Fatal Error running with codeception #440

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Feb 3, 2017

Member

The question is why in hell this file is being loaded. I promise you, Codeception doesn't scan your directories for all possible PHP files to load them. Maybe it is loaded by Composer?

Could you run the Codeception directly:

./vendor/bin/codecept run
Member

DavertMik commented Feb 3, 2017

The question is why in hell this file is being loaded. I promise you, Codeception doesn't scan your directories for all possible PHP files to load them. Maybe it is loaded by Composer?

Could you run the Codeception directly:

./vendor/bin/codecept run
@timbroder

This comment has been minimized.

Show comment
Hide comment
@timbroder

timbroder Feb 3, 2017

Contributor

That didn't fix it but I was able to track it down

What happened:

My Laravel migrator was set up with run_database_migrations: true but I had not specified database_migrations_path and it looks like this defaults to the root of the project, where laravel was scooping up *.php file to see if it contained a migration

I think that the default of database_migrations_path should be database/migrations where Laravel defaults it to

What do you think? I can open a PR with that

Contributor

timbroder commented Feb 3, 2017

That didn't fix it but I was able to track it down

What happened:

My Laravel migrator was set up with run_database_migrations: true but I had not specified database_migrations_path and it looks like this defaults to the root of the project, where laravel was scooping up *.php file to see if it contained a migration

I think that the default of database_migrations_path should be database/migrations where Laravel defaults it to

What do you think? I can open a PR with that

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Feb 3, 2017

Member

Wow, yes. Looks like a bug! Executing all PHP files is total nonsense.
Thanks for tracking, yes, send a PR

Member

DavertMik commented Feb 3, 2017

Wow, yes. Looks like a bug! Executing all PHP files is total nonsense.
Thanks for tracking, yes, send a PR

@janhenkgerritsen

This comment has been minimized.

Show comment
Hide comment
@janhenkgerritsen

janhenkgerritsen Feb 4, 2017

Contributor

The reason I left the default value for the database_migrations_path config variable as an empty string is that this will result in the default Laravel migration path due to this code.

However, it seems this code was only added for the 5.3 release of Laravel with this commit.

From the details you specified with your issue I can see you are using Laravel 5.2, and in Laravel 5.2 and before this check is used to determine the path.

So I think the easiest fix for this problem is to set the default value for the database_migrations_path config variable to null instead of an empty string. Can you try this out and let me know if this solution fixes your problem?

Contributor

janhenkgerritsen commented Feb 4, 2017

The reason I left the default value for the database_migrations_path config variable as an empty string is that this will result in the default Laravel migration path due to this code.

However, it seems this code was only added for the 5.3 release of Laravel with this commit.

From the details you specified with your issue I can see you are using Laravel 5.2, and in Laravel 5.2 and before this check is used to determine the path.

So I think the easiest fix for this problem is to set the default value for the database_migrations_path config variable to null instead of an empty string. Can you try this out and let me know if this solution fixes your problem?

@timbroder

This comment has been minimized.

Show comment
Hide comment
@timbroder

timbroder Feb 6, 2017

Contributor

@janhenkgerritsen sorry I saw the other thread before this one. Yes, changing the default to null fixes it.

I'll update the PR

Contributor

timbroder commented Feb 6, 2017

@janhenkgerritsen sorry I saw the other thread before this one. Yes, changing the default to null fixes it.

I'll update the PR

timbroder added a commit to timbroder/Codeception that referenced this issue Feb 6, 2017

@timbroder

This comment has been minimized.

Show comment
Hide comment
@timbroder

timbroder Feb 6, 2017

Contributor

@janhenkgerritsen PR #3991 updated with your suggestion

Contributor

timbroder commented Feb 6, 2017

@janhenkgerritsen PR #3991 updated with your suggestion

@janhenkgerritsen

This comment has been minimized.

Show comment
Hide comment
@janhenkgerritsen

janhenkgerritsen Feb 6, 2017

Contributor

I just merged your PR. Thanks for taking the time to investigate this issue and submitting a PR.

Contributor

janhenkgerritsen commented Feb 6, 2017

I just merged your PR. Thanks for taking the time to investigate this issue and submitting a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment