src/Context/Form/FormContext.php
public function attachFile($file, $selector)
    {
        $filesPath = $this->getMinkParameter('files_path');

        if (!$filesPath) {
            throw new \Exception('The "files_path" Mink parameter was not configured.');
        }

        $file = rtrim(realpath($filesPath), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file;

        if (!is_file($file)) {
            throw new \InvalidArgumentException(sprintf('The "%s" file does not exist.', $file));
        }

        $this->element('field', $selector)->attachFile($file);
    }
public function attachFile($file, $selector)
    {
        $filesPath = $this->getMinkParameter('files_path');

        if (!$filesPath) {
            throw new \Exception('The "files_path" Mink parameter was not configured.');
        }

        $file = rtrim(realpath($filesPath), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file;

        if (!is_file($file)) {
            throw new \InvalidArgumentException(sprintf('The "%s" file does not exist.', $file));
        }

        $this->element('field', $selector)->attachFile($file);
    }
public function attachFile ( $ file , $ selector ) { $ filesPath = $ this -> getMinkParameter ( 'files_path' ) ; if ( ! $ filesPath ) { throw new \ Exception ( 'The "files_path" Mink parameter was not configured.' ) ; } $ file = rtrim ( realpath ( $ filesPath ) , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $ file ; if ( ! is_file ( $ file ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The "%s" file does not exist.' , $ file ) ) ; } $ this -> element ( 'field' , $ selector ) -> attachFile ( $ file ) ; }
@param string $file
Path to a file. Relative to the directory specified in "files_path" in behat.yml.
@param string $selector
Field selector (label|id|name).

@throws \Exception
@throws NoSuchElement

@Given /^(?:|I )attach file "([^"]*)" to "([^"]*)"$/
@param string $file Path to a file . Relative to the directory specified in files_path in behat . yml . @param string $selector Field selector ( label|id|name ) .