<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

/**
 * Generated by PHPUnit_SkeletonGenerator on 2017-08-08 at 13:24:02.
 */
class FSOperationsTest extends \PHPUnit\Framework\TestCase
{
  /**
   * @var FSOperations
   */
  protected $object;

  /**
   * Sets up the fixture, for example, opens a network connection.
   * This method is called before a test is executed.
   */
  protected function setUp(): void
  {
    $this->object = new FSOperations();
  }

  /**
   * Tears down the fixture, for example, closes a network connection.
   * This method is called after a test is executed.
   */
  protected function tearDown(): void
  {
  }

  /**
   * @covers FSOperations::formatHumanReadable
   * @test
   */
  public function formatHumanReadable()
  {
    $this->assertEquals('1,00 B', $this->object->formatHumanReadable(1));
    $this->assertEquals('1,00 KB', $this->object->formatHumanReadable(1024));
    $this->assertEquals('1,00 MB', $this->object->formatHumanReadable(1024 * 1024));
    $this->assertEquals('1,00 GB', $this->object->formatHumanReadable(1024 * 1024 * 1024));
    $this->assertEquals('1,00 TB', $this->object->formatHumanReadable(1024 * 1024 * 1024 * 1024));

    $this->assertEquals('1,50 KB', $this->object->formatHumanReadable(1024 + 512));

    $this->assertEquals('2,30 KB', $this->object->formatHumanReadable(2357));
    $this->assertEquals('2,31 KB', $this->object->formatHumanReadable(2367));
  }

  /**
   * @covers FSOperations::path
   * @test
   */
  public function path_SinglePath_Identity()
  {
    $this->assertEquals('file', $this->object->path('file'));
  }

  /**
   * @covers FSOperations::path
   * @test
   */
  public function path_SinglePath_RemoveDirectorySeparator()
  {
    $this->assertEquals('file', $this->object->path('file/'));
    $this->assertEquals('file', $this->object->path('file\\'));
  }

  /**
   * @covers FSOperations::path
   * @test
   */
  public function path_MultipleArgs_Identity()
  {
    $this->assertEquals(
      implode(DIRECTORY_SEPARATOR, array('dir0', 'dir1', 'file')),
      $this->object->path('dir0', 'dir1', 'file')
    );
  }

  /**
   * @covers FSOperations::path
   * @test
   */
  public function path_MultipleArgs_RemoveDirectorySeparator()
  {
    $this->assertEquals(
      implode(DIRECTORY_SEPARATOR, array('dir0', 'dir1', 'file')),
      $this->object->path('dir0/', 'dir1/', 'file')
    );
    $this->assertEquals(
      implode(DIRECTORY_SEPARATOR, array('dir0', 'dir1', 'file')),
      $this->object->path('dir0\\', 'dir1\\', 'file')
    );
    $this->assertEquals(
      implode(DIRECTORY_SEPARATOR, array('dir0', 'dir1', 'file')),
      $this->object->path('dir0\\', 'dir1/', 'file')
    );
  }
}
