Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] PHPUnit Fails when new Service Provider is added #42

Closed
raftalks opened this issue Jan 14, 2013 · 12 comments
Closed

[BUG] PHPUnit Fails when new Service Provider is added #42

raftalks opened this issue Jan 14, 2013 · 12 comments

Comments

@raftalks
Copy link
Contributor

I used a fresh L4 install,
generated a workbench package
added the package service provider to config/app.php file under providers key
Then ran phpunit and test is not running.

Then I removed the service provider from the array and phpunit worked.

phpunit_workbench

It seems something wrong with autoloading the extended class Illuminate\Foundation\Testing\TestCase
as if I extend the class with PHPUnit_Framework_TestCase then it does work.

@bencorlett
Copy link
Contributor

Are you able to put ini_set('display_errors', 'On'); on line 2 of vendor/autoload.php and see what happens?

I find I nearly always need to run with error displaying on.

Also, are you running the tests for your application or for the package you're developing??

@raftalks
Copy link
Contributor Author

@bencorlett Thanks to the reply. I did put the display errors on and got the following error. I am running the test for the L4 application (not the package).

Note that Hbt\App\AppServiceProvider is actually a workbench package added to config/app.php file under providers.

As shown in the error, it seems when running the phpunit on L4 root, the workbench service providers are not found when it is trying to load it.

I did test this with a fresh install and creating a new workbench and adding the service provider and same happens.

Rafs-MacBook-Pro:app raf$ phpunit
PHPUnit 3.7.13 by Sebastian Bergmann.

Configuration read from /Users/raf/Sites/hbt2013/app/phpunit.xml


Fatal error: Class 'Hbt\App\AppServiceProvider' not found in /Users/raf/Sites/hbt2013/app/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 123

Call Stack:
    0.0032     230576   1. {main}() /Applications/MAMP/bin/php/php5.4.4/bin/phpunit:0
    0.1873     506072   2. PHPUnit_TextUI_Command::main() /Applications/MAMP/bin/php/php5.4.4/bin/phpunit:46
    0.1874     506304   3. PHPUnit_TextUI_Command->run() /Applications/MAMP/bin/php/php5.4.4/lib/php/PHPUnit/TextUI/Command.php:129
    0.6548    2760976   4. PHPUnit_TextUI_TestRunner->doRun() /Applications/MAMP/bin/php/php5.4.4/lib/php/PHPUnit/TextUI/Command.php:176
    0.6624    3051744   5. PHPUnit_Framework_TestSuite->run() /Applications/MAMP/bin/php/php5.4.4/lib/php/PHPUnit/TextUI/TestRunner.php:346
    0.6625    3053392   6. PHPUnit_Framework_TestSuite->run() /Applications/MAMP/bin/php/php5.4.4/lib/php/PHPUnit/Framework/TestSuite.php:705
    0.6625    3053992   7. PHPUnit_Framework_TestSuite->runTest() /Applications/MAMP/bin/php/php5.4.4/lib/php/PHPUnit/Framework/TestSuite.php:745
    0.6625    3054024   8. PHPUnit_Framework_TestCase->run() /Applications/MAMP/bin/php/php5.4.4/lib/php/PHPUnit/Framework/TestSuite.php:775
    0.6626    3055208   9. PHPUnit_Framework_TestResult->run() /Applications/MAMP/bin/php/php5.4.4/lib/php/PHPUnit/Framework/TestCase.php:769
    0.7245    3112248  10. PHPUnit_Framework_TestCase->runBare() /Applications/MAMP/bin/php/php5.4.4/lib/php/PHPUnit/Framework/TestResult.php:648
    0.7248    3130952  11. Illuminate\Foundation\Testing\TestCase->setUp() /Applications/MAMP/bin/php/php5.4.4/lib/php/PHPUnit/Framework/TestCase.php:821
    0.7248    3130984  12. Illuminate\Foundation\Testing\TestCase->refreshApplication() /Users/raf/Sites/hbt2013/app/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:28
    0.7248    3131064  13. TestCase->createApplication() /Users/raf/Sites/hbt2013/app/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:38
    0.7420    3135032  14. require('/Users/raf/Sites/hbt2013/app/start.php') /Users/raf/Sites/hbt2013/app/app/tests/TestCase.php:16
    0.9680    3931720  15. require('/Users/raf/Sites/hbt2013/app/vendor/laravel/framework/src/Illuminate/Foundation/start.php') /Users/raf/Sites/hbt2013/app/start.php:59
    1.0593    4208960  16. Illuminate\Foundation\ProviderRepository->load() /Users/raf/Sites/hbt2013/app/vendor/laravel/framework/src/Illuminate/Foundation/start.php:184
    1.4583    5041256  17. Illuminate\Foundation\ProviderRepository->createProvider() /Users/raf/Sites/hbt2013/app/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:67


@joecwallace
Copy link
Contributor

I'm having this same issue. It looks like Illuminate\Workbench\Starter::start() should be getting called and isn't.

But that's partly a guess. I can look into this and confirm later tonight, hopefully.

@joecwallace
Copy link
Contributor

I believe I was right.

The workbench autoloads are registered in public/index.php and artisan, but that leaves out the case of unit tests.

For now, a workaround is to create app/config/testing/app.php and fill it with the 'providers'array, leaving off your workbench service provider(s). Then write your tests for those modules in the workbench/{vendor}/{package}/tests directory.

@jasonlewis
Copy link
Contributor

Yeah that sounds about right @joecwallace. You might be able to add your workbench packages vendor/autoload.php in the files key of your applications composer.json

{
    "autoload": {
        "files": ["workbench/<vendor>/<package>/vendor/autoload.php"]
    }
}

Still... not ideal.

@raftalks
Copy link
Contributor Author

Thanks @joecwallace and @jasonlewis for the suggestions, and hopefully we can see what @taylorotwell has to say about this issue.

@joecwallace
Copy link
Contributor

I've thought of a better way to fix this. In app/tests/TestCase.php change the createApplication() method to something like this:

    public function createApplication()
    {
        $unitTesting = true;

        $testEnvironment = 'testing';

        $basePath = __DIR__.'/../..';

        Illuminate\Workbench\Starter::start($basePath.'/workbench');

        return require $basePath.'/start.php';
    }

Cleaner than redefining the providers array.

UPDATE: I submitted this fix as a pull request on laravel / laravel

@jasonlewis
Copy link
Contributor

Ah good one Joe! Much better alternative.
On Jan 16, 2013 8:56 AM, "Joe Wallace" [email protected] wrote:

I've thought of a better way to fix this. In app/tests/TestCase.phpchange the
createApplication() method to something like this:

public function createApplication()
{
    $unitTesting = true;

    $testEnvironment = 'testing';

    $basePath = __DIR__.'/../..';

    Illuminate\Workbench\Starter::start($basePath.'/workbench');

    return require $basePath.'/start.php';
}

Cleaner than redefining the providers array.


Reply to this email directly or view it on GitHubhttps://github.com//issues/42#issuecomment-12291594.

@raftalks
Copy link
Contributor Author

@joecwallace thanks, finally this looks like the solution we need.

@raftalks
Copy link
Contributor Author

Should this PR be merged to solve this issue? laravel/laravel#1608

@bencorlett
Copy link
Contributor

Yes

Sent from my iPad
Please excuse my brevity

On 21/01/2013, at 5:21 AM, Raf [email protected] wrote:

Should this PR be merged to solve this issue? laravel/laravel#1608


Reply to this email directly or view it on GitHub.

@taylorotwell
Copy link
Member

This has been fixed.

joelharkes pushed a commit to joelharkes/framework_old that referenced this issue Mar 7, 2019
Add console command to create oauth clients for organizations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants