/** * Rename or move the file and return its relative path. * * @param Model $model * @param \Transit\File $file * @param array $options * @return string */ protected function _renameAndMove(Model $model, File $file, array $options) { $nameCallback = null; if ($options['nameCallback'] && method_exists($model, $options['nameCallback'])) { $nameCallback = array($model, $options['nameCallback']); } $file->rename($nameCallback, $options['append'], $options['prepend']); if ($options['uploadDir']) { $file->move($options['uploadDir'], $options['overwrite']); } return (string) $options['finalPath'] . $file->basename(); }
/** * Test that move() doesn't overwrite files but appends an incremented number. */ public function testMoveNoOverwrite() { $testPath = TEST_DIR . '/test.jpg'; $movePath = TEMP_DIR . '/test-1.jpg'; copy($this->baseFile, $testPath); $this->assertFalse(file_exists($movePath)); $file = new File($testPath); $file->move(TEMP_DIR); $this->assertTrue(file_exists($movePath)); $file->delete(); }