AppserverIo\Appserver\Core\Api\AppService::cleanUpFolders PHP Method

cleanUpFolders() public method

Clean up the the directories for the webapp, e. g. to delete cached stuff that has to be recreated after a restart.
public cleanUpFolders ( AppserverIo\Psr\Application\ApplicationInterface $application ) : void
$application AppserverIo\Psr\Application\ApplicationInterface The application to clean up the directories for
return void
    public function cleanUpFolders(ApplicationInterface $application)
    {
        // create the directory we want to store the sessions in
        $cleanUpFolders = array(new \SplFileInfo($application->getCacheDir()));
        // create the applications temporary directories
        foreach ($cleanUpFolders as $cleanUpFolder) {
            $this->cleanUpDir($cleanUpFolder);
        }
    }

Usage Example

Example #1
0
 /**
  * Tests if we are able to clear the tmp directory of an application
  *
  * @return null
  */
 public function testCleanUpFolders()
 {
     $cacheDir = $this->getTmpDir() . DIRECTORY_SEPARATOR . 'cache';
     if (!is_dir($cacheDir)) {
         \mkdir($cacheDir);
     }
     touch($cacheDir . DIRECTORY_SEPARATOR . md5(__METHOD__));
     $mockApplication = $this->getMockBuilder('\\AppserverIo\\Psr\\Application\\ApplicationInterface')->setMethods(get_class_methods('\\AppserverIo\\Appserver\\Application\\Application'))->getMock();
     $mockApplication->expects($this->once())->method('getCacheDir')->will($this->returnValue($cacheDir));
     $this->assertCount(3, scandir($cacheDir));
     $this->appService->cleanUpFolders($mockApplication);
     $this->assertCount(2, scandir($cacheDir));
 }