GithubHelp home page GithubHelp logo

Comments (8)

stof avatar stof commented on July 4, 2024 1

I don't think this will be easy to do, because Behat does not run inside your Symfony application (and the code being tested with Behat might not be a Symfony application at all).

Maybe https://github.com/FriendsOfBehat/SymfonyExtension could have a way to make it work.

from behat.

tacman avatar tacman commented on July 4, 2024

I poked around the code a bit to find the new calls, but my event listener isn't being called.

<?php

namespace App\EventListener;

use Behat\Testwork\Event\Event;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Behat\Behat\EventDispatcher\Event\StepTested;
final class BehatListener
{
    #[AsEventListener(event: StepTested::BEFORE)]
    public function onBeforeStepTested(Event $event): void
    {
        dd($event);
        // ...
    }

}

The listener seems like it's registered correctly, here's the debug:

"tester.step_tested.before" event
---------------------------------

 ------- ------------------------------------------------------- ---------- 
  Order   Callable                                                Priority  
 ------- ------------------------------------------------------- ---------- 
  #1      App\EventListener\BehatListener::onBeforeStepTested()   0         
 ------- ------------------------------------------------------- ---------- 

from behat.

tacman avatar tacman commented on July 4, 2024

I think I need to implement / extend EventDispatchingStepTester in the FeatureContext.

But EventDispatchingBackgroundTester is marked as final, so it can't be extended.

class FeatureContext extends EventDispatchingBackgroundTester implements Context, BackgroundTester
{

So there must be some other way to wire this up! @everzet? I'll make a PR to the docs once this works.

from behat.

stof avatar stof commented on July 4, 2024

Behat events are not dispatched in the event dispatcher of your Symfony app (which is where you register your listener right now).

See https://docs.behat.org/en/latest/user_guide/context/hooks.html for the documentation about hooks in 3.x

from behat.

stof avatar stof commented on July 4, 2024

making the context implement BackgroundTester does not make sense at all.

from behat.

tacman avatar tacman commented on July 4, 2024

Thanks!

Certainly I'd love to hook it into the Symfony events, and then inject the services I need there. Is there a way to inject the Symfony event dispatcher and dispatch a Symfony event?

I have a custom logger that logs the steps and scenarios, and renders that log via Twig (and needs some other services). I'm open to suggestions on how to implement that, especially inside a bundle so it can be reused.

from behat.

stof avatar stof commented on July 4, 2024

anyway, as this issue was originally asking for documentation and that documentation exists already (see my first comment), I'm closing this issue.

from behat.

tacman avatar tacman commented on July 4, 2024

Thanks, @stof

from behat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.