ScriptFUSION\Porter\Porter::importOne PHP Method

importOne() public method

Imports one record according to the design of the specified import specification.
public importOne ( ImportSpecification $specification ) : array | null
$specification ScriptFUSION\Porter\Specification\ImportSpecification Import specification.
return array | null Record.
    public function importOne(ImportSpecification $specification)
    {
        $results = $this->import($specification);
        if (!$results->valid()) {
            return;
        }
        $one = $results->current();
        if ($results->next() || $results->valid()) {
            throw new ImportException('Cannot import one: more than one record imported.');
        }
        return $one;
    }

Usage Example

Example #1
0
 public function testImportOneOfMany()
 {
     $this->setExpectedException(ImportException::class);
     $this->provider->shouldReceive('fetch')->andReturn(new \ArrayIterator(['foo', 'bar']));
     $this->porter->importOne($this->specification);
 }