<?php
namespace nur\data\types;

use nur\b\ValueException;
use nur\t\TestCase;
use stdClass;

class FileTypeTest extends TestCase {
  function testWith() {
    $type = new FileType();
    self::assertSame(false, $type->with(false));
    self::assertSame(null, $type->with(null));
    self::assertSame([], $type->with([]));
    self::assertSame([1], $type->with([1]));
    self::assertSame(["abc"], $type->with(["abc"]));
    $file = [
      "name" => "image.jpg",
      "type" => "image/jpeg",
      "size" => 1537,
      "tmp_name" => "/tmp/xyzstu",
      "error" => UPLOAD_ERR_OK,
    ];
    self::assertSame($file, $type->with($file));
    self::assertException(ValueException::class, [$type, "with"], "");
    self::assertException(ValueException::class, [$type, "with"], 1);
    self::assertException(ValueException::class, [$type, "with"], 1.2);
    self::assertException(ValueException::class, [$type, "with"], true);
    self::assertException(ValueException::class, [$type, "with"], new stdClass());
  }
}
