Knp\Bundle\KnpBundlesBundle\Features\Context\FeatureContext::theBundlesHaveFollowingKeywords PHP Method

theBundlesHaveFollowingKeywords() public method

public theBundlesHaveFollowingKeywords ( Behat\Gherkin\Node\TableNode $table )
$table Behat\Gherkin\Node\TableNode
    public function theBundlesHaveFollowingKeywords(TableNode $table)
    {
        $entityManager = $this->getEntityManager();
        $repository = $entityManager->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\Keyword');
        foreach ($table->getHash() as $row) {
            if (isset($this->bundles[$row['bundle']])) {
                $bundle = $this->bundles[$row['bundle']];
                $keyword = $repository->findOneBy(array('value' => $row['keyword']));
                if (!$keyword) {
                    $keyword = new Entity\Keyword();
                    $keyword->setValue($row['keyword']);
                }
                $bundle->addKeyword($keyword);
                $entityManager->persist($bundle);
            }
        }
        $entityManager->flush();
    }