Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6615811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:30:29+00:00 2026-05-25T20:30:29+00:00

I’m just starting with BDD and this instructions about Behat but I’m missing an

  • 0

I’m just starting with BDD and this instructions about Behat but I’m missing an example a bit more complex, Product-Category example is too simple (but
necessary at first of course..) when you want to go beyond..

I’m working with models that doesn’t have a unique field in order to
do this:

$product = this->getRepository('AcmeDemoBundle:Product')->findOneByName($productName);

In my case I have a relation 1:1:

Room
  hotel_id
  ...

Default configuration
  room_id
  name    //"single room", "double room"...
  price
  ...

So, when I want to create the scenario “Scenario: A room has a default
configuration” I’d like to start this way:

I have a room XXX

but I can’t because I don’t have any field like “name” or any other
that is unique, so I just write:

I have a room

The problem comes when I want to retrieve the room to add a default
configuration like in the example Product-Category ($product = $this->getRepository(‘AcmeDemoBundle:Product’)->findOneByName($productName);), I don’t know what to do.., how to retrieve the room object I’m using to add a default configuration? or how to retrieve the default configuration object?

So, any idea how should I act?

EDIT:

After the response of everzet I want to add the scenario I’m interested in implement:

When I add a default configuration to a room
Then I should find a room has a default configuration

Maybe this scenario sounds strange, but as I said above, I don’t have a unique field in neither in Room nor in Default Configuration.

So, what should be the functions in my .feature file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:30:29+00:00Added an answer on May 25, 2026 at 8:30 pm

    All your scenario step definitions run inside single context class instance and every scenario has it’s own context instance. It means, that you can set ivars on the current context in one step definition and read it’s value in next step definition. It’s even described in the Behat documentation 😉

    In your case, your I have a room step could save last persisted record id into context ivar and next step could use it’s value to find a specific (last added) room in the database. Like that:

    // Given I have a room
    // …
    $room = new Room();
    $em->persist($room);
    $em->flush();
    $this->lastRoomId = $room->getId();
    // …
    
    // Then this room should have ...
    // …
    $room = $em->getRepository('AcmeDemoBundle:Room')
        ->findOneById($this->lastRoomId);
    // …
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.