public function testSize() { $file = new FileInfo(__FILE__); $sizeHuman = $file->getSizeHuman(2); $this->assertTrue(substr($sizeHuman, -1, 1) === 'K'); }
/** * @param FixtureData $f */ private function move(FixtureData $f) { $f->setName(str_replace(DIRECTORY_SEPARATOR, '-', $f->getName())); $tplPathName = uniqid('string_template_' . mt_rand(10, 99) . '_', true); $tplFileName = uniqid('string_template_' . mt_rand(10, 99) . '_', true); if ($f instanceof FixtureMovieData) { list($e, $opts) = $this->moveMovie($f, $this->getTwig(), $tplPathName, $tplFileName); } elseif ($f instanceof FixtureEpisodeData) { list($e, $opts) = $this->moveEpisode($f, $this->getTwig(), $tplPathName, $tplFileName); } else { $this->io()->error('Invalid fixture type!'); return; } $path = $e->render($tplPathName, $opts); $file = $e->render($tplFileName, $opts); $outputFilePath = preg_replace('{[/]+}', '/', sprintf('%s/%s/%s', $this->outputPath, $path, $file)); $outputPath = pathinfo($outputFilePath, PATHINFO_DIRNAME); $inputFilePath = $f->getFile()->getRealPath(); $offset = 2; while (true) { if (strncmp($outputFilePath, $inputFilePath, $offset++) !== 0) { $offset = $offset - 2; break; } } $outputFileInfo = new FileInfo($outputFilePath, null, null, false); $inputFileInfo = new FileInfo($inputFilePath); try { $inputFileSize = $inputFileInfo->getSizeHuman(); } catch (\RuntimeException $e) { $inputFileSize = null; } $tableRows[] = ['Input File', sprintf('[...]%s', basename($inputFilePath)), $inputFileSize]; try { $outputFileSize = $outputFileInfo->getSizeHuman(); } catch (\RuntimeException $e) { $outputFileSize = null; } $tableRows[] = ['Output File', sprintf('[...]%s', preg_replace('{[/]+}', '/', sprintf('%s/%s', $path, $file))), $outputFileSize]; $this->io()->table($tableRows, [null, 'Path', 'Size']); if (file_exists($outputFilePath) && false === $this->outputOverwrite && false === $this->handleExistingFile($outputFileInfo, $inputFileInfo)) { return; } if (!is_dir($outputPath) && false === @mkdir($outputPath, 0777, true)) { $this->io()->error(sprintf('Could not create directory "%s"', $outputPath)); return; } if (!$this->io()->isVeryVerbose()) { $this->io()->comment(sprintf('Writing "%s"', $outputFilePath), false); } if (false === @copy($inputFilePath, $outputFilePath)) { $this->io()->error(sprintf('Could not write file "%s"', $outputFilePath)); } else { unlink($inputFilePath); } }