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

Examples

Fixtures

The bundle's internal tests show several ways to load fixtures:

Unit test

<?php

declare(strict_types=1);

namespace Liip\FooBundle\Tests;

use AlexisLefebvre\TestBundle\Controller\DefaultController;
use AlexisLefebvre\TestBundle\Test\WebTestCase;

class ExampleUnitTest extends WebTestCase
{
    /**
     * Example using LiipFunctionalBundle the service mock builder.
     */
    public function testIndexAction(): void
    {
        $view = $this->getServiceMockBuilder('FooView')->getMock();

        $view->expects($this->once())
            ->method('setTemplate')
            ->with('FooBundle:Default:index.twig')
            ->will($this->returnValue(null))
        ;

        $view->expects($this->once())
            ->method('handle')
            ->with()
            ->will($this->returnValue('success'))
        ;

        $controller = new DefaultController($view);

        $this->assertSame('success', $controller->indexAction());
    }
}

Functional test

<?php

declare(strict_types=1);

namespace Liip\FooBundle\Tests;

use AlexisLefebvre\TestBundle\Test\WebTestCase;

class ExampleFunctionalTest extends WebTestCase
{
    /**
     * Example using LiipFunctionalBundle the fixture loader.
     */
    public function testUserFooIndex(): void
    {
        $this->loadFixtures(['Liip\FooBundle\Tests\Fixtures\LoadUserData']);

        $client = $this->createClient();
        $crawler = $client->request('GET', '/users/foo');
        $this->assertStatusCode(200, $client);

        $this->assertTrue($crawler->filter('html:contains("Email: foo@bar.com")')->count() > 0);
    }

    /**
     * Example using LiipFunctionalBundle WebTestCase helpers and with authentication.
     */
    public function testBasicAuthentication(): void
    {
        $this->loadFixtures(['Liip\FooBundle\Tests\Fixtures\LoadUserData']);

        $content = $this->fetchContent('/users/foo', 'GET', true);
        $this->assertSame('Hello foo!', $content);

        // check if the logout button is shown
        $this->assertContains('logout', $content);
    }

    public function test404Page(): void
    {
        $this->fetchContent('/asdasdas', 'GET', false, false);
    }

    public function testLoginPage(): void
    {
        $content = $this->fetchContent('/', 'GET', false);
        $this->assertContains('login', $content);
    }

    public function testValidationErrors(): void
    {
        $client = $this->makeClient(true);
        $crawler = $client->request('GET', '/users/1/edit');

        $client->submit($crawler->selectButton('Save')->form());

        $this->assertValidationErrors(['data.username', 'data.email'], $client->getContainer());
    }
}
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.
bugban/symfony
beyonder-capi/workflow-extensions-bundle
beyonder-capi/job-queue-bundle
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin