/** * @depends testExist * @return void */ public function testTouch() { // I did not compare access and modification time to defined values // because it looks like that this file attributes are cached in php // because they did not change until you call the script again. // beyond that i feared problem with windows. // TODO try clearstatcache() // create file $createFiles = array(__DIR__ . '/tmp/example_touch1.txt', __DIR__ . '/tmp/example_touch2.txt', __DIR__ . '/tmp/example_touch3.txt', __DIR__ . '/tmp/example_touch4.txt'); foreach ($createFiles as $createFile) { if (!is_file($createFile)) { fclose(fopen($createFile, 'x')); } } $filePath = __DIR__ . '/tmp/example_touch1.txt'; $fileObject = new File($filePath); $this->assertTrue($fileObject->touch()); $this->assertGreaterThanOrEqual(0, $fileObject->getMTime()); $this->assertGreaterThanOrEqual(0, $fileObject->getATime()); $filePath = __DIR__ . '/tmp/example_touch2.txt'; $modificationTime = time() - 3600; // current time -1 hour $fileObject = new File($filePath); $this->assertTrue($fileObject->touch($modificationTime)); $this->assertGreaterThanOrEqual(0, $fileObject->getMTime()); $this->assertGreaterThanOrEqual(0, $fileObject->getATime()); $filePath = __DIR__ . '/tmp/example_touch3.txt'; $accessTime = time() - 7200; // current time -2 hour $fileObject = new File($filePath); $this->assertTrue($fileObject->touch(null, $accessTime)); $this->assertGreaterThanOrEqual(0, $fileObject->getMTime()); $this->assertGreaterThanOrEqual(0, $fileObject->getATime()); $filePath = __DIR__ . '/tmp/example_touch4.txt'; $modificationTime = time() - 42200; // current time -12 hour $accessTime = time() - 36000; // current time -10 hour $fileObject = new File($filePath); $this->assertTrue($fileObject->touch($modificationTime, $accessTime)); $this->assertGreaterThanOrEqual(0, $fileObject->getMTime()); $this->assertGreaterThanOrEqual(0, $fileObject->getATime()); }