isDir() ) { rmdir( $file->getRealPath() ); } else { unlink( $file->getRealPath() ); } } rmdir( self::$tmpdir ); self::$tmpdir = null; } } protected static function assertTmpdir() { if ( self::$tmpdir === null || !is_dir( self::$tmpdir ) ) { self::fail( 'No temporary directory for ' . static::class ); } } /** * @param string $prefix For tempnam() * @param string $content Contents of the file * @return string Filename */ protected function makeTemp( $prefix, $content = 'foobar' ) { self::assertTmpdir(); $filename = tempnam( self::$tmpdir, $prefix ); if ( $filename === false ) { self::fail( 'Failed to create temporary file' ); } self::assertSame( strlen( $content ), file_put_contents( $filename, $content ), 'Writing test temporary file' ); return $filename; } }