protected function tearDown()
 {
     parent::tearDown();
     $testPath = getenv('YAPEPBASE_TEST_TEMPPATH');
     if (empty($testPath)) {
         return;
     }
     if (file_exists($testPath)) {
         $fileHandler = new FileHandlerPhp();
         $fileHandler->removeDirectory($testPath, true);
     }
 }
 /**
  * Tests the changeOwner() method.
  *
  * @return void
  */
 public function testChangeOwner()
 {
     if (!function_exists('posix_getpwuid') || false === posix_getpwuid(1)) {
         $this->markTestSkipped('Either the posix_getpwuid() function is not available, or there is no user with UID of 1');
     }
     if (!function_exists('posix_getgrgid') || false === posix_getgrgid(1)) {
         $this->markTestSkipped('Either the posix_getgrgid() function is not available, or there is no group with GID of 1');
     }
     $file = 'test.txt';
     $fullPath = $this->getTestPath() . $file;
     touch($fullPath);
     $this->assertTrue(file_exists($fullPath), 'Precondition failed. Unable to create test file: ' . $fullPath);
     $this->assertEquals(0, fileowner($fullPath), 'Precondition failed. Invalid owner for new file.');
     clearstatcache();
     $this->fileHandler->changeOwner($fullPath, null, 1);
     $this->assertEquals(1, fileowner($fullPath), 'Failed to change owner of the test file');
     clearstatcache();
     $this->fileHandler->changeOwner($fullPath, 1, 1);
     $this->assertEquals(1, filegroup($fullPath), 'Failed to change group of the test file');
     $this->assertEquals(1, fileowner($fullPath), 'Invalid user set for file when changing both group and user');
     clearstatcache();
     $this->fileHandler->changeOwner($fullPath, 0);
     $this->assertEquals(0, filegroup($fullPath), 'Failed to change group of the test file');
     $this->assertEquals(1, fileowner($fullPath), 'Changing only the group should not change the owner of a file');
 }
Example #3
0
 /**
  * Deletes every data in the storage.
  *
  * @throws \YapepBase\Exception\StorageException   If the Storage is read only.
  *
  * @return void
  */
 public function clear()
 {
     if ($this->readOnly) {
         throw new StorageException('Trying to write to a read only storage');
     }
     $startTime = microtime(true);
     try {
         $this->fileHandler->removeDirectory($this->path, true);
     } catch (FileException $e) {
         throw new StorageException('Unable to remove the directory: ' . $this->path, 0, $e);
     }
     $debugger = Application::getInstance()->getDiContainer()->getDebugger();
     if (!$this->debuggerDisabled && $debugger !== false) {
         $debugger->addItem(new StorageItem('file', 'file.' . $this->currentConfigurationName, StorageItem::METHOD_CLEAR, null, microtime(true) - $startTime));
     }
 }