public function getATime() { return $this->file->getATime(); }
public function testDecoratedMethods() { $decorated = $this->getMockBuilder('hanneskod\\classtools\\Tests\\MockSplFileInfo')->setConstructorArgs([''])->getMock(); $decorated->expects($this->once())->method('getRelativePath'); $decorated->expects($this->once())->method('getRelativePathname'); $decorated->expects($this->once())->method('getContents'); $decorated->expects($this->once())->method('getATime'); $decorated->expects($this->once())->method('getBasename'); $decorated->expects($this->once())->method('getCTime'); $decorated->expects($this->once())->method('getExtension'); $decorated->expects($this->once())->method('getFileInfo'); $decorated->expects($this->once())->method('getFilename'); $decorated->expects($this->once())->method('getGroup'); $decorated->expects($this->once())->method('getInode'); $decorated->expects($this->once())->method('getLinkTarget'); $decorated->expects($this->once())->method('getMTime'); $decorated->expects($this->once())->method('getOwner'); $decorated->expects($this->once())->method('getPath'); $decorated->expects($this->once())->method('getPathInfo'); $decorated->expects($this->once())->method('getPathname'); $decorated->expects($this->once())->method('getPerms'); $decorated->expects($this->once())->method('getRealPath'); $decorated->expects($this->once())->method('getSize'); $decorated->expects($this->once())->method('getType'); $decorated->expects($this->once())->method('isDir'); $decorated->expects($this->once())->method('isExecutable'); $decorated->expects($this->once())->method('isFile'); $decorated->expects($this->once())->method('isLink'); $decorated->expects($this->once())->method('isReadable'); $decorated->expects($this->once())->method('isWritable'); $decorated->expects($this->once())->method('openFile'); $decorated->expects($this->once())->method('setFileClass'); $decorated->expects($this->once())->method('setInfoClass'); $decorated->expects($this->once())->method('__toString')->will($this->returnValue('')); $fileInfo = new SplFileInfo($decorated); $fileInfo->getRelativePath(); $fileInfo->getRelativePathname(); $fileInfo->getContents(); $fileInfo->getATime(); $fileInfo->getBasename(); $fileInfo->getCTime(); $fileInfo->getExtension(); $fileInfo->getFileInfo(); $fileInfo->getFilename(); $fileInfo->getGroup(); $fileInfo->getInode(); $fileInfo->getLinkTarget(); $fileInfo->getMTime(); $fileInfo->getOwner(); $fileInfo->getPath(); $fileInfo->getPathInfo(); $fileInfo->getPathname(); $fileInfo->getPerms(); $fileInfo->getRealPath(); $fileInfo->getSize(); $fileInfo->getType(); $fileInfo->isDir(); $fileInfo->isExecutable(); $fileInfo->isFile(); $fileInfo->isLink(); $fileInfo->isReadable(); $fileInfo->isWritable(); $fileInfo->openFile(); $fileInfo->setFileClass(); $fileInfo->setInfoClass(); (string) $fileInfo; }
public function getATime($format = false) { if ($format) { return date($format, parent::getATime()); } return parent::getATime(); }
/** * Returns basic information about created file/object * @param string $entityName name of class * @param mixed $entityId id of entity * @return null|array basic information */ public function spy($entityName, $entityId) { $file = sprintf('%s/%s/%s.json', $this->config->dir, $entityName, $entityId); if (file_exists($file)) { $file = new \SplFileInfo($file); $result = array(); $result['last_modified_time'] = $file->getATime(); $result['size'] = $file->getSize(); return $result; } else { return null; } }
<?php function inRange($x, $a, $b) { return $x >= $a && $x <= $b ? "YES" : "NO"; } $file = tempnam(sys_get_temp_dir(), 'touch_date'); // No args $now = time(); touch($file); $fileInfo = new SplFileInfo($file); print inRange($fileInfo->getMTime(), $now, $now + 10) . "\n"; print inRange($fileInfo->getATime(), $now, $now + 10) . "\n"; // Mofification time only touch($file, strtotime("@100200300")); $fileInfo = new SplFileInfo($file); print $fileInfo->getMTime() . "\n"; print $fileInfo->getATime() . "\n"; // Modification and access time touch($file, strtotime("@100200300"), strtotime("@100400500")); $fileInfo = new SplFileInfo($file); print $fileInfo->getMTime() . "\n"; print $fileInfo->getATime() . "\n";
/** * @depends testExist * @return void */ public function testLastAccessed() { $filePath = __DIR__ . '/example.txt'; $fileObject = new File($filePath); $this->assertGreaterThanOrEqual(0, $fileObject->getATime()); $this->assertInstanceOf('DateTime', $fileObject->lastAccessed()); $fileObject = new \SplFileInfo($filePath); $this->assertGreaterThanOrEqual(0, $fileObject->getATime()); }
protected function getFileDetailsRawStatistic(\SplFileInfo $info, $fileGiven) { return ['File is Dir' => $info->isDir(), 'File is Executable' => $info->isExecutable(), 'File is File' => $info->isFile(), 'File is Link' => $info->isLink(), 'File is Readable' => $info->isReadable(), 'File is Writable' => $info->isWritable(), 'File Permissions' => $this->explainPerms($info->getPerms()), 'Size' => $info->getSize(), 'Sha1' => sha1_file($fileGiven), 'Timestamp Accessed' => $this->getFileTimes($info->getATime()), 'Timestamp Changed' => $this->getFileTimes($info->getCTime()), 'Timestamp Modified' => $this->getFileTimes($info->getMTime())]; }
public function testSpy() { $genClass = $this->container['config']->get('id_gen_strategy_class'); $entity = new \stdClass(); $entity->id = $genClass::generate(); $entity->foo = "bar"; $this->container['em']->persist($entity); $foundEntity = $this->container['em']->find('stdClass', $entity->id); $file = new \SplFileInfo(sprintf('%s/%s/%s.json', $this->container['config']->get('dir'), get_class($entity), $entity->id)); $currentCheck = array(); $currentCheck['last_modified_time'] = $file->getATime(); $currentCheck['size'] = $file->getSize(); $this->assertEquals($currentCheck, $this->container['em']->spy('stdClass', $entity->id)); $this->assertNull($this->container['em']->spy('stdClass', uniqid())); }
/** * Checks if the given file can be removed. * * @param \SplFileInfo $file * @return boolean */ private function isCollectibleFile(\SplFileInfo $file) { if (false === $file->isFile()) { return false; } $time = $file->getATime(); if ($time > $this->minTime) { return false; } $time = $file->getMTime(); if ($time > $this->minTime) { return false; } return true; }