kuri's avatar
Level 12

Adding test to Laravel package

Hi,

I just made a package for Laravel, it allows a model to be favorited by a User. I want to know how to make some tests, so I can implement travis CI when someone else makes a pull request.

The point is I dont know how to make a User model and Another demo model and then make them use my package trait in a test like travis CI.

Any sort of help is highly apreciated.

This is the package: https://github.com/ChristianKuri/laravel-favorite

Reviews are welcome. Thank you.

0 likes
4 replies
ejdelmonico's avatar
Level 53

@kuri Since the package will install in a Laravel project, the tests can use the User model in Laravel. You can just create another model and test with that as well. Just remember the testing paths have to be checked and consider using Orchestral for testing. It was created for testing Laravel packages. Just create your own TestCase class using Orchestral.

use Orchestra\Testbench\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
      public function setUp()
      {
            parent::setUp();
      }
}

1 like
kuri's avatar
Level 12

Thank you @ejdelmonico. Will it be able to implement travis CI? because I want to automate the testing functionality.

Where should I put the model created for testing? what folder structure should I follow?

ejdelmonico's avatar

I use Travis. If you want samples, check out all of Spatie packages on GitHub. Travis just runs your tests when you commit so the fact that you would use Orchestral doesn't matter to Travis.

kuri's avatar
Level 12

@ejdelmonico And to test if the tests and conections are working should I make another branch? or how do I test if its working?

Please or to participate in this conversation.