<?php

namespace Test\Michel\FileSystem;

use Michel\FileSystem\FileInfo;
use Michel\FileSystem\Tools\FileSplitter;
use Michel\UniTester\TestCase;

class FileSplitterTest extends TestCase
{

    protected function setUp(): void
    {
        // TODO: Implement setUp() method.
    }

    protected function tearDown(): void
    {
        // TODO: Implement tearDown() method.
    }

    protected function execute(): void
    {
        $this->testSplitMb();
        $this->testSplitNoSameSize();
        $this->testSplitKb();
    }
    public function testSplitMb()
    {
        $fileInfo = new FileInfo(dirname(__FILE__).'/resources/file_2MB.txt');
        $splitter = new FileSplitter($fileInfo);
        $files = $splitter->splitMb(1);
        $this->assertCount(2, $files);

        foreach ($files as $file) {
            $this->assertInstanceOf(FileInfo::class, $file);
            $file->delete();
        }
    }

    public function testSplitNoSameSize()
    {
        $fileInfo = new FileInfo(dirname(__FILE__).'/resources/file_2MB.txt');
        $splitter = new FileSplitter($fileInfo);
        $files = $splitter->splitKb(200);
        $this->assertCount(11, $files);

        foreach ($files as $file) {
            $this->assertInstanceOf(FileInfo::class, $file);
            $file->delete();
        }
    }

    public function testSplitKb()
    {
        $fileInfo = new FileInfo(dirname(__FILE__).'/resources/file_1MB.txt');
        $splitter = new FileSplitter($fileInfo);
        $files = $splitter->splitKb(512);
        $this->assertCount(2, $files);

        foreach ($files as $file) {
            $this->assertInstanceOf(FileInfo::class, $file);
            $file->delete();
        }

        $fileInfo = new FileInfo(dirname(__FILE__).'/resources/file_1MB.txt');
        $splitter = new FileSplitter($fileInfo);
        $files = $splitter->splitKb(500);
        $this->assertCount(3, $files);

        foreach ($files as $file) {
            $this->assertInstanceOf(FileInfo::class, $file);
            $file->delete();
        }
    }

}
