PhpUnit Extras

Working With Files

If you need to CRUD files during a test you may use the FileSandboxTrait.

Quick Start

  1. Put the following in your test's ::setUp or ::setUpBeforeClass method depending upon if you want the directory to empty for each new test (::setUp) or not.

      public function setUp() {
        parent::setUp();
        $this->setUpFileSandbox();
      }
    
      public function setUpBeforeClass() {
        parent::setUp();
        self::setUpFileSandbox();
      }
    
  2. Use $this->sb or self::$sb as the scratch directory path.

  3. Call $this->setUpFileSandbox() at any time to empty it's contents.