Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Test Bundle Laravel Package

alexislefebvre/test-bundle

View on GitHub
Deep Wiki
Context7

Query Counter

To catch pages that use way too many database queries, you can enable the query counter for tests. This will check the profiler for each request made in the test using the client, and fail the test if the number of queries executed is larger than the number of queries allowed in the configuration. To enable the query counter, adjust the config_test.yml file like this:

framework:
    # ...
    profiler:
        enabled: true
        collect: true

alexis_lefebvre_test:
    query:
        max_query_count: 50

That will limit each request executed within a functional test to 50 queries.

Maximum Query Count per Test

The default value set in the config file should be reasonable to catch pages with high query counts which are obviously mistakes. There will be cases where you know and accept that the request will cause a large number of queries, or where you want to specifically require the page to execute less than x queries, regardless of the amount set in the configuration. For those cases you can set an annotation on the test method that will override the default maximum for any requests made in that test.

To do that, include the AlexisLefebvre\TestBundle\Annotations\QueryCount namespace and add the [@QueryCount](https://github.com/QueryCount)(100) annotation, where 100 is the maximum amount of queries allowed for each request, like this:

use AlexisLefebvre\TestBundle\Annotations\QueryCount;

class DemoTest extends WebTestCase
{
    /**
     * [@QueryCount](https://github.com/QueryCount)(100)
     */
    public function testDoDemoStuff()
    {
        $client = $this->createClient();
        $crawler = $client->request('GET', '/demoPage');

        $this->assertTrue($crawler->filter('html:contains("Demo")')->count() > 0);
    }
}

Caveats

  • QueryCount annotations currently only work for tests that have a method name of testFooBla() (with a test prefix). The [@test](https://github.com/test) annotation isn't supported at the moment.

  • Enabling the Query Counter currently breaks PHPUnit's built-in annotations, e.g. [@dataProvider](https://github.com/dataProvider), [@depends](https://github.com/depends) etc. To fix this, you need to hide the appropriate PHPUnit annotation from Doctrine's annotation reader using the [@IgnoreAnnotation](https://github.com/IgnoreAnnotation) annotation:

    use AlexisLefebvre\TestBundle\Test\WebTestCase;
    
    /**
     * [@IgnoreAnnotation](https://github.com/IgnoreAnnotation)("dataProvider")
     * [@IgnoreAnnotation](https://github.com/IgnoreAnnotation)("depends")
     */
    class DemoTest extends WebTestCase
    {
        // ...
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware