public function testAlignMethodThrowsExceptionWhenPositionIsInvalid() { $adapter = $this->getMockBuilder('Phower\\Image\\Adapter\\AdapterInterface')->getMock(); $adapter->method('getWidth')->willReturn(100); $adapter->method('getHeight')->willReturn(100); $layer = new Layer($adapter); $this->setExpectedException('Phower\\Image\\Exception\\InvalidArgumentException'); $layer->align(10, 10, 10); }
/** * Import file into a new layer * * @param string $file * @param int $mode * @return \Phower\Image\Image * @throws InvalidArgumentException */ public function import($file, $mode = LayersStack::APPEND_TOP, $position = LayerInterface::POSITION_MIDDLE_CENTER) { if (!is_readable($file)) { throw new InvalidArgumentException('Unable to import source: ' . $file); } /* @var $adapter \Phower\Image\Adapter\AdapterInterface */ $callback = $this->getDefaultAdapter() . '::fromFile'; $adapter = call_user_func_array($callback, [$file]); $layer = new Layer($adapter); if (($this->width === null || $this->height === null) && $this->layers->count() === 0) { $this->width = $layer->getWidth(); $this->height = $layer->getHeight(); } else { $layer->align($this->width, $this->height, $position); } $this->layers->append($layer, $mode); return $this; }