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

Common Contexts Laravel Package

behat/common-contexts

Abandoned Behat 2.x add-on providing reusable subcontexts with extra steps/hooks. Includes contexts like SymfonyMailerContext, DoctrineFixturesContext, and SymfonyDoctrineContext for loading fixtures, purging DB, and resetting schema in Symfony-based suites.

View on GitHub
Deep Wiki
Context7

THIS PROJECT IS ABANDONED

This project (which was never updated for Behat 3.x) is abandoned and will not receive further updates.

Extra Contexts for Behat 2.x

This additional contexts could be used as your feature suite's submodules, giving you extra steps and hooks right out of the box.

How to use them

To use those contexts, you should simply instantiate them with needed arguments (see constructor arguments) and pass them into useContext() function like that:

<?php

namespace Acme\DemoBundle\Features\Context;

use Behat\Behat\Context\BehatContext;
use Behat\CommonContexts\SymfonyMailerContext;
use Behat\CommonContexts\DoctrineFixturesContext;

/**
 * Feature context.
 */
class FeatureContext extends BehatContext
{
    public function __construct()
    {
        // To use SymfonyMailerContext in your steps
        $this->useContext('symfony_extra', new SymfonyMailerContext());

        // To use DoctrineFixturesContext in your steps
        $this->useContext('doctrine_fixtures_context', new DoctrineFixturesContext());
    }

    /**
     * Example of using DoctrineFixturesContext in BeforeScenario hook
     *
     * @BeforeScenario
     */
    public function beforeScen()
    {
        $loader = new Loader();

        $this->getMainContext()
            ->getSubcontext('doctrine_fixtures_context')
            ->loadFixtureClasses($loader, array(
                'Acme\Bundle\DefaultBundle\DataFixtures\ORM\LoadNewsData',
                'Acme\Bundle\DefaultBundle\DataFixtures\ORM\LoadPagesData',
                'Acme\Bundle\DefaultBundle\DataFixtures\ORM\LoadReviewData',
                'Acme\Bundle\DefaultBundle\DataFixtures\ORM\LoadTicketData',
            ));

        /** @var $em \Doctrine\ORM\EntityManager */
        $em = $this->kernel->getContainer()->get('doctrine.orm.entity_manager');

        $purger = new ORMPurger();
        $executor = new ORMExecutor($em, $purger);
        $executor->purge();
        $executor->execute($loader->getFixtures(), true);
    }
}

Example: Using SymfonyDoctrineContext to reset Doctrine

database schema in Symfony framework before scenario starts

<?php

namespace Acme\DemoBundle\Features\Context;

use Behat\Behat\Context\BehatContext;
use Behat\CommonContexts\SymfonyDoctrineContext;

/**
 * Feature context.
 */
class FeatureContext extends BehatContext
{
    public function __construct()
    {
        // Connects SymfonyDoctrineContext
        $this->useContext('symfony_doctrine_context',  new SymfonyDoctrineContext);
    }

    /**
     * Clean database before scenario starts
     *
     * @BeforeScenario
     */
    public function beforeScenario($event)
    {
        // Asks subcontext SymfonyDoctrineContext to rebuild database schema
        $this
            ->getMainContext()
            ->getSubcontext('symfony_doctrine_context')
            ->buildSchema($event);
    }
}

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.
datacore/hub-sdk
alengo/sulu-http-cache-bundle
croct/coding-standard
croct/plug-php
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php
trappistes/laravel-custom-fields