Jump to content


Photo

Behat/Mink - echo a message to console within a step


  • Please log in to reply
4 replies to this topic

#1 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 10 May 2013 - 10:14 AM

Using behat to run some tests - if I add an echo within a step, or echo in my afterStep() function, I don't get the message until all the steps are done running (so if afterStep() has echo 'test'; at the end I get testtesttestest etc.)

I can't find anything on google about this, I see examples where people are doing an echo within their steps, but I can't get it to work.

Any ideas?
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#2 Mad programmer

Mad programmer

    Member

  • Members
  • PipPip
  • 26 posts

Posted 10 May 2013 - 03:33 PM

Hi Jessica,

I am not familiar with behat, but maybe it uses output buffering internally?
So I'd try to catch the output buffer and end it, after that you echo your content and then reenable the output buffer with that content?



#3 Adam

Adam

    Advanced Member

  • Gurus
  • 5,693 posts
  • LocationSheffield / UK

Posted 10 May 2013 - 04:51 PM

Just curious, why are you wanting to echo from an automated test? By nature they shouldn't fail, except during the initial development or after changes, but in those cases at the end is surely fine?

#4 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 10 May 2013 - 05:20 PM

For a few reasons - one is that one of our steps involves checking an email account to see if the email was recieved. The step automatically waits 30 seconds. However it doesn't output to the screen that it's checking email until after it's passed or failed, so when we are manually running the tests and watching, it sits for 30 seconds with no output. We wanted to add a simple message that says "Waiting for 30 seconds before Checking Email".
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#5 Adam

Adam

    Advanced Member

  • Gurus
  • 5,693 posts
  • LocationSheffield / UK

Posted 13 May 2013 - 05:35 PM

Why do you need to physically send the email? Just mock the mailer and ensure it receives what it should. Otherwise your tests are dependant on some outside system that could fail for reasons completely unrelated to your code, which will screw up the CI environment for no reason. There should be other checks in place to spot issues with the network. Plus, as your test suite grows, you don't want 30 seconds waits dotted around, it will take forever to run them all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com