S
S
Sergey2020-01-25 16:44:37
Laravel
Sergey, 2020-01-25 16:44:37

How to test a new Laravel package?

Wrote a package with a new notification channel for Laravel. I want to send to the appropriate community . But among other requirements, the package must be covered by tests. And here for me a stupor - how to do it right? Searched the Internet, found nothing; it's all about unit testing a regular application on Laravel, but it's a standalone package... In general, I don't even know which side to approach. How to write a package test? Even, corny, how to use artisan in a package?
I would be grateful for links and answers!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2020-01-27
@SVZhidkow

I found the answer to my own question.
The most basic is the settings of the phpunit.xml file. You can take the most standard from Laravel.
But here it is important to specify the directory where the tests are located. If the tests folder is at the root, then:

<testsuites>
    <testsuite name="Feature">
        <directory>tests</directory>
    </testsuite>
</testsuites>

The tests contain the usual Laravel unit tests
. Also, do not forget to specify where the package files themselves are located. Usually it is /src:
<filter>
    <whitelist processUncoveredFilesFromWhitelist="true">
        <directory suffix=".php">src/</directory>
    </whitelist>
</filter>

Further, if necessary, we execute composer update.
And we run the unit tests in the standard way through the terminal, as in the documentation phpunit, or, most likely,vendor\bin\phpunit

J
JhaoDa, 2020-01-25
@JhaoDa

Open any package from this community and see how it's done there. What prevented you from doing this?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question