kubaszymanowski's avatar

Test Laravel package integration

Hi

What I want to do is test my Laravel 5 package. Specifically how it integrates with a actual Laravel app(I already have unit tests).

My idea is:

  • create a tests/Integration directory in my package

  • exclude tests/Integration in phpunit.xml

  • in tests/Integration install a Laravel project, create a simple app and write tests there

  • do not require my package as a Laravel app dependency, instead autoload newest version like this

    "autoload": {
        "psr-4": {
            "MyNamespace\\": "../../src/",
            "App\\": "app/"
        }
    },

With described solution the workflow would be:

  • Run phpunit in main directory

  • Go to tests/Integration

  • Run composer update(for newest version of Laravel and to dump-autoload automatically)

  • Run phpunit there

Do you know a simplier solution? Do you think I should create this Laravel test app as a separate project that requires my package and run the tests completely separately.

If you are concerned about composer pulling my Integration tests(which is a Laravel app) when running composer require my-package, I have solved this by adding tests export-ignore to .gitattributes.

Thanks for any suggestions. Kuba

0 likes
3 replies
ifpingram's avatar

@kubaszymanowski the easiest thing to do, is to leave the tests in your composer package, then import the package into a test Laravel app and then use them from this apps tests using a PHP trait.

Here's an example I put online to test somebody else's package (The Garbage Man package)

https://github.com/ifpingram/laravel-garbage-man-host

https://github.com/ifpingram/laravel-garbage-man-host/blob/master/composer.json

https://github.com/ifpingram/laravel-garbage-man-host/blob/master/tests/PurgeCommandTest.php

HTH!

kubaszymanowski's avatar

Where is this Trait definition? I can't seem to find it. I see you autoload this namespace as:

"psr-4": {
    "Spinen\\GarbageMan\\Testing\\": "vendor/spinen/laravel-garbage-man/tests"
}

But I can't find any traits there. I also see you require "spinen/laravel-garbage-man": "dev-feature/support5.2" but that branch doesn't seem to exist.

Can you enlighten me?

ifpingram's avatar

@kubaszymanowski yes I see what you mean, I've only given you half of the answer - apologies :)

If you are on Larachat Slack Testing channel, give me a shout on there, as it is easier to show you in real time as opposed to via the forum...

Please or to participate in this conversation.