public function theFollowingRecordsInTheRepository($entity, YamlStringNode $records)
    {
        $manager = $this->getDoctrine()->getManager();
        $accessor = new PropertyAccessor();
        foreach ($records->toArray() as $record) {
            $instance = new $entity();
            foreach ($record as $prop => $value) {
                $accessor->setValue($instance, $prop, $value);
            }

            $manager->persist($instance);
        }
        $manager->flush();
    }
public function theFollowingRecordsInTheRepository($entity, YamlStringNode $records)
    {
        $manager = $this->getDoctrine()->getManager();
        $accessor = new PropertyAccessor();
        foreach ($records->toArray() as $record) {
            $instance = new $entity();
            foreach ($record as $prop => $value) {
                $accessor->setValue($instance, $prop, $value);
            }

            $manager->persist($instance);
        }
        $manager->flush();
    }
public function theFollowingRecordsInTheRepository ( $ entity , YamlStringNode $ records ) { $ manager = $ this -> getDoctrine ( ) -> getManager ( ) ; $ accessor = new PropertyAccessor ( ) ; foreach ( $ records -> toArray ( ) as $ record ) { $ instance = new $ entity ( ) ; foreach ( $ record as $ prop => $ value ) { $ accessor -> setValue ( $ instance , $ prop , $ value ) ; } $ manager -> persist ( $ instance ) ; } $ manager -> flush ( ) ; }
Use a YAML syntax to populate a repository with multiple records

Example: Given the following records in the repository "App\Entity\Post"
"""
- title: "Welcome"
body: "Welcome to web page"
- title: "Another Post"
body: "This is another post"
"""

@Given /^the following records in the repository "([^"]*)"$/
Use a YAML syntax to populate a repository with multiple records