PHP code example of peterfox / behat-resources-extension

1. Go to this page and download the library: Download peterfox/behat-resources-extension library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

peterfox / behat-resources-extension example snippets




use BehatResources\ResourceFactory;

class EloquentResourceFactory implements ResourceFactory
{
    /**
     * @param string $class
     * @param string $type
     * @param array $arguments
     * @return Object
     */
    public function buildObject($class, $type, $arguments = [])
    {
        return factory($class)->make($arguments);
    }

    /**
     * @param string $class
     * @param string $type
     * @param array $arguments
     * @return Object
     */
    public function buildPersistedObject($class, $type, $arguments = [])
    {
        return factory($class)->create($arguments);
    }
}




use BehatResources\Context\ResourceContext;

class FeatureContext extends MinkContext implements ResourceContext
{
    private $builder;

    /**
     * @param ResourceBuilder $builder
     */
    public function setResourceBuilder(ResourceBuilder $builder)
    {
        $this->builder = $builder;
    }

    /**
     * @param $type
     * @param $identifier
     * @return array
     */
    public function getResource($type, $identifier)
    {
        return $this->resourceBuilder->getLoader()->load($type, $identifier);
    }

    /**
     * @param $type
     * @param $identifier
     * @return object
     */
    public function getResourceObject($type, $identifier)
    {
        return $this->resourceBuilder->build($type, $identifier);
    }
    
    /**
     * @param $type
     * @param $identifier
     * @return object
     */
    public function getPersistedResourceObject($type, $identifier)
    {
        return $this->resourceBuilder->build($type, $identifier);
    }

    /**
     * Returns your implementation of the ResourceFactory for changing resources into Objects/Models/Entities etc.
     *
     * @return ResourceFactory|null
     */
    public function getResourceFactory()
    {
        return new EloquentResourceFactory();
    }
}

    /**
     * @Given /^there is a ([^"]*) called "([^"]*)"$/
     */
    public function thereIsACalled($resource, $name)
    {
        $this->getPersistedResourceObject($resource, $name);
    }